Check-in Differences
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From c5692a3458233cdd To 0da08dfd33708d89

2016-12-29
15:48
rl2_load_raw_tiles: supporting 1-BIT, 2-BIT, 4-BIT MONOCHROME and PALETTE check-in: 6618242a60 user: sandro tags: trunk
11:37
rl2_load_raw_tiles: initial implementation check-in: 0da08dfd33 user: sandro tags: trunk
2016-12-28
12:40
bugfix: importing DATAGRID from TIFF (by strip / setting the initial palette only after importing the first Section check-in: 77db64b78e user: sandro tags: trunk
2015-06-05
12:03
updating to automake 1.15 check-in: 7574f54ee8 user: sandro tags: trunk
2015-06-04
21:50
implementing RL2_CopyRasterCoverage() check-in: c5692a3458 user: sandro tags: trunk
2015-05-31
10:02
wmslite micro-server: supporting WMS vector layers in GetCapabilities check-in: 6b8e213297 user: sandro tags: trunk

Deleted Android_R4.2.0.mk.

     1         -# -------------------
     2         -# Android_R4.2.0.mk
     3         -# ndk-build clean
     4         -# ndk-build
     5         -# -------------------
     6         -LOCAL_PATH := $(call my-dir)
     7         -JSQLITE_PATH := javasqlite-20120209
     8         -SPATIALITE_PATH := libspatialite-4.2.0-rc1
     9         -GEOS_PATH := geos-3.4.2
    10         -PROJ4_PATH := proj-4.8.0
    11         -SQLITE_PATH := sqlite-amalgamation-3080403
    12         -ICONV_PATH := libiconv-1.13.1
    13         -RASTERLITE2_PATH := librasterlite2-4.2.0
    14         -GEOTIFF_PATH := libgeotiff-1.4.0
    15         -TIFF_PATH := tiff-4.0.3/libtiff
    16         -JPEG_PATH := jpeg-8d
    17         -GIF_PATH := giflib-5.0.6/lib
    18         -CAIRO_PATH := cairo-1.12.14/src
    19         -FREETYPE_PATH := freetype-2.5.3
    20         -FONTCONFIG_PATH := fontconfig-2.11.1
    21         -EXPAT_PATH := expat-2.1.0
    22         -PIXMAN_PATH := pixman-0.32.4
    23         -PNG_PATH := libpng-1.6.10
    24         -WEBP_PATH := libwebp-0.4.0
    25         -XML2_PATH := libxml2-2.9.1
    26         -CURL_PATH := curl-7.36.0
    27         -LZMA_PATH := xz-5.1.3alpha
    28         -
    29         -include $(LOCAL_PATH)/jsqlite-R4.2.0.mk
    30         -include $(LOCAL_PATH)/iconv-1.13.1.mk
    31         -include $(LOCAL_PATH)/sqlite-3080403.mk
    32         -include $(LOCAL_PATH)/proj4-4.8.0.mk
    33         -include $(LOCAL_PATH)/geos-3.4.2.mk
    34         -include $(LOCAL_PATH)/spatialite-4.2.0.mk
    35         -include $(LOCAL_PATH)/libjpeg-8d.mk
    36         -include $(LOCAL_PATH)/giflib-5.0.6.mk
    37         -include $(LOCAL_PATH)/libpng-1.6.10.mk
    38         -include $(LOCAL_PATH)/libtiff-4.0.3.mk
    39         -include $(LOCAL_PATH)/libwebp-0.4.0.mk
    40         -include $(LOCAL_PATH)/pixman-0.32.4.mk
    41         -include $(LOCAL_PATH)/freetype-2.5.3.mk
    42         -include $(LOCAL_PATH)/fontconfig-2.11.1.mk
    43         -include $(LOCAL_PATH)/expat-2.1.0.mk
    44         -include $(LOCAL_PATH)/cairo-1.12.14.mk
    45         -include $(LOCAL_PATH)/libgeotiff-1.4.0.mk
    46         -include $(LOCAL_PATH)/libxml2-2.9.1.mk
    47         -include $(LOCAL_PATH)/libcurl-7.36.0.mk
    48         -include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk
    49         -include $(LOCAL_PATH)/rasterlite2-4.2.0.mk
    50         -$(call import-module,android/cpufeatures)

Added Android_R4.3.0.mk.

            1  +# -------------------
            2  +# Android_R4.3.0.mk
            3  +# ndk-build clean
            4  +# ndk-build
            5  +# -------------------
            6  +LOCAL_PATH := $(call my-dir)
            7  +JSQLITE_PATH := javasqlite-20120209
            8  +SPATIALITE_PATH := libspatialite-4.3.0
            9  +GEOS_PATH := geos-3.4.2
           10  +PROJ4_PATH := proj-4.9.1
           11  +SQLITE_PATH := sqlite-amalgamation-3081002
           12  +ICONV_PATH := libiconv-1.13.1
           13  +RASTERLITE2_PATH := librasterlite2-4.3.0
           14  +GEOTIFF_PATH := libgeotiff-1.4.0
           15  +TIFF_PATH := tiff-4.0.3/libtiff
           16  +JPEG_PATH := jpeg-8d
           17  +GIF_PATH := giflib-5.0.6/lib
           18  +CAIRO_PATH := cairo-1.12.14/src
           19  +FREETYPE_PATH := freetype-2.5.3
           20  +FONTCONFIG_PATH := fontconfig-2.11.1
           21  +EXPAT_PATH := expat-2.1.0
           22  +PIXMAN_PATH := pixman-0.32.4
           23  +PNG_PATH := libpng-1.6.10
           24  +WEBP_PATH := libwebp-0.4.0
           25  +XML2_PATH := libxml2-2.9.1
           26  +CURL_PATH := curl-7.36.0
           27  +LZMA_PATH := xz-5.1.3alpha
           28  +CHARLS_PATH := charls-1.0
           29  +OPENJPEG_PATH := openjpeg-2.0.0
           30  +
           31  +include $(LOCAL_PATH)/charls-1.0.mk
           32  +include $(LOCAL_PATH)/jsqlite-R4.2.0.mk
           33  +include $(LOCAL_PATH)/iconv-1.13.1.mk
           34  +include $(LOCAL_PATH)/sqlite-3081002.mk
           35  +include $(LOCAL_PATH)/proj4-4.9.1.mk
           36  +include $(LOCAL_PATH)/geos-3.4.2.mk
           37  +include $(LOCAL_PATH)/spatialite-4.3.0.mk
           38  +include $(LOCAL_PATH)/libjpeg-8d.mk
           39  +include $(LOCAL_PATH)/openjpeg-2.0.0.mk
           40  +include $(LOCAL_PATH)/giflib-5.0.6.mk
           41  +include $(LOCAL_PATH)/libpng-1.6.10.mk
           42  +include $(LOCAL_PATH)/libtiff-4.0.3.mk
           43  +include $(LOCAL_PATH)/libwebp-0.4.0.mk
           44  +include $(LOCAL_PATH)/pixman-0.32.4.mk
           45  +include $(LOCAL_PATH)/freetype-2.5.3.mk
           46  +include $(LOCAL_PATH)/fontconfig-2.11.1.mk
           47  +include $(LOCAL_PATH)/expat-2.1.0.mk
           48  +include $(LOCAL_PATH)/cairo-1.12.14.mk
           49  +include $(LOCAL_PATH)/libgeotiff-1.4.0.mk
           50  +include $(LOCAL_PATH)/libxml2-2.9.1.mk
           51  +include $(LOCAL_PATH)/libcurl-7.36.0.mk
           52  +include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk
           53  +include $(LOCAL_PATH)/rasterlite2-4.3.0.mk
           54  +$(call import-module,android/cpufeatures)

Changes to Makefile-static-MinGW.

     9      9   	./static_bin/wmslite.exe
    10     10   
    11     11   ./static_bin/rl2sniff.exe: ./tools/rl2sniff.o 
    12     12   	$(GG) ./tools/rl2sniff.o -o ./static_bin/rl2sniff.exe \
    13     13   	/usr/local/lib/librasterlite2.a \
    14     14   	/usr/local/lib/libspatialite.a \
    15     15   	/usr/local/lib/libsqlite3.a \
    16         -	/usr/local/lib/liblwgeom.a \
           16  +	/usr/local/lib/librttopo.a \
    17     17   	/usr/local/lib/libproj.a \
    18     18   	/usr/local/lib/libgeos_c.a \
    19     19   	/usr/local/lib/libgeos.a \
    20     20   	/usr/local/lib/libfreexl.a \
    21     21   	/usr/local/lib/libcairo.a \
    22     22   	/usr/local/lib/libpixman-1.a \
    23     23   	/usr/local/lib/libfontconfig.a \
................................................................................
    42     42   	strip --strip-all ./static_bin/rl2sniff.exe
    43     43   	
    44     44   ./static_bin/rl2tool.exe: ./tools/rl2tool.o 
    45     45   	$(GG) ./tools/rl2tool.o -o ./static_bin/rl2tool.exe \
    46     46   	/usr/local/lib/librasterlite2.a \
    47     47   	/usr/local/lib/libspatialite.a \
    48     48   	/usr/local/lib/libsqlite3.a \
    49         -	/usr/local/lib/liblwgeom.a \
           49  +	/usr/local/lib/librttopo.a \
    50     50   	/usr/local/lib/libproj.a \
    51     51   	/usr/local/lib/libgeos_c.a \
    52     52   	/usr/local/lib/libgeos.a \
    53     53   	/usr/local/lib/libfreexl.a \
    54     54   	/usr/local/lib/libcairo.a \
    55     55   	/usr/local/lib/libpixman-1.a \
    56     56   	/usr/local/lib/libfontconfig.a \
................................................................................
    75     75   	strip --strip-all ./static_bin/rl2tool.exe
    76     76   
    77     77   ./static_bin/wmslite.exe: ./tools/wmslite.o 
    78     78   	$(GG) ./tools/wmslite.o -o ./static_bin/wmslite.exe \
    79     79   	/usr/local/lib/librasterlite2.a \
    80     80   	/usr/local/lib/libspatialite.a \
    81     81   	/usr/local/lib/libsqlite3.a \
    82         -	/usr/local/lib/liblwgeom.a \
           82  +	/usr/local/lib/librttopo.a \
    83     83   	/usr/local/lib/libproj.a \
    84     84   	/usr/local/lib/libgeos_c.a \
    85     85   	/usr/local/lib/libgeos.a \
    86     86   	/usr/local/lib/libfreexl.a \
    87     87   	/usr/local/lib/libcairo.a \
    88     88   	/usr/local/lib/libpixman-1.a \
    89     89   	/usr/local/lib/libfontconfig.a \

Changes to Makefile.am.

     1      1   ACLOCAL_AMFLAGS = -I m4
     2      2   
     3      3   SUBDIRS = headers src test tools
     4      4   
     5         -EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \
            5  +EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \
     6      6   	Makefile-static-MinGW
     7      7   
     8         -AUTOMAKE_OPTIONS = dist-zip
            8  +AUTOMAKE_OPTIONS = dist-zip foreign
     9      9   
    10     10   pkgconfigdir = $(libdir)/pkgconfig
    11     11   pkgconfig_DATA = rasterlite2.pc
    12     12   
    13     13   coverage-init:
    14     14   	lcov --directory src --capture --initial --output-file rasterlite2_cov.info
    15     15   
    16     16   coverage::
    17     17   	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture
           18  +	lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info
    18     19   	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info
    19     20   
    20     21   MOSTLYCLEANFILES = rasterlite2_cov.info 

Changes to Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   
    17     17   VPATH = @srcdir@
    18         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           18  +am__is_gnu_make = { \
           19  +  if test -z '$(MAKELEVEL)'; then \
           20  +    false; \
           21  +  elif test -n '$(MAKE_HOST)'; then \
           22  +    true; \
           23  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           24  +    true; \
           25  +  else \
           26  +    false; \
           27  +  fi; \
           28  +}
    19     29   am__make_running_with_option = \
    20     30     case $${target_option-} in \
    21     31         ?) ;; \
    22     32         *) echo "am__make_running_with_option: internal error: invalid" \
    23     33                 "target option '$${target_option-}' specified" >&2; \
    24     34            exit 1;; \
    25     35     esac; \
................................................................................
    75     85   POST_INSTALL = :
    76     86   NORMAL_UNINSTALL = :
    77     87   PRE_UNINSTALL = :
    78     88   POST_UNINSTALL = :
    79     89   build_triplet = @build@
    80     90   host_triplet = @host@
    81     91   subdir = .
    82         -DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
    83         -	$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
    84         -	$(top_srcdir)/configure $(am__configure_deps) \
    85         -	$(srcdir)/config.h.in $(srcdir)/Doxyfile.in \
    86         -	$(srcdir)/rasterlite2.pc.in COPYING compile config.guess \
    87         -	config.sub depcomp install-sh missing ltmain.sh
    88     92   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    89     93   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    90     94   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    91     95   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    92     96   	$(top_srcdir)/configure.ac
    93     97   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    94     98   	$(ACLOCAL_M4)
           99  +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
          100  +	$(am__configure_deps) $(am__DIST_COMMON)
    95    101   am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
    96    102    configure.lineno config.status.lineno
    97    103   mkinstalldirs = $(install_sh) -d
    98    104   CONFIG_HEADER = config.h
    99    105   CONFIG_CLEAN_FILES = Doxyfile rasterlite2.pc
   100    106   CONFIG_CLEAN_VPATH_FILES =
   101    107   AM_V_P = $(am__v_P_@AM_V@)
................................................................................
   180    186     unique=`for i in $$list; do \
   181    187       if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   182    188     done | $(am__uniquify_input)`
   183    189   ETAGS = etags
   184    190   CTAGS = ctags
   185    191   CSCOPE = cscope
   186    192   DIST_SUBDIRS = $(SUBDIRS)
          193  +am__DIST_COMMON = $(srcdir)/Doxyfile.in $(srcdir)/Makefile.in \
          194  +	$(srcdir)/config.h.in $(srcdir)/rasterlite2.pc.in AUTHORS \
          195  +	COPYING ChangeLog INSTALL NEWS README compile config.guess \
          196  +	config.sub depcomp install-sh ltmain.sh missing
   187    197   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   188    198   distdir = $(PACKAGE)-$(VERSION)
   189    199   top_distdir = $(distdir)
   190    200   am__remove_distdir = \
   191    201     if test -d "$(distdir)"; then \
   192    202       find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
   193    203         && rm -rf "$(distdir)" \
................................................................................
   366    376   sysconfdir = @sysconfdir@
   367    377   target_alias = @target_alias@
   368    378   top_build_prefix = @top_build_prefix@
   369    379   top_builddir = @top_builddir@
   370    380   top_srcdir = @top_srcdir@
   371    381   ACLOCAL_AMFLAGS = -I m4
   372    382   SUBDIRS = headers src test tools
   373         -EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \
          383  +EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \
   374    384   	Makefile-static-MinGW
   375    385   
   376         -AUTOMAKE_OPTIONS = dist-zip
          386  +AUTOMAKE_OPTIONS = dist-zip foreign
   377    387   pkgconfigdir = $(libdir)/pkgconfig
   378    388   pkgconfig_DATA = rasterlite2.pc
   379    389   MOSTLYCLEANFILES = rasterlite2_cov.info 
   380    390   all: config.h
   381    391   	$(MAKE) $(AM_MAKEFLAGS) all-recursive
   382    392   
   383    393   .SUFFIXES:
   384    394   am--refresh: Makefile
   385    395   	@:
   386    396   $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
   387    397   	@for dep in $?; do \
   388    398   	  case '$(am__configure_deps)' in \
   389    399   	    *$$dep*) \
   390         -	      echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \
   391         -	      $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \
          400  +	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
          401  +	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
   392    402   		&& exit 0; \
   393    403   	      exit 1;; \
   394    404   	  esac; \
   395    405   	done; \
   396         -	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \
          406  +	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
   397    407   	$(am__cd) $(top_srcdir) && \
   398         -	  $(AUTOMAKE) --gnu Makefile
   399         -.PRECIOUS: Makefile
          408  +	  $(AUTOMAKE) --foreign Makefile
   400    409   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   401    410   	@case '$?' in \
   402    411   	  *config.status*) \
   403    412   	    echo ' $(SHELL) ./config.status'; \
   404    413   	    $(SHELL) ./config.status;; \
   405    414   	  *) \
   406    415   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
................................................................................
   648    657   	$(am__post_remove_distdir)
   649    658   
   650    659   dist-xz: distdir
   651    660   	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
   652    661   	$(am__post_remove_distdir)
   653    662   
   654    663   dist-tarZ: distdir
   655         -	@echo WARNING: "Support for shar distribution archives is" \
   656         -	               "deprecated." >&2
          664  +	@echo WARNING: "Support for distribution archives compressed with" \
          665  +		       "legacy program 'compress' is deprecated." >&2
   657    666   	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
   658    667   	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
   659    668   	$(am__post_remove_distdir)
   660    669   
   661    670   dist-shar: distdir
   662         -	@echo WARNING: "Support for distribution archives compressed with" \
   663         -		       "legacy program 'compress' is deprecated." >&2
          671  +	@echo WARNING: "Support for shar distribution archives is" \
          672  +	               "deprecated." >&2
   664    673   	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
   665    674   	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
   666    675   	$(am__post_remove_distdir)
   667    676   dist-zip: distdir
   668    677   	-rm -f $(distdir).zip
   669    678   	zip -rq $(distdir).zip $(distdir)
   670    679   	$(am__post_remove_distdir)
................................................................................
   691    700   	*.shar.gz*) \
   692    701   	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
   693    702   	*.zip*) \
   694    703   	  unzip $(distdir).zip ;;\
   695    704   	esac
   696    705   	chmod -R a-w $(distdir)
   697    706   	chmod u+w $(distdir)
   698         -	mkdir $(distdir)/_build $(distdir)/_inst
          707  +	mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst
   699    708   	chmod a-w $(distdir)
   700    709   	test -d $(distdir)/_build || exit 0; \
   701    710   	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
   702    711   	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
   703    712   	  && am__cwd=`pwd` \
   704         -	  && $(am__cd) $(distdir)/_build \
   705         -	  && ../configure \
          713  +	  && $(am__cd) $(distdir)/_build/sub \
          714  +	  && ../../configure \
   706    715   	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
   707    716   	    $(DISTCHECK_CONFIGURE_FLAGS) \
   708         -	    --srcdir=.. --prefix="$$dc_install_base" \
          717  +	    --srcdir=../.. --prefix="$$dc_install_base" \
   709    718   	  && $(MAKE) $(AM_MAKEFLAGS) \
   710    719   	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
   711    720   	  && $(MAKE) $(AM_MAKEFLAGS) check \
   712    721   	  && $(MAKE) $(AM_MAKEFLAGS) install \
   713    722   	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
   714    723   	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
   715    724   	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
................................................................................
   882    891   	install-man install-pdf install-pdf-am install-pkgconfigDATA \
   883    892   	install-ps install-ps-am install-strip installcheck \
   884    893   	installcheck-am installdirs installdirs-am maintainer-clean \
   885    894   	maintainer-clean-generic mostlyclean mostlyclean-generic \
   886    895   	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
   887    896   	uninstall-am uninstall-pkgconfigDATA
   888    897   
          898  +.PRECIOUS: Makefile
          899  +
   889    900   
   890    901   coverage-init:
   891    902   	lcov --directory src --capture --initial --output-file rasterlite2_cov.info
   892    903   
   893    904   coverage::
   894    905   	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture
          906  +	lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info
   895    907   	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info
   896    908   
   897    909   # Tell versions [3.59,3.63) of GNU make to not export all variables.
   898    910   # Otherwise a system limit (for SysV at least) may be exceeded.
   899    911   .NOEXPORT:

Changes to aclocal.m4.

     1         -# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
            1  +# generated automatically by aclocal 1.15 -*- Autoconf -*-
     2      2   
     3         -# Copyright (C) 1996-2013 Free Software Foundation, Inc.
            3  +# Copyright (C) 1996-2014 Free Software Foundation, Inc.
     4      4   
     5      5   # This file is free software; the Free Software Foundation
     6      6   # gives unlimited permission to copy and/or distribute it,
     7      7   # with or without modifications, as long as this notice is preserved.
     8      8   
     9      9   # This program is distributed in the hope that it will be useful,
    10     10   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................
   231    231   
   232    232   _PKG_CONFIG([$1], [variable="][$3]["], [$2])
   233    233   AS_VAR_COPY([$1], [pkg_cv_][$1])
   234    234   
   235    235   AS_VAR_IF([$1], [""], [$5], [$4])dnl
   236    236   ])# PKG_CHECK_VAR
   237    237   
   238         -# Copyright (C) 2002-2013 Free Software Foundation, Inc.
          238  +# Copyright (C) 2002-2014 Free Software Foundation, Inc.
   239    239   #
   240    240   # This file is free software; the Free Software Foundation
   241    241   # gives unlimited permission to copy and/or distribute it,
   242    242   # with or without modifications, as long as this notice is preserved.
   243    243   
   244    244   # AM_AUTOMAKE_VERSION(VERSION)
   245    245   # ----------------------------
   246    246   # Automake X.Y traces this macro to ensure aclocal.m4 has been
   247    247   # generated from the m4 files accompanying Automake X.Y.
   248    248   # (This private macro should not be called outside this file.)
   249    249   AC_DEFUN([AM_AUTOMAKE_VERSION],
   250         -[am__api_version='1.14'
          250  +[am__api_version='1.15'
   251    251   dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
   252    252   dnl require some minimum version.  Point them to the right macro.
   253         -m4_if([$1], [1.14.1], [],
          253  +m4_if([$1], [1.15], [],
   254    254         [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
   255    255   ])
   256    256   
   257    257   # _AM_AUTOCONF_VERSION(VERSION)
   258    258   # -----------------------------
   259    259   # aclocal traces this macro to find the Autoconf version.
   260    260   # This is a private macro too.  Using m4_define simplifies
................................................................................
   262    262   m4_define([_AM_AUTOCONF_VERSION], [])
   263    263   
   264    264   # AM_SET_CURRENT_AUTOMAKE_VERSION
   265    265   # -------------------------------
   266    266   # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
   267    267   # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
   268    268   AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
   269         -[AM_AUTOMAKE_VERSION([1.14.1])dnl
          269  +[AM_AUTOMAKE_VERSION([1.15])dnl
   270    270   m4_ifndef([AC_AUTOCONF_VERSION],
   271    271     [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
   272    272   _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
   273    273   
   274    274   # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
   275    275   
   276         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
          276  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
   277    277   #
   278    278   # This file is free software; the Free Software Foundation
   279    279   # gives unlimited permission to copy and/or distribute it,
   280    280   # with or without modifications, as long as this notice is preserved.
   281    281   
   282    282   # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
   283    283   # $ac_aux_dir to '$srcdir/foo'.  In other projects, it is set to
................................................................................
   314    314   # configure, and could therefore not use this "fixed" $ac_aux_dir.
   315    315   #
   316    316   # Another solution, used here, is to always expand $ac_aux_dir to an
   317    317   # absolute PATH.  The drawback is that using absolute paths prevent a
   318    318   # configured tree to be moved without reconfiguration.
   319    319   
   320    320   AC_DEFUN([AM_AUX_DIR_EXPAND],
   321         -[dnl Rely on autoconf to set up CDPATH properly.
   322         -AC_PREREQ([2.50])dnl
   323         -# expand $ac_aux_dir to an absolute path
   324         -am_aux_dir=`cd $ac_aux_dir && pwd`
          321  +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
          322  +# Expand $ac_aux_dir to an absolute path.
          323  +am_aux_dir=`cd "$ac_aux_dir" && pwd`
   325    324   ])
   326    325   
   327    326   # AM_CONDITIONAL                                            -*- Autoconf -*-
   328    327   
   329         -# Copyright (C) 1997-2013 Free Software Foundation, Inc.
          328  +# Copyright (C) 1997-2014 Free Software Foundation, Inc.
   330    329   #
   331    330   # This file is free software; the Free Software Foundation
   332    331   # gives unlimited permission to copy and/or distribute it,
   333    332   # with or without modifications, as long as this notice is preserved.
   334    333   
   335    334   # AM_CONDITIONAL(NAME, SHELL-CONDITION)
   336    335   # -------------------------------------
................................................................................
   353    352   fi
   354    353   AC_CONFIG_COMMANDS_PRE(
   355    354   [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
   356    355     AC_MSG_ERROR([[conditional "$1" was never defined.
   357    356   Usually this means the macro was only invoked conditionally.]])
   358    357   fi])])
   359    358   
   360         -# Copyright (C) 1999-2013 Free Software Foundation, Inc.
          359  +# Copyright (C) 1999-2014 Free Software Foundation, Inc.
   361    360   #
   362    361   # This file is free software; the Free Software Foundation
   363    362   # gives unlimited permission to copy and/or distribute it,
   364    363   # with or without modifications, as long as this notice is preserved.
   365    364   
   366    365   
   367    366   # There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
................................................................................
   544    543   _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
   545    544   AC_SUBST([am__nodep])dnl
   546    545   _AM_SUBST_NOTMAKE([am__nodep])dnl
   547    546   ])
   548    547   
   549    548   # Generate code to set up dependency tracking.              -*- Autoconf -*-
   550    549   
   551         -# Copyright (C) 1999-2013 Free Software Foundation, Inc.
          550  +# Copyright (C) 1999-2014 Free Software Foundation, Inc.
   552    551   #
   553    552   # This file is free software; the Free Software Foundation
   554    553   # gives unlimited permission to copy and/or distribute it,
   555    554   # with or without modifications, as long as this notice is preserved.
   556    555   
   557    556   
   558    557   # _AM_OUTPUT_DEPENDENCY_COMMANDS
................................................................................
   620    619   [AC_CONFIG_COMMANDS([depfiles],
   621    620        [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
   622    621        [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
   623    622   ])
   624    623   
   625    624   # Do all the work for Automake.                             -*- Autoconf -*-
   626    625   
   627         -# Copyright (C) 1996-2013 Free Software Foundation, Inc.
          626  +# Copyright (C) 1996-2014 Free Software Foundation, Inc.
   628    627   #
   629    628   # This file is free software; the Free Software Foundation
   630    629   # gives unlimited permission to copy and/or distribute it,
   631    630   # with or without modifications, as long as this notice is preserved.
   632    631   
   633    632   # This macro actually does too much.  Some checks are only needed if
   634    633   # your package does certain things.  But this isn't really a big deal.
................................................................................
   710    709   AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
   711    710   AC_REQUIRE([AC_PROG_MKDIR_P])dnl
   712    711   # For better backward compatibility.  To be removed once Automake 1.9.x
   713    712   # dies out for good.  For more background, see:
   714    713   # <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
   715    714   # <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
   716    715   AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
   717         -# We need awk for the "check" target.  The system "awk" is bad on
   718         -# some platforms.
          716  +# We need awk for the "check" target (and possibly the TAP driver).  The
          717  +# system "awk" is bad on some platforms.
   719    718   AC_REQUIRE([AC_PROG_AWK])dnl
   720    719   AC_REQUIRE([AC_PROG_MAKE_SET])dnl
   721    720   AC_REQUIRE([AM_SET_LEADING_DOT])dnl
   722    721   _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
   723    722   	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
   724    723   			     [_AM_PROG_TAR([v7])])])
   725    724   _AM_IF_OPTION([no-dependencies],,
................................................................................
   784    783   If you want to complete the configuration process using your problematic
   785    784   'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
   786    785   to "yes", and re-run configure.
   787    786   
   788    787   END
   789    788       AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
   790    789     fi
   791         -fi])
          790  +fi
          791  +dnl The trailing newline in this macro's definition is deliberate, for
          792  +dnl backward compatibility and to allow trailing 'dnl'-style comments
          793  +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841.
          794  +])
   792    795   
   793    796   dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
   794    797   dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
   795    798   dnl mangled by Autoconf and run in a shell conditional statement.
   796    799   m4_define([_AC_COMPILER_EXEEXT],
   797    800   m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
   798    801   
................................................................................
   813    816         break ;;
   814    817       * )
   815    818         _am_stamp_count=`expr $_am_stamp_count + 1` ;;
   816    819     esac
   817    820   done
   818    821   echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
   819    822   
   820         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
          823  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
   821    824   #
   822    825   # This file is free software; the Free Software Foundation
   823    826   # gives unlimited permission to copy and/or distribute it,
   824    827   # with or without modifications, as long as this notice is preserved.
   825    828   
   826    829   # AM_PROG_INSTALL_SH
   827    830   # ------------------
   828    831   # Define $install_sh.
   829    832   AC_DEFUN([AM_PROG_INSTALL_SH],
   830    833   [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
   831         -if test x"${install_sh}" != xset; then
          834  +if test x"${install_sh+set}" != xset; then
   832    835     case $am_aux_dir in
   833    836     *\ * | *\	*)
   834    837       install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
   835    838     *)
   836    839       install_sh="\${SHELL} $am_aux_dir/install-sh"
   837    840     esac
   838    841   fi
   839    842   AC_SUBST([install_sh])])
   840    843   
   841         -# Copyright (C) 2003-2013 Free Software Foundation, Inc.
          844  +# Copyright (C) 2003-2014 Free Software Foundation, Inc.
   842    845   #
   843    846   # This file is free software; the Free Software Foundation
   844    847   # gives unlimited permission to copy and/or distribute it,
   845    848   # with or without modifications, as long as this notice is preserved.
   846    849   
   847    850   # Check whether the underlying file-system supports filenames
   848    851   # with a leading dot.  For instance MS-DOS doesn't.
................................................................................
   856    859   fi
   857    860   rmdir .tst 2>/dev/null
   858    861   AC_SUBST([am__leading_dot])])
   859    862   
   860    863   # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
   861    864   # From Jim Meyering
   862    865   
   863         -# Copyright (C) 1996-2013 Free Software Foundation, Inc.
          866  +# Copyright (C) 1996-2014 Free Software Foundation, Inc.
   864    867   #
   865    868   # This file is free software; the Free Software Foundation
   866    869   # gives unlimited permission to copy and/or distribute it,
   867    870   # with or without modifications, as long as this notice is preserved.
   868    871   
   869    872   # AM_MAINTAINER_MODE([DEFAULT-MODE])
   870    873   # ----------------------------------
................................................................................
   891    894     MAINT=$MAINTAINER_MODE_TRUE
   892    895     AC_SUBST([MAINT])dnl
   893    896   ]
   894    897   )
   895    898   
   896    899   # Check to see how 'make' treats includes.	            -*- Autoconf -*-
   897    900   
   898         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
          901  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
   899    902   #
   900    903   # This file is free software; the Free Software Foundation
   901    904   # gives unlimited permission to copy and/or distribute it,
   902    905   # with or without modifications, as long as this notice is preserved.
   903    906   
   904    907   # AM_MAKE_INCLUDE()
   905    908   # -----------------
................................................................................
   941    944   AC_SUBST([am__quote])
   942    945   AC_MSG_RESULT([$_am_result])
   943    946   rm -f confinc confmf
   944    947   ])
   945    948   
   946    949   # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
   947    950   
   948         -# Copyright (C) 1997-2013 Free Software Foundation, Inc.
          951  +# Copyright (C) 1997-2014 Free Software Foundation, Inc.
   949    952   #
   950    953   # This file is free software; the Free Software Foundation
   951    954   # gives unlimited permission to copy and/or distribute it,
   952    955   # with or without modifications, as long as this notice is preserved.
   953    956   
   954    957   # AM_MISSING_PROG(NAME, PROGRAM)
   955    958   # ------------------------------
................................................................................
   982    985   fi
   983    986   ])
   984    987   
   985    988   #  -*- Autoconf -*-
   986    989   # Obsolete and "removed" macros, that must however still report explicit
   987    990   # error messages when used, to smooth transition.
   988    991   #
   989         -# Copyright (C) 1996-2013 Free Software Foundation, Inc.
          992  +# Copyright (C) 1996-2014 Free Software Foundation, Inc.
   990    993   #
   991    994   # This file is free software; the Free Software Foundation
   992    995   # gives unlimited permission to copy and/or distribute it,
   993    996   # with or without modifications, as long as this notice is preserved.
   994    997   
   995    998   AC_DEFUN([AM_CONFIG_HEADER],
   996    999   [AC_DIAGNOSE([obsolete],
................................................................................
  1009   1012   
  1010   1013   AC_DEFUN([AM_C_PROTOTYPES],
  1011   1014            [AC_FATAL([automatic de-ANSI-fication support has been removed])])
  1012   1015   AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES])
  1013   1016   
  1014   1017   # Helper functions for option handling.                     -*- Autoconf -*-
  1015   1018   
  1016         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
         1019  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1017   1020   #
  1018   1021   # This file is free software; the Free Software Foundation
  1019   1022   # gives unlimited permission to copy and/or distribute it,
  1020   1023   # with or without modifications, as long as this notice is preserved.
  1021   1024   
  1022   1025   # _AM_MANGLE_OPTION(NAME)
  1023   1026   # -----------------------
................................................................................
  1038   1041   
  1039   1042   # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
  1040   1043   # -------------------------------------------
  1041   1044   # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
  1042   1045   AC_DEFUN([_AM_IF_OPTION],
  1043   1046   [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
  1044   1047   
  1045         -# Copyright (C) 1999-2013 Free Software Foundation, Inc.
         1048  +# Copyright (C) 1999-2014 Free Software Foundation, Inc.
  1046   1049   #
  1047   1050   # This file is free software; the Free Software Foundation
  1048   1051   # gives unlimited permission to copy and/or distribute it,
  1049   1052   # with or without modifications, as long as this notice is preserved.
  1050   1053   
  1051   1054   # _AM_PROG_CC_C_O
  1052   1055   # ---------------
................................................................................
  1085   1088      CC="$am_aux_dir/compile $CC"
  1086   1089   fi
  1087   1090   AC_LANG_POP([C])])
  1088   1091   
  1089   1092   # For backward compatibility.
  1090   1093   AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
  1091   1094   
  1092         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
         1095  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1093   1096   #
  1094   1097   # This file is free software; the Free Software Foundation
  1095   1098   # gives unlimited permission to copy and/or distribute it,
  1096   1099   # with or without modifications, as long as this notice is preserved.
  1097   1100   
  1098   1101   # AM_RUN_LOG(COMMAND)
  1099   1102   # -------------------
................................................................................
  1104   1107      ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
  1105   1108      ac_status=$?
  1106   1109      echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
  1107   1110      (exit $ac_status); }])
  1108   1111   
  1109   1112   # Check to make sure that the build environment is sane.    -*- Autoconf -*-
  1110   1113   
  1111         -# Copyright (C) 1996-2013 Free Software Foundation, Inc.
         1114  +# Copyright (C) 1996-2014 Free Software Foundation, Inc.
  1112   1115   #
  1113   1116   # This file is free software; the Free Software Foundation
  1114   1117   # gives unlimited permission to copy and/or distribute it,
  1115   1118   # with or without modifications, as long as this notice is preserved.
  1116   1119   
  1117   1120   # AM_SANITY_CHECK
  1118   1121   # ---------------
................................................................................
  1185   1188        # Hide warnings about reused PIDs.
  1186   1189        wait $am_sleep_pid 2>/dev/null
  1187   1190      fi
  1188   1191      AC_MSG_RESULT([done])])
  1189   1192   rm -f conftest.file
  1190   1193   ])
  1191   1194   
  1192         -# Copyright (C) 2009-2013 Free Software Foundation, Inc.
         1195  +# Copyright (C) 2009-2014 Free Software Foundation, Inc.
  1193   1196   #
  1194   1197   # This file is free software; the Free Software Foundation
  1195   1198   # gives unlimited permission to copy and/or distribute it,
  1196   1199   # with or without modifications, as long as this notice is preserved.
  1197   1200   
  1198   1201   # AM_SILENT_RULES([DEFAULT])
  1199   1202   # --------------------------
................................................................................
  1245   1248   AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
  1246   1249   AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
  1247   1250   AM_BACKSLASH='\'
  1248   1251   AC_SUBST([AM_BACKSLASH])dnl
  1249   1252   _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
  1250   1253   ])
  1251   1254   
  1252         -# Copyright (C) 2001-2013 Free Software Foundation, Inc.
         1255  +# Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1253   1256   #
  1254   1257   # This file is free software; the Free Software Foundation
  1255   1258   # gives unlimited permission to copy and/or distribute it,
  1256   1259   # with or without modifications, as long as this notice is preserved.
  1257   1260   
  1258   1261   # AM_PROG_INSTALL_STRIP
  1259   1262   # ---------------------
................................................................................
  1273   1276   dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
  1274   1277   if test "$cross_compiling" != no; then
  1275   1278     AC_CHECK_TOOL([STRIP], [strip], :)
  1276   1279   fi
  1277   1280   INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
  1278   1281   AC_SUBST([INSTALL_STRIP_PROGRAM])])
  1279   1282   
  1280         -# Copyright (C) 2006-2013 Free Software Foundation, Inc.
         1283  +# Copyright (C) 2006-2014 Free Software Foundation, Inc.
  1281   1284   #
  1282   1285   # This file is free software; the Free Software Foundation
  1283   1286   # gives unlimited permission to copy and/or distribute it,
  1284   1287   # with or without modifications, as long as this notice is preserved.
  1285   1288   
  1286   1289   # _AM_SUBST_NOTMAKE(VARIABLE)
  1287   1290   # ---------------------------
................................................................................
  1292   1295   # AM_SUBST_NOTMAKE(VARIABLE)
  1293   1296   # --------------------------
  1294   1297   # Public sister of _AM_SUBST_NOTMAKE.
  1295   1298   AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
  1296   1299   
  1297   1300   # Check how to create a tarball.                            -*- Autoconf -*-
  1298   1301   
  1299         -# Copyright (C) 2004-2013 Free Software Foundation, Inc.
         1302  +# Copyright (C) 2004-2014 Free Software Foundation, Inc.
  1300   1303   #
  1301   1304   # This file is free software; the Free Software Foundation
  1302   1305   # gives unlimited permission to copy and/or distribute it,
  1303   1306   # with or without modifications, as long as this notice is preserved.
  1304   1307   
  1305   1308   # _AM_PROG_TAR(FORMAT)
  1306   1309   # --------------------

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-rc1.
            3  +# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-devel.
     4      4   #
     5      5   # Report bugs to <a.furieri@lqt.it>.
     6      6   #
     7      7   #
     8      8   # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
     9      9   #
    10     10   #
................................................................................
   586    586   subdirs=
   587    587   MFLAGS=
   588    588   MAKEFLAGS=
   589    589   
   590    590   # Identity of this package.
   591    591   PACKAGE_NAME='librasterlite2'
   592    592   PACKAGE_TARNAME='librasterlite2'
   593         -PACKAGE_VERSION='1.0.0-rc1'
   594         -PACKAGE_STRING='librasterlite2 1.0.0-rc1'
          593  +PACKAGE_VERSION='1.0.0-devel'
          594  +PACKAGE_STRING='librasterlite2 1.0.0-devel'
   595    595   PACKAGE_BUGREPORT='a.furieri@lqt.it'
   596    596   PACKAGE_URL=''
   597    597   
   598    598   # Factoring default headers for most tests.
   599    599   ac_includes_default="\
   600    600   #include <stdio.h>
   601    601   #ifdef HAVE_SYS_TYPES_H
................................................................................
  1368   1368   #
  1369   1369   # Report the --help message.
  1370   1370   #
  1371   1371   if test "$ac_init_help" = "long"; then
  1372   1372     # Omit some internal or obsolete options to make the list less imposing.
  1373   1373     # This message is too long to be a string in the A/UX 3.1 sh.
  1374   1374     cat <<_ACEOF
  1375         -\`configure' configures librasterlite2 1.0.0-rc1 to adapt to many kinds of systems.
         1375  +\`configure' configures librasterlite2 1.0.0-devel to adapt to many kinds of systems.
  1376   1376   
  1377   1377   Usage: $0 [OPTION]... [VAR=VALUE]...
  1378   1378   
  1379   1379   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1380   1380   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1381   1381   
  1382   1382   Defaults for the options are specified in brackets.
................................................................................
  1438   1438     --build=BUILD     configure for building on BUILD [guessed]
  1439   1439     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1440   1440   _ACEOF
  1441   1441   fi
  1442   1442   
  1443   1443   if test -n "$ac_init_help"; then
  1444   1444     case $ac_init_help in
  1445         -     short | recursive ) echo "Configuration of librasterlite2 1.0.0-rc1:";;
         1445  +     short | recursive ) echo "Configuration of librasterlite2 1.0.0-devel:";;
  1446   1446      esac
  1447   1447     cat <<\_ACEOF
  1448   1448   
  1449   1449   Optional Features:
  1450   1450     --disable-option-checking  ignore unrecognized --enable/--with options
  1451   1451     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1452   1452     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1590   1590       cd "$ac_pwd" || { ac_status=$?; break; }
  1591   1591     done
  1592   1592   fi
  1593   1593   
  1594   1594   test -n "$ac_init_help" && exit $ac_status
  1595   1595   if $ac_init_version; then
  1596   1596     cat <<\_ACEOF
  1597         -librasterlite2 configure 1.0.0-rc1
         1597  +librasterlite2 configure 1.0.0-devel
  1598   1598   generated by GNU Autoconf 2.69
  1599   1599   
  1600   1600   Copyright (C) 2012 Free Software Foundation, Inc.
  1601   1601   This configure script is free software; the Free Software Foundation
  1602   1602   gives unlimited permission to copy, distribute and modify it.
  1603   1603   _ACEOF
  1604   1604     exit
................................................................................
  2134   2134     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2135   2135   
  2136   2136   } # ac_fn_c_check_type
  2137   2137   cat >config.log <<_ACEOF
  2138   2138   This file contains any messages produced by compilers while
  2139   2139   running configure, to aid debugging if configure makes a mistake.
  2140   2140   
  2141         -It was created by librasterlite2 $as_me 1.0.0-rc1, which was
         2141  +It was created by librasterlite2 $as_me 1.0.0-devel, which was
  2142   2142   generated by GNU Autoconf 2.69.  Invocation command line was
  2143   2143   
  2144   2144     $ $0 $@
  2145   2145   
  2146   2146   _ACEOF
  2147   2147   exec 5>>config.log
  2148   2148   {
................................................................................
  2519   2519   ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
  2520   2520   ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
  2521   2521   ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
  2522   2522   
  2523   2523   
  2524   2524   
  2525   2525   
  2526         -am__api_version='1.14'
         2526  +am__api_version='1.15'
  2527   2527   
  2528   2528   # Find a good install program.  We prefer a C program (faster),
  2529   2529   # so one script is as good as another.  But avoid the broken or
  2530   2530   # incompatible versions:
  2531   2531   # SysV /etc/install, /usr/sbin/install
  2532   2532   # SunOS /usr/etc/install
  2533   2533   # IRIX /sbin/install
................................................................................
  2691   2691   test "$program_suffix" != NONE &&
  2692   2692     program_transform_name="s&\$&$program_suffix&;$program_transform_name"
  2693   2693   # Double any \ or $.
  2694   2694   # By default was `s,x,x', remove it if useless.
  2695   2695   ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
  2696   2696   program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
  2697   2697   
  2698         -# expand $ac_aux_dir to an absolute path
  2699         -am_aux_dir=`cd $ac_aux_dir && pwd`
         2698  +# Expand $ac_aux_dir to an absolute path.
         2699  +am_aux_dir=`cd "$ac_aux_dir" && pwd`
  2700   2700   
  2701   2701   if test x"${MISSING+set}" != xset; then
  2702   2702     case $am_aux_dir in
  2703   2703     *\ * | *\	*)
  2704   2704       MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
  2705   2705     *)
  2706   2706       MISSING="\${SHELL} $am_aux_dir/missing" ;;
................................................................................
  2711   2711     am_missing_run="$MISSING "
  2712   2712   else
  2713   2713     am_missing_run=
  2714   2714     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
  2715   2715   $as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
  2716   2716   fi
  2717   2717   
  2718         -if test x"${install_sh}" != xset; then
         2718  +if test x"${install_sh+set}" != xset; then
  2719   2719     case $am_aux_dir in
  2720   2720     *\ * | *\	*)
  2721   2721       install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
  2722   2722     *)
  2723   2723       install_sh="\${SHELL} $am_aux_dir/install-sh"
  2724   2724     esac
  2725   2725   fi
................................................................................
  3005   3005       CYGPATH_W=echo
  3006   3006     fi
  3007   3007   fi
  3008   3008   
  3009   3009   
  3010   3010   # Define the identity of the package.
  3011   3011    PACKAGE='librasterlite2'
  3012         - VERSION='1.0.0-rc1'
         3012  + VERSION='1.0.0-devel'
  3013   3013   
  3014   3014   
  3015   3015   cat >>confdefs.h <<_ACEOF
  3016   3016   #define PACKAGE "$PACKAGE"
  3017   3017   _ACEOF
  3018   3018   
  3019   3019   
................................................................................
  3039   3039   
  3040   3040   # For better backward compatibility.  To be removed once Automake 1.9.x
  3041   3041   # dies out for good.  For more background, see:
  3042   3042   # <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
  3043   3043   # <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
  3044   3044   mkdir_p='$(MKDIR_P)'
  3045   3045   
  3046         -# We need awk for the "check" target.  The system "awk" is bad on
  3047         -# some platforms.
         3046  +# We need awk for the "check" target (and possibly the TAP driver).  The
         3047  +# system "awk" is bad on some platforms.
  3048   3048   # Always define AMTAR for backward compatibility.  Yes, it's still used
  3049   3049   # in the wild :-(  We should find a proper way to deprecate it ...
  3050   3050   AMTAR='$${TAR-tar}'
  3051   3051   
  3052   3052   
  3053   3053   # We'll loop over all known methods to create a tar archive until one works.
  3054   3054   _am_tools='gnutar  pax cpio none'
................................................................................
  3097   3097   'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
  3098   3098   to "yes", and re-run configure.
  3099   3099   
  3100   3100   END
  3101   3101       as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
  3102   3102     fi
  3103   3103   fi
         3104  +
  3104   3105   
  3105   3106   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
  3106   3107   $as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
  3107   3108       # Check whether --enable-maintainer-mode was given.
  3108   3109   if test "${enable_maintainer_mode+set}" = set; then :
  3109   3110     enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
  3110   3111   else
................................................................................
 19156  19157   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 19157  19158   
 19158  19159   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 19159  19160   # Save the log message, to keep $0 and so on meaningful, and to
 19160  19161   # report actual input values of CONFIG_FILES etc. instead of their
 19161  19162   # values after options handling.
 19162  19163   ac_log="
 19163         -This file was extended by librasterlite2 $as_me 1.0.0-rc1, which was
        19164  +This file was extended by librasterlite2 $as_me 1.0.0-devel, which was
 19164  19165   generated by GNU Autoconf 2.69.  Invocation command line was
 19165  19166   
 19166  19167     CONFIG_FILES    = $CONFIG_FILES
 19167  19168     CONFIG_HEADERS  = $CONFIG_HEADERS
 19168  19169     CONFIG_LINKS    = $CONFIG_LINKS
 19169  19170     CONFIG_COMMANDS = $CONFIG_COMMANDS
 19170  19171     $ $0 $@
................................................................................
 19222  19223   
 19223  19224   Report bugs to <a.furieri@lqt.it>."
 19224  19225   
 19225  19226   _ACEOF
 19226  19227   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 19227  19228   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 19228  19229   ac_cs_version="\\
 19229         -librasterlite2 config.status 1.0.0-rc1
        19230  +librasterlite2 config.status 1.0.0-devel
 19230  19231   configured by $0, generated by GNU Autoconf 2.69,
 19231  19232     with options \\"\$ac_cs_config\\"
 19232  19233   
 19233  19234   Copyright (C) 2012 Free Software Foundation, Inc.
 19234  19235   This config.status script is free software; the Free Software Foundation
 19235  19236   gives unlimited permission to copy, distribute and modify it."
 19236  19237   

Changes to configure.ac.

     1      1   #                                               -*- Autoconf -*-
     2      2   # Process this file with autoconf to produce a configure script.
     3      3   
     4      4   AC_PREREQ(2.61)
     5         -AC_INIT(librasterlite2, 1.0.0-rc1, a.furieri@lqt.it)
            5  +AC_INIT(librasterlite2, 1.0.0-devel, a.furieri@lqt.it)
     6      6   AC_LANG(C)
     7      7   AC_CONFIG_AUX_DIR([.])
     8      8   AC_CONFIG_MACRO_DIR([m4])
     9      9   
    10     10   AM_INIT_AUTOMAKE
    11     11   AM_MAINTAINER_MODE
    12     12   AM_CONFIG_HEADER(config.h)

Changes to headers/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   
    17     17   VPATH = @srcdir@
    18         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           18  +am__is_gnu_make = { \
           19  +  if test -z '$(MAKELEVEL)'; then \
           20  +    false; \
           21  +  elif test -n '$(MAKE_HOST)'; then \
           22  +    true; \
           23  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           24  +    true; \
           25  +  else \
           26  +    false; \
           27  +  fi; \
           28  +}
    19     29   am__make_running_with_option = \
    20     30     case $${target_option-} in \
    21     31         ?) ;; \
    22     32         *) echo "am__make_running_with_option: internal error: invalid" \
    23     33                 "target option '$${target_option-}' specified" >&2; \
    24     34            exit 1;; \
    25     35     esac; \
................................................................................
    75     85   POST_INSTALL = :
    76     86   NORMAL_UNINSTALL = :
    77     87   PRE_UNINSTALL = :
    78     88   POST_UNINSTALL = :
    79     89   build_triplet = @build@
    80     90   host_triplet = @host@
    81     91   subdir = headers
    82         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
    83         -	$(nobase_include_HEADERS) $(noinst_HEADERS)
    84     92   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    85     93   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    86     94   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    87     95   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    88     96   	$(top_srcdir)/configure.ac
    89     97   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    90     98   	$(ACLOCAL_M4)
           99  +DIST_COMMON = $(srcdir)/Makefile.am $(nobase_include_HEADERS) \
          100  +	$(noinst_HEADERS) $(am__DIST_COMMON)
    91    101   mkinstalldirs = $(install_sh) -d
    92    102   CONFIG_HEADER = $(top_builddir)/config.h
    93    103   CONFIG_CLEAN_FILES =
    94    104   CONFIG_CLEAN_VPATH_FILES =
    95    105   AM_V_P = $(am__v_P_@AM_V@)
    96    106   am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
    97    107   am__v_P_0 = false
................................................................................
   155    165   am__define_uniq_tagged_files = \
   156    166     list='$(am__tagged_files)'; \
   157    167     unique=`for i in $$list; do \
   158    168       if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   159    169     done | $(am__uniquify_input)`
   160    170   ETAGS = etags
   161    171   CTAGS = ctags
          172  +am__DIST_COMMON = $(srcdir)/Makefile.in
   162    173   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   163    174   ACLOCAL = @ACLOCAL@
   164    175   AMTAR = @AMTAR@
   165    176   AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
   166    177   AR = @AR@
   167    178   AS = @AS@
   168    179   AUTOCONF = @AUTOCONF@
................................................................................
   321    332   	        && { if test -f $@; then exit 0; else break; fi; }; \
   322    333   	      exit 1;; \
   323    334   	  esac; \
   324    335   	done; \
   325    336   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu headers/Makefile'; \
   326    337   	$(am__cd) $(top_srcdir) && \
   327    338   	  $(AUTOMAKE) --gnu headers/Makefile
   328         -.PRECIOUS: Makefile
   329    339   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   330    340   	@case '$?' in \
   331    341   	  *config.status*) \
   332    342   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   333    343   	  *) \
   334    344   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   335    345   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
   570    580   	install-info install-info-am install-man \
   571    581   	install-nobase_includeHEADERS install-pdf install-pdf-am \
   572    582   	install-ps install-ps-am install-strip installcheck \
   573    583   	installcheck-am installdirs maintainer-clean \
   574    584   	maintainer-clean-generic mostlyclean mostlyclean-generic \
   575    585   	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
   576    586   	uninstall-am uninstall-nobase_includeHEADERS
          587  +
          588  +.PRECIOUS: Makefile
   577    589   
   578    590   
   579    591   # Tell versions [3.59,3.63) of GNU make to not export all variables.
   580    592   # Otherwise a system limit (for SysV at least) may be exceeded.
   581    593   .NOEXPORT:

Changes to headers/rasterlite2/rasterlite2.h.

  3465   3465       RL2_DECLARE int rl2_load_raw_raster_into_dbms (sqlite3 * sqlite,
  3466   3466   						   int max_threads,
  3467   3467   						   rl2CoveragePtr cvg,
  3468   3468   						   const char *sctn_name,
  3469   3469   						   rl2RasterPtr rst,
  3470   3470   						   int pyramidize);
  3471   3471   
         3472  +    RL2_DECLARE int rl2_load_raw_tiles_into_dbms (sqlite3 * sqlite,
         3473  +						  rl2CoveragePtr cvg,
         3474  +						  const char *sctn_name,
         3475  +						  unsigned int sctn_width,
         3476  +						  unsigned int sctn_height,
         3477  +						  int sctn_srid,
         3478  +						  double sctn_minx,
         3479  +						  double sctn_miny,
         3480  +						  double sctn_maxx,
         3481  +						  double sctn_maxy,
         3482  +						  int (*getTile) (void *data,
         3483  +								  double
         3484  +								  tile_minx,
         3485  +								  double
         3486  +								  tile_miny,
         3487  +								  double
         3488  +								  tile_maxx,
         3489  +								  double
         3490  +								  tile_maxy,
         3491  +								  unsigned char
         3492  +								  *bufpix,
         3493  +								  rl2PalettePtr
         3494  +								  * palette),
         3495  +						  void *data, int pyramidize);
         3496  +
  3472   3497       RL2_DECLARE int
  3473   3498   	rl2_get_raw_raster_data (sqlite3 * handle, int max_threads,
  3474   3499   				 rl2CoveragePtr cvg, unsigned int width,
  3475   3500   				 unsigned int height, double minx, double miny,
  3476   3501   				 double maxx, double maxy, double x_res,
  3477   3502   				 double y_res, unsigned char **buffer,
  3478   3503   				 int *buf_size, rl2PalettePtr * palette,
  3479   3504   				 unsigned char out_pixel);
  3480   3505   
         3506  +    RL2_DECLARE int
         3507  +	rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads,
         3508  +				 rl2CoveragePtr cvg, unsigned int width,
         3509  +				 unsigned int height, double minx, double miny,
         3510  +				 double maxx, double maxy, double x_res,
         3511  +				 double y_res, unsigned char **mask,
         3512  +				 int *mask_size);
         3513  +
  3481   3514       RL2_DECLARE int
  3482   3515   	rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
  3483   3516   					 rl2CoveragePtr cvg,
  3484   3517   					 sqlite3_int64 section_id,
  3485   3518   					 unsigned int width,
  3486   3519   					 unsigned int height, double minx,
  3487   3520   					 double miny, double maxx, double maxy,
  3488   3521   					 double x_res, double y_res,
  3489   3522   					 unsigned char **buffer, int *buf_size,
  3490   3523   					 rl2PalettePtr * palette,
  3491   3524   					 unsigned char out_pixel);
  3492   3525   
         3526  +    RL2_DECLARE int
         3527  +	rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads,
         3528  +					 rl2CoveragePtr cvg,
         3529  +					 sqlite3_int64 section_id,
         3530  +					 unsigned int width,
         3531  +					 unsigned int height, double minx,
         3532  +					 double miny, double maxx, double maxy,
         3533  +					 double x_res, double y_res,
         3534  +					 unsigned char **mask, int *mask_size);
         3535  +
  3493   3536       RL2_DECLARE int
  3494   3537   	rl2_get_triple_band_raw_raster_data (sqlite3 * handle,
  3495   3538   					     rl2CoveragePtr cvg,
  3496   3539   					     unsigned int width,
  3497   3540   					     unsigned int height,
  3498   3541   					     double minx, double miny,
  3499   3542   					     double maxx, double maxy,
................................................................................
  3673   3716       RL2_DECLARE int
  3674   3717   	rl2_compare_palettes (rl2PalettePtr palette_1, rl2PalettePtr palette_2);
  3675   3718   
  3676   3719       RL2_DECLARE int
  3677   3720   	rl2_check_dbms_palette (sqlite3 * handle, rl2CoveragePtr cvg,
  3678   3721   				rl2TiffOriginPtr tiff);
  3679   3722   
         3723  +    RL2_DECLARE int
         3724  +	rl2_install_dbms_palette_from_tiff (sqlite3 * handle,
         3725  +					    rl2CoveragePtr cvg,
         3726  +					    rl2TiffOriginPtr tiff);
         3727  +
  3680   3728       RL2_DECLARE int
  3681   3729   	rl2_serialize_dbms_pixel (rl2PixelPtr pixel, unsigned char **blob,
  3682   3730   				  int *blob_size);
  3683   3731   
  3684   3732       RL2_DECLARE int
  3685   3733   	rl2_is_valid_dbms_pixel (const unsigned char *blob, int blob_size,
  3686   3734   				 unsigned char sample_type,

Changes to headers/rasterlite2/rl2graphics.h.

  1339   1339       RL2_DECLARE int rl2_graph_draw_rescaled_bitmap (rl2GraphicsContextPtr
  1340   1340   						    context,
  1341   1341   						    rl2GraphicsBitmapPtr bitmap,
  1342   1342   						    double scale_x,
  1343   1343   						    double scale_y, double x,
  1344   1344   						    double y);
  1345   1345   
         1346  +/**
         1347  + Rescales a raw pixbuf (RGB or GRAYSCALE)
         1348  +
         1349  + \param inbuf pointer to the input pixbuf.
         1350  + \param inwidth the width (measured in pixels) of the input pixbuf.
         1351  + \param inheight the height (measured in pixels) of the input pixbuf.
         1352  + \param pixtype either RL2_PIXEL_RGB or RL2_PIXEL_GRAYSCALE.
         1353  + \param outbuf pointer to the input pixbuf.
         1354  + \param outwidth the width (measured in pixels) of the output pixbuf.
         1355  + \param outheight the height (measured in pixels) of the output pixbuf.
         1356  +
         1357  + \return 0 (false) on error, any other value on success.
         1358  + */
         1359  +    RL2_DECLARE int rl2_rescale_pixbuf (const unsigned char *inbuf,
         1360  +					unsigned int inwidth,
         1361  +					unsigned int inheight,
         1362  +					unsigned char pixtype,
         1363  +					const unsigned char *outbuf,
         1364  +					unsigned int outwidth,
         1365  +					unsigned int outheight);
         1366  +
  1346   1367   /**
  1347   1368    Creates an RGB Array corresponding to the current Canvass
  1348   1369   
  1349   1370    \param context the pointer to a valid Graphics Context (aka Canvass).
  1350   1371   
  1351   1372    \return the pointer to the RGB Array: NULL on failure.
  1352   1373    

Changes to headers/rasterlite2/sqlite.h.

    47     47   
    48     48   #ifdef LOADABLE_EXTENSION	/* loadable-extension only */
    49     49   #include <sqlite3ext.h>
    50     50   extern const sqlite3_api_routines *sqlite3_api;
    51     51   #else /* ordinary lib */
    52     52   #include <sqlite3.h>
    53     53   #endif
           54  +
           55  +#ifndef SQLITE_DETERMINISTIC
           56  +/* probably SQLite < 3.8.3 - attempting to fix */
           57  +#define SQLITE_DETERMINISTIC	SQLITE_UTF8
           58  +#endif
    54     59   
    55     60   #endif

Changes to headers/rasterlite2_private.h.

  1097   1097       } rl2Point;
  1098   1098       typedef rl2Point *rl2PointPtr;
  1099   1099   
  1100   1100       typedef struct rl2_linestring
  1101   1101       {
  1102   1102   	int points;
  1103   1103   	double *coords;
         1104  +	double minx;
         1105  +	double miny;
         1106  +	double maxx;
         1107  +	double maxy;
  1104   1108   	struct rl2_linestring *next;
  1105   1109       } rl2Linestring;
  1106   1110       typedef rl2Linestring *rl2LinestringPtr;
  1107   1111   
  1108   1112       typedef struct rl2_ring
  1109   1113       {
  1110   1114   	int points;
  1111   1115   	double *coords;
         1116  +	double minx;
         1117  +	double miny;
         1118  +	double maxx;
         1119  +	double maxy;
  1112   1120   	struct rl2_ring *next;
  1113   1121       } rl2Ring;
  1114   1122       typedef rl2Ring *rl2RingPtr;
  1115   1123   
  1116   1124       typedef struct rl2_polygon
  1117   1125       {
  1118   1126   	rl2RingPtr exterior;
................................................................................
  1202   1210   	rl2PrivRasterStatisticsPtr stats;
  1203   1211   	rl2PrivRasterPtr raster;
  1204   1212   	rl2PrivPalettePtr palette;
  1205   1213   	int retcode;
  1206   1214       } rl2AuxDecoder;
  1207   1215       typedef rl2AuxDecoder *rl2AuxDecoderPtr;
  1208   1216   
         1217  +    typedef struct rl2_aux_mask_decoder
         1218  +    {
         1219  +	void *opaque_thread_id;
         1220  +	sqlite3_int64 tile_id;
         1221  +	unsigned char *blob_odd;
         1222  +	int blob_odd_sz;
         1223  +	unsigned char *maskbuf;
         1224  +	unsigned int width;
         1225  +	unsigned int height;
         1226  +	double x_res;
         1227  +	double y_res;
         1228  +	int scale;
         1229  +	double minx;
         1230  +	double maxy;
         1231  +	double tile_minx;
         1232  +	double tile_maxy;
         1233  +	rl2PrivRasterPtr raster;
         1234  +	int retcode;
         1235  +    } rl2AuxMaskDecoder;
         1236  +    typedef rl2AuxMaskDecoder *rl2AuxMaskDecoderPtr;
         1237  +
  1209   1238       typedef struct rl2_aux_shadower
  1210   1239       {
  1211   1240   	void *opaque_thread_id;
  1212   1241   	unsigned int width;
  1213   1242   	unsigned int height;
  1214   1243   	double relief_factor;
  1215   1244   	double scale_factor;
................................................................................
  1253   1282   				    unsigned int *height,
  1254   1283   				    unsigned char sample_type,
  1255   1284   				    unsigned char pixel_type,
  1256   1285   				    unsigned char num_bands,
  1257   1286   				    unsigned char **pixels, int *pixels_sz);
  1258   1287   
  1259   1288       RL2_PRIVATE int
  1260         -	rl2_data_to_png (const unsigned char *pixels, const unsigned char *mask,
  1261         -			 double opacity, rl2PalettePtr plt,
  1262         -			 unsigned int width, unsigned int height,
  1263         -			 unsigned char sample_type, unsigned char pixel_type,
  1264         -			 unsigned char num_bands, unsigned char **compr_data,
  1265         -			 int *compressed_size);
         1289  +	rl2_data_to_png (const unsigned char *pixels,
         1290  +			 const unsigned char *mask, double opacity,
         1291  +			 rl2PalettePtr plt, unsigned int width,
         1292  +			 unsigned int height, unsigned char sample_type,
         1293  +			 unsigned char pixel_type, unsigned char num_bands,
         1294  +			 unsigned char **compr_data, int *compressed_size);
  1266   1295   
  1267   1296       RL2_PRIVATE int
  1268   1297   	rl2_decode_png (const unsigned char *png, int png_sz,
  1269   1298   			unsigned int *width, unsigned int *height,
  1270   1299   			unsigned char *sample_type, unsigned char *pixel_type,
  1271   1300   			unsigned char *num_bands, unsigned char **pixels,
  1272   1301   			int *pixels_sz, unsigned char **mask, int *mask_sz,
................................................................................
  1278   1307   			    unsigned char pixel_type, unsigned char num_bands,
  1279   1308   			    unsigned char **compr_data, int *compressed_size);
  1280   1309   
  1281   1310       RL2_PRIVATE int
  1282   1311   	rl2_decode_charls (const unsigned char *charls, int charls_sz,
  1283   1312   			   unsigned int *width, unsigned int *height,
  1284   1313   			   unsigned char *sample_type,
  1285         -			   unsigned char *pixel_type, unsigned char *num_bands,
  1286         -			   unsigned char **pixels, int *pixels_sz);
         1314  +			   unsigned char *pixel_type,
         1315  +			   unsigned char *num_bands, unsigned char **pixels,
         1316  +			   int *pixels_sz);
  1287   1317   
  1288   1318       RL2_PRIVATE int
  1289   1319   	rl2_data_to_gif (const unsigned char *pixels,
  1290   1320   			 rl2PalettePtr plt, unsigned int width,
  1291   1321   			 unsigned int height, unsigned char sample_type,
  1292   1322   			 unsigned char pixel_type, unsigned char **compr_data,
  1293   1323   			 int *compressed_size);
................................................................................
  1343   1373   					 unsigned int height,
  1344   1374   					 unsigned char sample_type,
  1345   1375   					 unsigned char num_bands,
  1346   1376   					 unsigned char auto_ndvi,
  1347   1377   					 unsigned char red_band_index,
  1348   1378   					 unsigned char nir_band_index,
  1349   1379   					 double x_res, double y_res,
  1350         -					 double minx, double miny, double maxx,
  1351         -					 double maxy, int level, int scale,
  1352         -					 rl2PalettePtr palette,
         1380  +					 double minx, double miny,
         1381  +					 double maxx, double maxy, int level,
         1382  +					 int scale, rl2PalettePtr palette,
  1353   1383   					 rl2PixelPtr no_data,
  1354   1384   					 rl2RasterSymbolizerPtr style,
  1355   1385   					 rl2RasterStatisticsPtr stats);
  1356   1386   
  1357   1387       RL2_PRIVATE int rl2_load_dbms_tiles_section (sqlite3 * handle,
  1358   1388   						 int max_threads,
  1359   1389   						 sqlite3_int64 section_id,
................................................................................
  1364   1394   						 unsigned int height,
  1365   1395   						 unsigned char sample_type,
  1366   1396   						 unsigned char num_bands,
  1367   1397   						 unsigned char auto_ndvi,
  1368   1398   						 unsigned char red_band_index,
  1369   1399   						 unsigned char nir_band_index,
  1370   1400   						 double x_res, double y_res,
  1371         -						 double minx, double maxy,
  1372         -						 int scale,
         1401  +						 double minx, double miny,
         1402  +						 double maxx, double maxy,
         1403  +						 int level, int scale,
  1373   1404   						 rl2PalettePtr palette,
  1374   1405   						 rl2PixelPtr no_data);
  1375   1406   
  1376   1407       RL2_PRIVATE void
  1377   1408   	compute_aggregate_sq_diff (rl2RasterStatisticsPtr aggreg_stats);
  1378   1409   
  1379   1410       RL2_PRIVATE int get_coverage_sample_bands (sqlite3 * sqlite,
................................................................................
  1389   1420   				       unsigned char *num_bands,
  1390   1421   				       unsigned char *compression);
  1391   1422   
  1392   1423       RL2_PRIVATE rl2PixelPtr default_nodata (unsigned char sample,
  1393   1424   					    unsigned char pixel,
  1394   1425   					    unsigned char num_bands);
  1395   1426   
         1427  +    RL2_PRIVATE int
         1428  +	do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg);
         1429  +
  1396   1430       RL2_PRIVATE WmsRetryListPtr alloc_retry_list ();
  1397   1431   
  1398   1432       RL2_PRIVATE void free_retry_list (WmsRetryListPtr lst);
  1399   1433   
  1400   1434       RL2_PRIVATE void add_retry (WmsRetryListPtr lst, double minx, double miny,
  1401   1435   				double maxx, double maxy);
  1402   1436   
................................................................................
  1447   1481   					  int scale, double x_res,
  1448   1482   					  double y_res);
  1449   1483   
  1450   1484       RL2_PRIVATE int rl2_find_best_resolution_level (sqlite3 * handle,
  1451   1485   						    const char *coverage,
  1452   1486   						    int by_section,
  1453   1487   						    sqlite3_int64 section_id,
  1454         -						    double x_res, double y_res,
         1488  +						    double x_res,
         1489  +						    double y_res,
  1455   1490   						    int *level_id, int *scale,
  1456   1491   						    int *real_scale,
  1457   1492   						    double *xx_res,
  1458   1493   						    double *yy_res);
  1459   1494   
  1460   1495       RL2_PRIVATE unsigned char get_palette_format (rl2PrivPalettePtr plt);
  1461   1496   
................................................................................
  1497   1532   						     unsigned char format,
  1498   1533   						     int quality,
  1499   1534   						     unsigned char **image,
  1500   1535   						     int *image_sz);
  1501   1536   
  1502   1537       RL2_PRIVATE int get_payload_from_palette_transparent (unsigned int width,
  1503   1538   							  unsigned int height,
  1504         -							  unsigned char *pixels,
  1505         -							  rl2PalettePtr palette,
  1506         -							  unsigned char format,
  1507         -							  int quality,
  1508         -							  unsigned char **image,
         1539  +							  unsigned char
         1540  +							  *pixels,
         1541  +							  rl2PalettePtr
         1542  +							  palette,
         1543  +							  unsigned char
         1544  +							  format, int quality,
         1545  +							  unsigned char
         1546  +							  **image,
  1509   1547   							  int *image_sz,
  1510         -							  unsigned char bg_red,
         1548  +							  unsigned char
         1549  +							  bg_red,
  1511   1550   							  unsigned char
  1512   1551   							  bg_green,
  1513   1552   							  unsigned char
  1514   1553   							  bg_blue,
  1515   1554   							  double opacity);
  1516   1555   
  1517   1556       RL2_PRIVATE int get_payload_from_grayscale_opaque (unsigned int width,
  1518   1557   						       unsigned int height,
  1519   1558   						       sqlite3 * handle,
  1520         -						       double minx, double miny,
  1521         -						       double maxx, double maxy,
  1522         -						       int srid,
         1559  +						       double minx,
         1560  +						       double miny,
         1561  +						       double maxx,
         1562  +						       double maxy, int srid,
  1523   1563   						       unsigned char *pixels,
  1524   1564   						       unsigned char format,
  1525   1565   						       int quality,
  1526   1566   						       unsigned char **image,
  1527   1567   						       int *image_sz);
  1528   1568   
  1529   1569       RL2_PRIVATE int get_payload_from_grayscale_transparent (unsigned int
  1530   1570   							    width,
  1531   1571   							    unsigned int
  1532   1572   							    height,
  1533   1573   							    unsigned char
  1534   1574   							    *pixels,
  1535   1575   							    unsigned char
  1536         -							    format, int quality,
         1576  +							    format,
         1577  +							    int quality,
  1537   1578   							    unsigned char
  1538   1579   							    **image,
  1539   1580   							    int *image_sz,
  1540   1581   							    unsigned char
  1541   1582   							    bg_gray,
  1542   1583   							    double opacity);
  1543   1584   
  1544   1585       RL2_PRIVATE int get_payload_from_rgb_opaque (unsigned int width,
  1545   1586   						 unsigned int height,
  1546         -						 sqlite3 * handle, double minx,
  1547         -						 double miny, double maxx,
  1548         -						 double maxy, int srid,
         1587  +						 sqlite3 * handle,
         1588  +						 double minx, double miny,
         1589  +						 double maxx, double maxy,
         1590  +						 int srid,
  1549   1591   						 unsigned char *pixels,
  1550   1592   						 unsigned char format,
  1551   1593   						 int quality,
  1552   1594   						 unsigned char **image,
  1553   1595   						 int *image_sz);
  1554   1596   
  1555   1597       RL2_PRIVATE int get_payload_from_rgb_transparent (unsigned int width,
................................................................................
  1574   1616       RL2_PRIVATE int get_rgba_from_monochrome_opaque (unsigned int width,
  1575   1617   						     unsigned int height,
  1576   1618   						     unsigned char *pixels,
  1577   1619   						     unsigned char *rgba);
  1578   1620   
  1579   1621       RL2_PRIVATE int get_rgba_from_monochrome_transparent (unsigned int width,
  1580   1622   							  unsigned int height,
  1581         -							  unsigned char *pixels,
         1623  +							  unsigned char
         1624  +							  *pixels,
  1582   1625   							  unsigned char *rgba);
  1583   1626   
  1584   1627       RL2_PRIVATE int get_rgba_from_palette_mask (unsigned int base_width,
  1585   1628   						unsigned int base_height,
  1586   1629   						unsigned char *pixels,
  1587   1630   						unsigned char *mask,
  1588   1631   						rl2PalettePtr palette,
................................................................................
  1614   1657       RL2_PRIVATE int get_rgba_from_grayscale_opaque (unsigned int width,
  1615   1658   						    unsigned int height,
  1616   1659   						    unsigned char *pixels,
  1617   1660   						    unsigned char *rgba);
  1618   1661   
  1619   1662       RL2_PRIVATE int get_rgba_from_grayscale_transparent (unsigned int width,
  1620   1663   							 unsigned int height,
  1621         -							 unsigned char *pixels,
         1664  +							 unsigned char
         1665  +							 *pixels,
  1622   1666   							 unsigned char *rgba,
  1623   1667   							 unsigned char bg_gray);
  1624   1668   
  1625   1669       RL2_PRIVATE int get_rgba_from_rgb_mask (unsigned int width,
  1626   1670   					    unsigned int height,
  1627   1671   					    unsigned char *pixels,
  1628   1672   					    unsigned char *mask,
................................................................................
  1658   1702   						  unsigned char *mask,
  1659   1703   						  rl2PrivPixelPtr no_made,
  1660   1704   						  unsigned char *rgba);
  1661   1705   
  1662   1706       RL2_PRIVATE int get_payload_from_gray_rgba_opaque (unsigned int width,
  1663   1707   						       unsigned int height,
  1664   1708   						       sqlite3 * handle,
  1665         -						       double minx, double miny,
  1666         -						       double maxx, double maxy,
  1667         -						       int srid,
         1709  +						       double minx,
         1710  +						       double miny,
         1711  +						       double maxx,
         1712  +						       double maxy, int srid,
  1668   1713   						       unsigned char *rgb,
  1669   1714   						       unsigned char format,
  1670   1715   						       int quality,
  1671   1716   						       unsigned char **image,
  1672   1717   						       int *image_sz);
  1673   1718   
  1674   1719       RL2_PRIVATE int get_payload_from_gray_rgba_transparent (unsigned int
  1675   1720   							    width,
  1676   1721   							    unsigned int
  1677   1722   							    height,
  1678         -							    unsigned char *rgb,
         1723  +							    unsigned char
         1724  +							    *rgb,
  1679   1725   							    unsigned char
  1680   1726   							    *alpha,
  1681   1727   							    unsigned char
  1682         -							    format, int quality,
         1728  +							    format,
         1729  +							    int quality,
  1683   1730   							    unsigned char
  1684   1731   							    **image,
  1685   1732   							    int *image_sz,
  1686   1733   							    double opacity);
  1687   1734   
  1688   1735       RL2_PRIVATE int get_payload_from_rgb_rgba_opaque (unsigned int width,
  1689   1736   						      unsigned int height,
  1690   1737   						      sqlite3 * handle,
  1691         -						      double minx, double miny,
  1692         -						      double maxx, double maxy,
  1693         -						      int srid,
         1738  +						      double minx,
         1739  +						      double miny,
         1740  +						      double maxx,
         1741  +						      double maxy, int srid,
  1694   1742   						      unsigned char *rgb,
  1695   1743   						      unsigned char format,
  1696   1744   						      int quality,
  1697   1745   						      unsigned char **image,
  1698   1746   						      int *image_sz);
  1699   1747   
  1700   1748       RL2_PRIVATE int get_payload_from_rgb_rgba_transparent (unsigned int width,
  1701   1749   							   unsigned int
  1702   1750   							   height,
  1703   1751   							   unsigned char *rgb,
  1704         -							   unsigned char *alpha,
  1705         -							   unsigned char format,
         1752  +							   unsigned char
         1753  +							   *alpha,
         1754  +							   unsigned char
         1755  +							   format,
  1706   1756   							   int quality,
  1707   1757   							   unsigned char
  1708   1758   							   **image,
  1709   1759   							   int *image_sz,
  1710   1760   							   double opacity,
  1711   1761   							   int
  1712   1762   							   half_transparent);
  1713   1763   
  1714   1764       RL2_PRIVATE int build_rgb_alpha (unsigned int width,
  1715   1765   				     unsigned int height, unsigned char *rgba,
  1716         -				     unsigned char **rgb, unsigned char **alpha,
         1766  +				     unsigned char **rgb,
         1767  +				     unsigned char **alpha,
  1717   1768   				     unsigned char bg_red,
  1718   1769   				     unsigned char bg_green,
  1719   1770   				     unsigned char bg_blue);
  1720   1771   
  1721   1772       RL2_PRIVATE int get_rgba_from_multiband8 (unsigned int width,
  1722   1773   					      unsigned int height,
  1723   1774   					      unsigned char red_band,
................................................................................
  1742   1793       RL2_PRIVATE int parse_worldfile (FILE * in, double *px, double *py,
  1743   1794   				     double *pres_x, double *pres_y);
  1744   1795   
  1745   1796       RL2_PRIVATE rl2CoverageStylePtr coverage_style_from_xml (char *name,
  1746   1797   							     unsigned char
  1747   1798   							     *xml);
  1748   1799   
  1749         -    RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char *name,
         1800  +    RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char
         1801  +								    *name,
  1750   1802   								    unsigned
  1751   1803   								    char *xml);
  1752   1804   
  1753   1805       RL2_PRIVATE rl2GroupStylePtr group_style_from_sld_xml (char *name,
  1754   1806   							   unsigned char *xml);
  1755   1807   
  1756   1808       RL2_PRIVATE rl2PrivCoverageStylePtr
................................................................................
  1831   1883   
  1832   1884       RL2_PRIVATE void rl2_destroy_point_symbolizer (rl2PrivPointSymbolizerPtr
  1833   1885   						   symbolizer);
  1834   1886   
  1835   1887       RL2_PRIVATE void rl2_destroy_line_symbolizer (rl2PrivLineSymbolizerPtr
  1836   1888   						  symbolizer);
  1837   1889   
  1838         -    RL2_PRIVATE void rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr
  1839         -						     symbolizer);
         1890  +    RL2_PRIVATE void
         1891  +	rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr symbolizer);
  1840   1892   
  1841   1893       RL2_PRIVATE void rl2_destroy_text_symbolizer (rl2PrivTextSymbolizerPtr
  1842   1894   						  symbolizer);
  1843   1895   
  1844   1896       RL2_PRIVATE rl2PrivRuleSingleArgPtr
  1845   1897   	rl2_create_default_rule_single_arg (void);
  1846   1898   
................................................................................
  1876   1928   					 unsigned char nir_band_index,
  1877   1929   					 double x_res, double y_res,
  1878   1930   					 double minx, double maxy,
  1879   1931   					 double tile_minx, double tile_maxy,
  1880   1932   					 rl2PixelPtr no_data,
  1881   1933   					 rl2RasterSymbolizerPtr style,
  1882   1934   					 rl2RasterStatisticsPtr stats);
         1935  +
         1936  +    RL2_PRIVATE int rl2_copy_raw_mask (rl2RasterPtr raster,
         1937  +				       unsigned char *maskbuf,
         1938  +				       unsigned int width,
         1939  +				       unsigned int height,
         1940  +				       double x_res, double y_res,
         1941  +				       double minx, double maxy,
         1942  +				       double tile_minx, double tile_maxy);
  1883   1943   
  1884   1944       RL2_PRIVATE unsigned char *rl2_copy_endian_raw_pixels (const unsigned char
  1885   1945   							   *pixels,
  1886   1946   							   int pixels_sz,
  1887   1947   							   unsigned int width,
  1888         -							   unsigned int height,
         1948  +							   unsigned int
         1949  +							   height,
  1889   1950   							   unsigned char
  1890   1951   							   sample_type,
  1891   1952   							   unsigned char
  1892   1953   							   num_bands,
  1893   1954   							   int big_endian);
  1894   1955   
  1895   1956       RL2_PRIVATE int rl2_build_shaded_relief_mask (sqlite3 * handle,
  1896   1957   						  int max_threads,
  1897   1958   						  rl2CoveragePtr cvg,
         1959  +						  int by_section,
         1960  +						  sqlite3_int64 section_id,
  1898   1961   						  double relief_factor,
  1899   1962   						  double scale_factor,
  1900   1963   						  unsigned int width,
  1901   1964   						  unsigned int height,
  1902   1965   						  double minx, double miny,
  1903   1966   						  double maxx, double maxy,
  1904   1967   						  double x_res, double y_res,
................................................................................
  1910   1973   					const char *title,
  1911   1974   					const char *abstract);
  1912   1975   
  1913   1976       RL2_PRIVATE int rl2_test_layer_group (sqlite3 * handle,
  1914   1977   					  const char *group_name);
  1915   1978   
  1916   1979       RL2_PRIVATE int rl2_rgba_raster_data (sqlite3 * handle,
  1917         -					  const char *coverage_name, void *ctx,
  1918         -					  int level, double minx, double miny,
  1919         -					  double maxx, double maxy,
  1920         -					  rl2PalettePtr palette,
         1980  +					  const char *coverage_name,
         1981  +					  void *ctx, int level, double minx,
         1982  +					  double miny, double maxx,
         1983  +					  double maxy, rl2PalettePtr palette,
  1921   1984   					  rl2PixelPtr no_data);
  1922   1985   
  1923   1986       RL2_PRIVATE int rl2_aux_render_image (struct aux_renderer *aux,
  1924   1987   					  unsigned char **ximage,
  1925   1988   					  int *ximage_size);
         1989  +
         1990  +    RL2_PRIVATE int rl2_aux_default_image (unsigned int width,
         1991  +					   unsigned int height,
         1992  +					   unsigned char red,
         1993  +					   unsigned char green,
         1994  +					   unsigned char blue, int format_id,
         1995  +					   int transparent, int quality,
         1996  +					   unsigned char **ximage,
         1997  +					   int *ximage_size);
  1926   1998   
  1927   1999       RL2_PRIVATE void rl2_aux_group_renderer (struct aux_group_renderer *auxgrp);
  1928   2000   
  1929   2001       RL2_PRIVATE double rl2_get_shaded_relief_scale_factor (sqlite3 * handle,
  1930   2002   							   const char
  1931   2003   							   *coverage);
  1932   2004   
................................................................................
  1950   2022   						    rl2CoveragePtr cvg,
  1951   2023   						    int by_section,
  1952   2024   						    sqlite3_int64 section_id,
  1953   2025   						    unsigned int width,
  1954   2026   						    unsigned int height,
  1955   2027   						    double minx, double miny,
  1956   2028   						    double maxx, double maxy,
  1957         -						    double x_res, double y_res,
         2029  +						    double x_res,
         2030  +						    double y_res,
  1958   2031   						    unsigned char **buffer,
  1959   2032   						    int *buf_size,
  1960   2033   						    rl2PalettePtr * palette,
  1961   2034   						    unsigned char out_pixel,
  1962   2035   						    rl2PixelPtr bgcolor,
  1963   2036   						    rl2RasterSymbolizerPtr
  1964   2037   						    style,
  1965   2038   						    rl2RasterStatisticsPtr
  1966   2039   						    stats);
         2040  +
         2041  +    RL2_PRIVATE int rl2_get_raw_raster_mask_common (sqlite3 * handle,
         2042  +						    int max_threads,
         2043  +						    rl2CoveragePtr cvg,
         2044  +						    int by_section,
         2045  +						    sqlite3_int64 section_id,
         2046  +						    unsigned int width,
         2047  +						    unsigned int height,
         2048  +						    double minx, double miny,
         2049  +						    double maxx, double maxy,
         2050  +						    double x_res, double y_res,
         2051  +						    unsigned char **mask,
         2052  +						    int *mask_size);
         2053  +
         2054  +    RL2_PRIVATE rl2RasterPtr
         2055  +	rl2_raster_decode_mask (int scale, const unsigned char *blob_odd,
         2056  +				int blob_odd_sz, int *status);
  1967   2057   
  1968   2058       RL2_PRIVATE char *rl2_double_quoted_sql (const char *value);
  1969   2059   
  1970   2060       RL2_PRIVATE int rl2_parse_point (sqlite3 * sqlite,
  1971   2061   				     const unsigned char *blob, int blob_sz,
  1972   2062   				     double *x, double *y);
  1973   2063   
  1974   2064       RL2_PRIVATE int rl2_parse_point_generic (sqlite3 * sqlite,
  1975   2065   					     const unsigned char *blob,
  1976   2066   					     int blob_sz, double *x, double *y);
  1977   2067   
  1978   2068       RL2_PRIVATE int rl2_parse_bbox_srid (sqlite3 * sqlite,
  1979         -					 const unsigned char *blob, int blob_sz,
  1980         -					 int *srid, double *minx, double *miny,
  1981         -					 double *maxx, double *maxy);
         2069  +					 const unsigned char *blob,
         2070  +					 int blob_sz, int *srid, double *minx,
         2071  +					 double *miny, double *maxx,
         2072  +					 double *maxy);
  1982   2073   
  1983         -    RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite, const unsigned char *blob,
  1984         -				    int blob_sz, double *minx, double *miny,
  1985         -				    double *maxx, double *maxy);
         2074  +    RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite,
         2075  +				    const unsigned char *blob, int blob_sz,
         2076  +				    double *minx, double *miny, double *maxx,
         2077  +				    double *maxy);
  1986   2078   
  1987   2079       RL2_PRIVATE int rl2_build_bbox (sqlite3 * sqlite, int srid, double minx,
  1988   2080   				    double miny, double maxx, double maxy,
  1989   2081   				    unsigned char **blob, int *blob_sz);
  1990   2082   
  1991   2083       RL2_PRIVATE int rl2_delta_encode (unsigned char *buffer, int size,
  1992   2084   				      int distance);
  1993   2085   
  1994   2086       RL2_PRIVATE int rl2_delta_decode (unsigned char *buffer, int size,
  1995   2087   				      int distance);
  1996   2088   
  1997         -    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char *name,
         2089  +    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char
         2090  +							       *name,
  1998   2091   							       sqlite3_int64
  1999   2092   							       value);
  2000   2093   
  2001   2094       RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_double (const char
  2002   2095   								  *name,
  2003   2096   								  double value);
  2004   2097   
................................................................................
  2012   2105   
  2013   2106       RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_null (const char
  2014   2107   								*name);
  2015   2108   
  2016   2109       RL2_PRIVATE void rl2_destroy_variant_value (rl2PrivVariantValuePtr value);
  2017   2110   
  2018   2111       RL2_PRIVATE void rl2_draw_vector_feature (void *ctx, sqlite3 * handle,
  2019         -					      rl2VectorSymbolizerPtr symbolizer,
  2020         -					      int height, double minx,
  2021         -					      double miny, double x_res,
  2022         -					      double y_res,
         2112  +					      const void *priv_data,
         2113  +					      rl2VectorSymbolizerPtr
         2114  +					      symbolizer, int height,
         2115  +					      double minx, double miny,
         2116  +					      double maxx, double maxy,
         2117  +					      double x_res, double y_res,
  2023   2118   					      rl2GeometryPtr geom,
  2024   2119   					      rl2VariantArrayPtr variant);
  2025   2120   
  2026   2121       RL2_PRIVATE rl2GeometryPtr
  2027   2122   	rl2_geometry_from_blob (const unsigned char *blob, int blob_sz);
  2028   2123   
  2029   2124       RL2_PRIVATE rl2GeometryPtr
................................................................................
  2033   2128   
  2034   2129       RL2_PRIVATE int rl2_serialize_linestring (rl2LinestringPtr line,
  2035   2130   					      unsigned char **blob,
  2036   2131   					      int *blob_sz);
  2037   2132   
  2038   2133       RL2_PRIVATE int rl2_serialize_ring (rl2RingPtr ring, unsigned char **blob,
  2039   2134   					int *blob_sz);
         2135  +
         2136  +    RL2_PRIVATE int rl2_serialize_ring_as_linestring (rl2RingPtr ring,
         2137  +						      unsigned char **blob,
         2138  +						      int *blob_sz);
  2040   2139   
  2041   2140       RL2_PRIVATE double rl2_compute_curve_length (rl2GeometryPtr geom);
  2042   2141   
  2043   2142       RL2_PRIVATE rl2GeometryPtr
  2044         -	rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom, double from,
  2045         -			     double to);
         2143  +	rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom,
         2144  +			     double from, double to);
  2046   2145   
  2047   2146       RL2_PRIVATE rl2GeometryPtr rl2_clone_curve (rl2GeometryPtr in);
  2048   2147   
  2049   2148       RL2_PRIVATE rl2GeometryPtr rl2_clone_linestring (rl2LinestringPtr in);
  2050   2149   
  2051   2150       RL2_PRIVATE rl2GeometryPtr
  2052   2151   	rl2_build_circle (double x, double y, double radius);
................................................................................
  2053   2152   
  2054   2153       RL2_PRIVATE int rl2_load_font_into_dbms (sqlite3 * handle,
  2055   2154   					     unsigned char *blob, int blob_sz);
  2056   2155   
  2057   2156       RL2_PRIVATE int rl2_get_font_from_dbms (sqlite3 * handle,
  2058   2157   					    const char *facename,
  2059   2158   					    unsigned char **font, int *font_sz);
         2159  +
         2160  +    RL2_PRIVATE rl2LinestringPtr rl2_linestring_to_image (rl2LinestringPtr line,
         2161  +							  int height,
         2162  +							  double minx,
         2163  +							  double miny,
         2164  +							  double x_res,
         2165  +							  double y_res);
         2166  +
         2167  +    RL2_PRIVATE rl2RingPtr rl2_ring_to_image (rl2RingPtr ring, int height,
         2168  +					      double minx, double miny,
         2169  +					      double x_res, double y_res);
         2170  +
         2171  +    RL2_PRIVATE void rl2DestroyLinestring (rl2LinestringPtr ptr);
         2172  +
         2173  +    RL2_PRIVATE void rl2DestroyRing (rl2RingPtr ptr);
  2060   2174   
  2061   2175   #ifdef __cplusplus
  2062   2176   }
  2063   2177   #endif
  2064   2178   
  2065   2179   #endif				/* _RASTERLITE2_PRIVATE_H */

Changes to headers/rl2svg_private.h.

   502    502   							in);
   503    503   
   504    504       RL2_PRIVATE rl2PrivSvgLinePtr svg_alloc_line (double x1, double y1,
   505    505   						  double x2, double y2);
   506    506   
   507    507       RL2_PRIVATE rl2PrivSvgLinePtr svg_clone_line (rl2PrivSvgLinePtr in);
   508    508   
   509         -    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points, double *x,
   510         -							  double *y);
          509  +    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points,
          510  +							  double *x, double *y);
   511    511   
   512         -    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_clone_polyline (rl2PrivSvgPolylinePtr
   513         -							  in);
          512  +    RL2_PRIVATE rl2PrivSvgPolylinePtr
          513  +	svg_clone_polyline (rl2PrivSvgPolylinePtr in);
   514    514   
   515    515       RL2_PRIVATE rl2PrivSvgPolygonPtr svg_alloc_polygon (int points, double *x,
   516    516   							double *y);
   517    517   
   518    518       RL2_PRIVATE rl2PrivSvgPolygonPtr svg_clone_polygon (rl2PrivSvgPolygonPtr
   519    519   							in);
   520    520   
   521    521       RL2_PRIVATE rl2PrivSvgPathMovePtr svg_alloc_path_move (double x, double y);
   522    522   
   523         -    RL2_PRIVATE rl2PrivSvgPathMovePtr svg_clone_path_move (rl2PrivSvgPathMovePtr
   524         -							   in);
          523  +    RL2_PRIVATE rl2PrivSvgPathMovePtr
          524  +	svg_clone_path_move (rl2PrivSvgPathMovePtr in);
   525    525   
   526    526       RL2_PRIVATE rl2PrivSvgPathBezierPtr svg_alloc_path_bezier (double x1,
   527    527   							       double y1,
   528    528   							       double x2,
   529    529   							       double y2,
   530    530   							       double x,
   531    531   							       double y);
................................................................................
   606    606   
   607    607       RL2_PRIVATE void svg_set_group_parent (rl2PrivSvgItemPtr item,
   608    608   					   rl2PrivSvgGroupPtr grp);
   609    609   
   610    610       RL2_PRIVATE rl2PrivSvgGradientStopPtr svg_alloc_gradient_stop (double
   611    611   								   offset,
   612    612   								   double red,
   613         -								   double green,
   614         -								   double blue,
          613  +								   double
          614  +								   green,
          615  +								   double
          616  +								   blue,
   615    617   								   double
   616    618   								   opacity);
   617    619   
   618    620       RL2_PRIVATE rl2PrivSvgGradientStopPtr
   619    621   	svg_clone_gradient_stop (rl2PrivSvgGradientStopPtr in);
   620    622   
   621    623       RL2_PRIVATE rl2PrivSvgGradientPtr svg_alloc_gradient (void);
   622    624   
   623         -    RL2_PRIVATE rl2PrivSvgGradientPtr svg_clone_gradient (rl2PrivSvgGradientPtr
   624         -							  in,
   625         -							  rl2PrivSvgGradientPtr
   626         -							  old);
          625  +    RL2_PRIVATE rl2PrivSvgGradientPtr
          626  +	svg_clone_gradient (rl2PrivSvgGradientPtr in,
          627  +			    rl2PrivSvgGradientPtr old);
   627    628   
   628    629       RL2_PRIVATE rl2PrivSvgDocumentPtr svg_alloc_document (void);
   629    630   
   630    631       RL2_PRIVATE void svg_close_group (rl2PrivSvgDocumentPtr svg_doc);
   631    632   
   632    633       RL2_PRIVATE void svg_insert_group (rl2PrivSvgDocumentPtr svg_doc);
   633    634   
   634    635       RL2_PRIVATE void svg_close_clip (rl2PrivSvgDocumentPtr svg_doc);
   635    636   
   636    637       RL2_PRIVATE void svg_insert_clip (rl2PrivSvgDocumentPtr svg_doc);
   637    638   
   638         -    RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr svg_doc,
          639  +    RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr
          640  +						 svg_doc,
   639    641   						 const char *xlink_href,
   640    642   						 double x, double y,
   641    643   						 double width, double height);
   642    644   
   643         -    RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc, int type,
   644         -				       void *data);
          645  +    RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc,
          646  +				       int type, void *data);
   645    647   
   646    648       RL2_PRIVATE void svg_insert_gradient_stop (rl2PrivSvgGradientPtr gradient,
   647    649   					       double offset, double red,
   648    650   					       double green, double blue,
   649    651   					       double opacity);
   650    652   
   651    653       RL2_PRIVATE rl2PrivSvgGradientPtr
   652    654   	svg_insert_linear_gradient (rl2PrivSvgDocumentPtr svg_doc,
   653    655   				    const char *id, const char *xlink_href,
   654         -				    double x1, double y1, double x2, double y2,
   655         -				    int units);
          656  +				    double x1, double y1, double x2,
          657  +				    double y2, int units);
   656    658   
   657    659       RL2_PRIVATE rl2PrivSvgGradientPtr
   658    660   	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
   659    661   				    const char *id, const char *xlink_href,
   660         -				    double cx, double cy, double fx, double fy,
   661         -				    double r, int units);
          662  +				    double cx, double cy, double fx,
          663  +				    double fy, double r, int units);
   662    664   
   663    665       RL2_PRIVATE rl2PrivSvgGradientPtr
   664    666   	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
   665    667   				    const char *id, const char *xlink_href,
   666         -				    double cx, double cy, double fx, double fy,
   667         -				    double r, int units);
          668  +				    double cx, double cy, double fx,
          669  +				    double fy, double r, int units);
   668    670   
   669    671       RL2_PRIVATE void svg_init_style (rl2PrivSvgStylePtr style);
   670    672   
   671    673       RL2_PRIVATE void svg_style_cleanup (rl2PrivSvgStylePtr style);
   672    674   
   673    675   
   674    676   #ifdef __cplusplus
   675    677   }
   676    678   #endif
   677    679   
   678    680   #endif				/* _RL2SVG_PRIVATE_H */

Deleted rasterlite2-4.2.0.mk.

     1         -include $(CLEAR_VARS)
     2         -# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
     3         -LOCAL_MODULE    := rasterlite2
     4         -
     5         -# SQLite flags copied from ASOP [may not be needed for rasterlite2]
     6         -common_sqlite_flags := \
     7         - -DHAVE_USLEEP=1 \
     8         - -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
     9         - -DSQLITE_THREADSAFE=1 \
    10         - -DNDEBUG=1 \
    11         - -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
    12         - -DSQLITE_DEFAULT_AUTOVACUUM=1 \
    13         - -DSQLITE_TEMP_STORE=3 \
    14         - -DSQLITE_ENABLE_FTS3 \
    15         - -DSQLITE_ENABLE_FTS3_BACKWARDS \
    16         - -DSQLITE_ENABLE_RTREE=1 \
    17         - -DSQLITE_DEFAULT_FILE_FORMAT=4
    18         -
    19         -# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
    20         -spatialite_flags := \
    21         - -DOMIT_FREEXL \
    22         - -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
    23         - -Dfdatasync=fsync \
    24         - -DSQLITE_ENABLE_RTREE=1 \
    25         - -DSQLITE_OMIT_BUILTIN_TEST=1
    26         -
    27         -# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
    28         -rasterlite2_flags := \
    29         - -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
    30         - -O
    31         -
    32         -LOCAL_CFLAGS    := \
    33         - $(common_sqlite_flags) \
    34         - $(spatialite_flags) \
    35         - $(rasterlite2_flags)
    36         -
    37         -LOCAL_C_INCLUDES := \
    38         - $(SQLITE_PATH) \
    39         - $(GEOTIFF_PATH)/libxtiff \
    40         - $(GEOTIFF_PATH) \
    41         - $(TIFF_PATH) \
    42         - $(JPEG_PATH) \
    43         - $(GIF_PATH) \
    44         - $(PNG_PATH) \
    45         - $(WEBP_PATH)/src/webp \
    46         - $(WEBP_PATH)/src/dec \
    47         - $(WEBP_PATH)/src/dsp \
    48         - $(WEBP_PATH)/src/enc \
    49         - $(WEBP_PATH)/src/utils \
    50         - $(WEBP_PATH)/src \
    51         - $(WEBP_PATH) \
    52         - $(CAIRO_PATH) \
    53         - $(ICONV_PATH)/include \
    54         - $(ICONV_PATH)/libcharset/include \
    55         - $(XML2_PATH)/include \
    56         - $(CURL_PATH) \
    57         - $(CURL_PATH)/include \
    58         - $(CURL_PATH)/lib \
    59         - $(RASTERLITE2_PATH) \
    60         - $(RASTERLITE2_PATH)/headers \
    61         - $(SPATIALITE_PATH)/src/headers \
    62         - $(LZMA_PATH)/src/liblzma/api
    63         -LOCAL_SRC_FILES := \
    64         - $(RASTERLITE2_PATH)/src/rasterlite2.c \
    65         - $(RASTERLITE2_PATH)/src/rl2ascii.c \
    66         - $(RASTERLITE2_PATH)/src/rl2codec.c \
    67         - $(RASTERLITE2_PATH)/src/rl2dbms.c \
    68         - $(RASTERLITE2_PATH)/src/rl2gif.c \
    69         - $(RASTERLITE2_PATH)/src/rl2import.c \
    70         - $(RASTERLITE2_PATH)/src/rl2jpeg.c \
    71         - $(RASTERLITE2_PATH)/src/rl2paint.c \
    72         - $(RASTERLITE2_PATH)/src/rl2png.c \
    73         - $(RASTERLITE2_PATH)/src/rl2rastersym.c \
    74         - $(RASTERLITE2_PATH)/src/rl2raw.c \
    75         - $(RASTERLITE2_PATH)/src/rl2sql.c \
    76         - $(RASTERLITE2_PATH)/src/rl2sqlaux.c \
    77         - $(RASTERLITE2_PATH)/src/rl2svg.c \
    78         - $(RASTERLITE2_PATH)/src/rl2svgaux.c \
    79         - $(RASTERLITE2_PATH)/src/rl2svgxml.c \
    80         - $(RASTERLITE2_PATH)/src/rl2symbolizer.c \
    81         - $(RASTERLITE2_PATH)/src/rl2tiff.c \
    82         - $(RASTERLITE2_PATH)/src/rl2version.c \
    83         - $(RASTERLITE2_PATH)/src/rl2webp.c \
    84         - $(RASTERLITE2_PATH)/src/rl2wms.c
    85         -LOCAL_STATIC_LIBRARIES := libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg
    86         -include $(BUILD_STATIC_LIBRARY)

Added rasterlite2-4.3.0.mk.

            1  +include $(CLEAR_VARS)
            2  +# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
            3  +LOCAL_MODULE    := rasterlite2
            4  +
            5  +# SQLite flags copied from ASOP [may not be needed for rasterlite2]
            6  +common_sqlite_flags := \
            7  + -DHAVE_USLEEP=1 \
            8  + -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
            9  + -DSQLITE_THREADSAFE=1 \
           10  + -DNDEBUG=1 \
           11  + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
           12  + -DSQLITE_DEFAULT_AUTOVACUUM=1 \
           13  + -DSQLITE_TEMP_STORE=3 \
           14  + -DSQLITE_ENABLE_FTS3 \
           15  + -DSQLITE_ENABLE_FTS3_BACKWARDS \
           16  + -DSQLITE_ENABLE_RTREE=1 \
           17  + -DSQLITE_DEFAULT_FILE_FORMAT=4
           18  +
           19  +# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
           20  +spatialite_flags := \
           21  + -DOMIT_FREEXL \
           22  + -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
           23  + -Dfdatasync=fsync \
           24  + -DSQLITE_ENABLE_RTREE=1 \
           25  + -DENABLE_GCP=1 \
           26  + -DENABLE_GEOPACKAGE=1 \
           27  + -DENABLE_LIBXML2=1 \
           28  + -DSQLITE_OMIT_BUILTIN_TEST=1
           29  +
           30  +# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
           31  +# comment out VERSION in config.h - manually set to avoid conflict with other packages
           32  +rasterlite2_flags := \
           33  + -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
           34  + -DVERSION=\"0.9\" \
           35  + -O
           36  +
           37  +LOCAL_CFLAGS    := \
           38  + $(common_sqlite_flags) \
           39  + $(spatialite_flags) \
           40  + $(rasterlite2_flags)
           41  +
           42  +# 2014-10-03 - adapted based on ls -1 result
           43  +LOCAL_C_INCLUDES := \
           44  + $(SQLITE_PATH) \
           45  + $(GEOTIFF_PATH)/libxtiff \
           46  + $(GEOTIFF_PATH) \
           47  + $(TIFF_PATH) \
           48  + $(JPEG_PATH) \
           49  + $(GIF_PATH) \
           50  + $(PNG_PATH) \
           51  + $(WEBP_PATH)/src/webp \
           52  + $(WEBP_PATH)/src/dec \
           53  + $(WEBP_PATH)/src/dsp \
           54  + $(WEBP_PATH)/src/enc \
           55  + $(WEBP_PATH)/src/utils \
           56  + $(WEBP_PATH)/src \
           57  + $(WEBP_PATH) \
           58  + $(CAIRO_PATH) \
           59  + $(FONTCONFIG_PATH) \
           60  + $(ICONV_PATH)/include \
           61  + $(FREETYPE_PATH)/include \
           62  + $(ICONV_PATH)/libcharset/include \
           63  + $(XML2_PATH)/include \
           64  + $(CURL_PATH) \
           65  + $(CURL_PATH)/include \
           66  + $(CURL_PATH)/lib \
           67  + $(RASTERLITE2_PATH) \
           68  + $(RASTERLITE2_PATH)/headers \
           69  + $(SPATIALITE_PATH)/src/headers \
           70  + $(LZMA_PATH)/src/liblzma/api \
           71  + $(OPENJPEG_PATH)/src/lib/openjp2 \
           72  + $(CHARLS_PATH)
           73  +
           74  +LOCAL_SRC_FILES := \
           75  + $(RASTERLITE2_PATH)/src/md5.c \
           76  + $(RASTERLITE2_PATH)/src/rasterlite2.c \
           77  + $(RASTERLITE2_PATH)/src/rl2ascii.c \
           78  + $(RASTERLITE2_PATH)/src/rl2auxfont.c \
           79  + $(RASTERLITE2_PATH)/src/rl2auxgeom.c \
           80  + $(RASTERLITE2_PATH)/src/rl2auxrender.c \
           81  + $(RASTERLITE2_PATH)/src/rl2charls.c \
           82  + $(RASTERLITE2_PATH)/src/rl2codec.c \
           83  + $(RASTERLITE2_PATH)/src/rl2dbms.c \
           84  + $(RASTERLITE2_PATH)/src/rl2gif.c \
           85  + $(RASTERLITE2_PATH)/src/rl2import.c \
           86  + $(RASTERLITE2_PATH)/src/rl2jpeg.c \
           87  + $(RASTERLITE2_PATH)/src/rl2md5.c \
           88  + $(RASTERLITE2_PATH)/src/rl2openjpeg.c \
           89  + $(RASTERLITE2_PATH)/src/rl2paint.c \
           90  + $(RASTERLITE2_PATH)/src/rl2png.c \
           91  + $(RASTERLITE2_PATH)/src/rl2pyramid.c \
           92  + $(RASTERLITE2_PATH)/src/rl2rastersym.c \
           93  + $(RASTERLITE2_PATH)/src/rl2raw.c \
           94  + $(RASTERLITE2_PATH)/src/rl2sql.c \
           95  + $(RASTERLITE2_PATH)/src/rl2sqlaux.c \
           96  + $(RASTERLITE2_PATH)/src/rl2svg.c \
           97  + $(RASTERLITE2_PATH)/src/rl2svgaux.c \
           98  + $(RASTERLITE2_PATH)/src/rl2svgxml.c \
           99  + $(RASTERLITE2_PATH)/src/rl2symbaux.c \
          100  + $(RASTERLITE2_PATH)/src/rl2symbolizer.c \
          101  + $(RASTERLITE2_PATH)/src/rl2tiff.c \
          102  + $(RASTERLITE2_PATH)/src/rl2version.c \
          103  + $(RASTERLITE2_PATH)/src/rl2webp.c \
          104  + $(RASTERLITE2_PATH)/src/rl2wms.c
          105  +LOCAL_STATIC_LIBRARIES := libcharls libopenjpeg libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg
          106  +include $(BUILD_STATIC_LIBRARY)

Changes to src/Makefile.am.

    21     21   	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@	@LIBCURL_LIBS@ \
    22     22   	@LIBXML2_LIBS@ @LIBFREETYPE2_LIBS@
    23     23   
    24     24   if MINGW
    25     25   librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
    26     26   librasterlite2_la_LIBADD += -lm
    27     27   else
    28         -librasterlite2_la_LDFLAGS = -version-info 0:0:0
           28  +librasterlite2_la_LDFLAGS = -version-info 1:0:0
    29     29   librasterlite2_la_LIBADD += -lpthread -lm
    30     30   endif
    31     31   
    32     32   mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
    33     33   	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
    34     34   	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
    35     35   	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
................................................................................
    46     46   mod_rasterlite2_la_CPPFLAGS += -DLOADABLE_EXTENSION
    47     47   mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static
    48     48   
    49     49   if MINGW
    50     50   mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
    51     51   mod_rasterlite2_la_LIBADD += -lm
    52     52   else
    53         -mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0
           53  +mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0
    54     54   mod_rasterlite2_la_LIBADD += -lpthread -lm
    55     55   endif
    56     56   
    57     57   MOSTLYCLEANFILES = *.gcna *.gcno *.gcda

Changes to src/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   
    17     17   
    18     18   VPATH = @srcdir@
    19         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           19  +am__is_gnu_make = { \
           20  +  if test -z '$(MAKELEVEL)'; then \
           21  +    false; \
           22  +  elif test -n '$(MAKE_HOST)'; then \
           23  +    true; \
           24  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           25  +    true; \
           26  +  else \
           27  +    false; \
           28  +  fi; \
           29  +}
    20     30   am__make_running_with_option = \
    21     31     case $${target_option-} in \
    22     32         ?) ;; \
    23     33         *) echo "am__make_running_with_option: internal error: invalid" \
    24     34                 "target option '$${target_option-}' specified" >&2; \
    25     35            exit 1;; \
    26     36     esac; \
................................................................................
    80     90   build_triplet = @build@
    81     91   host_triplet = @host@
    82     92   @MINGW_TRUE@am__append_1 = -lm
    83     93   @MINGW_FALSE@am__append_2 = -lpthread -lm
    84     94   @MINGW_TRUE@am__append_3 = -lm
    85     95   @MINGW_FALSE@am__append_4 = -lpthread -lm
    86     96   subdir = src
    87         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
    88         -	$(top_srcdir)/depcomp $(noinst_HEADERS)
    89     97   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    90     98   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    91     99   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    92    100   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    93    101   	$(top_srcdir)/configure.ac
    94    102   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    95    103   	$(ACLOCAL_M4)
          104  +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \
          105  +	$(am__DIST_COMMON)
    96    106   mkinstalldirs = $(install_sh) -d
    97    107   CONFIG_HEADER = $(top_builddir)/config.h
    98    108   CONFIG_CLEAN_FILES =
    99    109   CONFIG_CLEAN_VPATH_FILES =
   100    110   am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
   101    111   am__vpath_adj = case $$p in \
   102    112       $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
................................................................................
   230    240   am__define_uniq_tagged_files = \
   231    241     list='$(am__tagged_files)'; \
   232    242     unique=`for i in $$list; do \
   233    243       if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   234    244     done | $(am__uniquify_input)`
   235    245   ETAGS = etags
   236    246   CTAGS = ctags
          247  +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
   237    248   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   238    249   ACLOCAL = @ACLOCAL@
   239    250   AMTAR = @AMTAR@
   240    251   AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
   241    252   AR = @AR@
   242    253   AS = @AS@
   243    254   AUTOCONF = @AUTOCONF@
................................................................................
   391    402   	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
   392    403   	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
   393    404   	rl2auxgeom.c rl2auxfont.c
   394    405   
   395    406   librasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ @LIBLZMA_LIBS@ \
   396    407   	@LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
   397    408   	@LIBFREETYPE2_LIBS@ $(am__append_1) $(am__append_2)
   398         -@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 0:0:0
          409  +@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 1:0:0
   399    410   @MINGW_TRUE@librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
   400    411   mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
   401    412   	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
   402    413   	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
   403    414   	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
   404    415   	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
   405    416   	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
................................................................................
   407    418   
   408    419   mod_rasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ \
   409    420   	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
   410    421   	@LIBFREETYPE2_LIBS@ $(am__append_3) $(am__append_4)
   411    422   mod_rasterlite2_la_CPPFLAGS = @CFLAGS@ -I$(top_srcdir)/headers -I. \
   412    423   	-DLOADABLE_EXTENSION
   413    424   mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static
   414         -@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0
          425  +@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0
   415    426   @MINGW_TRUE@mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
   416    427   MOSTLYCLEANFILES = *.gcna *.gcno *.gcda
   417    428   all: all-am
   418    429   
   419    430   .SUFFIXES:
   420    431   .SUFFIXES: .c .lo .o .obj
   421    432   $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
................................................................................
   426    437   	        && { if test -f $@; then exit 0; else break; fi; }; \
   427    438   	      exit 1;; \
   428    439   	  esac; \
   429    440   	done; \
   430    441   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
   431    442   	$(am__cd) $(top_srcdir) && \
   432    443   	  $(AUTOMAKE) --gnu src/Makefile
   433         -.PRECIOUS: Makefile
   434    444   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   435    445   	@case '$?' in \
   436    446   	  *config.status*) \
   437    447   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   438    448   	  *) \
   439    449   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   440    450   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
   996   1006   	install-exec-am install-html install-html-am install-info \
   997   1007   	install-info-am install-libLTLIBRARIES install-man install-pdf \
   998   1008   	install-pdf-am install-ps install-ps-am install-strip \
   999   1009   	installcheck installcheck-am installdirs maintainer-clean \
  1000   1010   	maintainer-clean-generic mostlyclean mostlyclean-compile \
  1001   1011   	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
  1002   1012   	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES
         1013  +
         1014  +.PRECIOUS: Makefile
  1003   1015   
  1004   1016   
  1005   1017   # Tell versions [3.59,3.63) of GNU make to not export all variables.
  1006   1018   # Otherwise a system limit (for SysV at least) may be exceeded.
  1007   1019   .NOEXPORT:

Changes to src/rasterlite2.c.

   510    510   	  return RL2_FALSE;
   511    511   #endif
   512    512         };
   513    513       return RL2_ERROR;
   514    514   }
   515    515   
   516    516   static int
   517         -check_coverage_no_data (rl2PrivPixelPtr pxl_no_data, unsigned char sample_type,
   518         -			unsigned char pixel_type, unsigned char num_samples)
          517  +check_coverage_no_data (rl2PrivPixelPtr pxl_no_data,
          518  +			unsigned char sample_type, unsigned char pixel_type,
          519  +			unsigned char num_samples)
   519    520   {
   520    521   /* checking if the NoData pixel is consistent with the Coverage */
   521    522       if (pxl_no_data == NULL)
   522    523   	return 1;
   523    524       if (pxl_no_data->sampleType != sample_type)
   524    525   	return 0;
   525    526       if (pxl_no_data->pixelType != pixel_type)
................................................................................
  1251   1252       return (rl2RasterPtr) rst;
  1252   1253   }
  1253   1254   
  1254   1255   RL2_DECLARE rl2RasterPtr
  1255   1256   rl2_create_raster (unsigned int width, unsigned int height,
  1256   1257   		   unsigned char sample_type, unsigned char pixel_type,
  1257   1258   		   unsigned char num_samples, unsigned char *bufpix,
  1258         -		   int bufpix_size, rl2PalettePtr palette, unsigned char *mask,
  1259         -		   int mask_size, rl2PixelPtr no_data)
         1259  +		   int bufpix_size, rl2PalettePtr palette,
         1260  +		   unsigned char *mask, int mask_size, rl2PixelPtr no_data)
  1260   1261   {
  1261   1262   /* allocating and initializing a Raster object with an optional Transparency Mask */
  1262   1263       return create_raster_common (width, height, sample_type, pixel_type,
  1263   1264   				 num_samples, bufpix, bufpix_size, palette,
  1264   1265   				 mask, mask_size, no_data, 0);
  1265   1266   }
  1266   1267   
................................................................................
  1428   1429       rst->minY = cy - vExt;
  1429   1430       rst->maxX = cx + hExt;
  1430   1431       rst->maxY = cy + vExt;
  1431   1432       return RL2_OK;
  1432   1433   }
  1433   1434   
  1434   1435   RL2_DECLARE int
  1435         -rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid, double horz_res,
  1436         -				    double vert_res, double x, double y)
         1436  +rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid,
         1437  +				    double horz_res, double vert_res,
         1438  +				    double x, double y)
  1437   1439   {
  1438   1440   /* setting the Raster's georeferencing infos - UpperLeft corner */
  1439   1441       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
  1440   1442       double hExt;
  1441   1443       double vExt;
  1442   1444       if (rst == NULL)
  1443   1445   	return RL2_ERROR;
................................................................................
  1451   1453       rst->maxX = x + hExt;
  1452   1454       rst->maxY = y;
  1453   1455       return RL2_OK;
  1454   1456   }
  1455   1457   
  1456   1458   RL2_DECLARE int
  1457   1459   rl2_raster_georeference_upper_right (rl2RasterPtr ptr, int srid,
  1458         -				     double horz_res, double vert_res, double x,
  1459         -				     double y)
         1460  +				     double horz_res, double vert_res,
         1461  +				     double x, double y)
  1460   1462   {
  1461   1463   /* setting the Raster's georeferencing infos - UpperRight corner */
  1462   1464       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
  1463   1465       double hExt;
  1464   1466       double vExt;
  1465   1467       if (rst == NULL)
  1466   1468   	return RL2_ERROR;
................................................................................
  1473   1475       rst->minY = y - vExt;
  1474   1476       rst->maxX = x;
  1475   1477       rst->maxY = y;
  1476   1478       return RL2_OK;
  1477   1479   }
  1478   1480   
  1479   1481   RL2_DECLARE int
  1480         -rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid, double horz_res,
  1481         -				    double vert_res, double x, double y)
         1482  +rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid,
         1483  +				    double horz_res, double vert_res,
         1484  +				    double x, double y)
  1482   1485   {
  1483   1486   /* setting the Raster's georeferencing infos - LowerLeft corner */
  1484   1487       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
  1485   1488       double hExt;
  1486   1489       double vExt;
  1487   1490       if (rst == NULL)
  1488   1491   	return RL2_ERROR;
................................................................................
  1496   1499       rst->maxX = x + hExt;
  1497   1500       rst->maxY = y + vExt;
  1498   1501       return RL2_OK;
  1499   1502   }
  1500   1503   
  1501   1504   RL2_DECLARE int
  1502   1505   rl2_raster_georeference_lower_right (rl2RasterPtr ptr, int srid,
  1503         -				     double horz_res, double vert_res, double x,
  1504         -				     double y)
         1506  +				     double horz_res, double vert_res,
         1507  +				     double x, double y)
  1505   1508   {
  1506   1509   /* setting the Raster's georeferencing infos - LowerRight corner */
  1507   1510       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
  1508   1511       double hExt;
  1509   1512       double vExt;
  1510   1513       if (rst == NULL)
  1511   1514   	return RL2_ERROR;
................................................................................
  1803   1806       entry->red = r;
  1804   1807       entry->green = g;
  1805   1808       entry->blue = b;
  1806   1809       return RL2_OK;
  1807   1810   }
  1808   1811   
  1809   1812   RL2_DECLARE int
  1810         -rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index, unsigned char r,
  1811         -		       unsigned char g, unsigned char b)
         1813  +rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index,
         1814  +		       unsigned char r, unsigned char g, unsigned char b)
  1812   1815   {
  1813   1816   /* finding the index corresponding to the given color (if any) */
  1814   1817       int i;
  1815   1818       rl2PrivPaletteEntryPtr entry;
  1816   1819       rl2PrivPalettePtr plt = (rl2PrivPalettePtr) ptr;
  1817   1820       if (plt == NULL)
  1818   1821   	return RL2_ERROR;

Changes to src/rl2ascii.c.

   316    316   	 &no_data))
   317    317         {
   318    318   	  fprintf (stderr, "ASCII Origin: invalid Header found on %s\n", path);
   319    319   	  goto error;
   320    320         }
   321    321   
   322    322       ascii =
   323         -	alloc_ascii_origin (path, srid, sample_type, width, height, minx, miny,
   324         -			    maxx, maxy, xres, yres, no_data);
          323  +	alloc_ascii_origin (path, srid, sample_type, width, height, minx,
          324  +			    miny, maxx, maxy, xres, yres, no_data);
   325    325       if (ascii == NULL)
   326    326   	goto error;
   327    327   
   328    328       *buf = '\0';
   329    329       col_no = width;
   330    330   /* creating the helper Temporary File */
   331    331       ascii->tmp = tmpfile ();
................................................................................
   614    614   	return RL2_FALSE;
   615    615       if (coverage->Srid != srid)
   616    616         {
   617    617   	  if (verbose)
   618    618   	      fprintf (stderr, "Mismatching SRID !!!\n");
   619    619   	  return RL2_FALSE;
   620    620         }
   621         -    if (rl2_get_ascii_grid_origin_resolution (ascii, &hResolution, &vResolution)
   622         -	!= RL2_OK)
          621  +    if (rl2_get_ascii_grid_origin_resolution
          622  +	(ascii, &hResolution, &vResolution) != RL2_OK)
   623    623   	return RL2_FALSE;
   624    624       confidence = coverage->hResolution / 100.0;
   625    625       if (hResolution < (coverage->hResolution - confidence)
   626    626   	|| hResolution > (coverage->hResolution + confidence))
   627    627         {
   628    628   	  if (verbose)
   629    629   	      fprintf (stderr, "Mismatching Horizontal Resolution !!!\n");
................................................................................
   748    748   	  unsigned short *p_out = pixels + (y * width);
   749    749   	  if (fseek (origin->tmp, offset, SEEK_SET) != 0)
   750    750   	      return 0;
   751    751   	  for (x = 0, col = startCol; x < width && col < origin->width;
   752    752   	       x++, col++)
   753    753   	    {
   754    754   		unsigned short uint16;
   755         -		if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp) <=
   756         -		    0)
          755  +		if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp)
          756  +		    <= 0)
   757    757   		    return 0;
   758    758   		*p_out++ = uint16;
   759    759   	    }
   760    760         }
   761    761       return 1;
   762    762   }
   763    763   
................................................................................
  1068   1068   		      /* setting opaque pixels */
  1069   1069   		      memset (p, 1, shadow_x);
  1070   1070   		  }
  1071   1071   	    }
  1072   1072         }
  1073   1073       raster =
  1074   1074   	rl2_create_raster (coverage->tileWidth, coverage->tileHeight,
  1075         -			   coverage->sampleType, RL2_PIXEL_DATAGRID, 1, pixels,
  1076         -			   pixels_sz, NULL, mask, mask_size, NULL);
         1075  +			   coverage->sampleType, RL2_PIXEL_DATAGRID, 1,
         1076  +			   pixels, pixels_sz, NULL, mask, mask_size, NULL);
  1077   1077       if (raster == NULL)
  1078   1078   	goto error;
  1079   1079       return raster;
  1080   1080     error:
  1081   1081       if (pixels != NULL)
  1082   1082   	free (pixels);
  1083   1083       if (mask != NULL)

Changes to src/rl2auxfont.c.

   690    690   		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
   691    691   		      int blob_sz = sqlite3_column_bytes (stmt, 0);
   692    692   		      if (xfont != NULL)
   693    693   			{
   694    694   			    free (xfont);
   695    695   			    xfont = NULL;
   696    696   			}
   697         -		      if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz) ==
   698         -			  RL2_OK)
          697  +		      if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz)
          698  +			  == RL2_OK)
   699    699   			{
   700    700   			    *font = xfont;
   701    701   			    *font_sz = xfont_sz;
   702    702   			}
   703    703   		  }
   704    704   	    }
   705    705   	  else
................................................................................
   723    723   		       unsigned char **font, int *font_sz)
   724    724   {
   725    725   /* attempting to fetch a BLOB-encoded TrueType Font */
   726    726       const char *sql;
   727    727       int ret;
   728    728       sqlite3_stmt *stmt = NULL;
   729    729       unsigned char *xfont = NULL;
   730         -    int xfont_sz;
   731    730       if (facename == NULL)
   732    731   	return RL2_ERROR;
   733    732   
   734    733       *font = NULL;
   735    734       *font_sz = 0;
   736    735   /* preparing the SQL query statement */
   737    736       sql = "SELECT font FROM SE_fonts WHERE Lower(font_facename) = Lower(?)";
................................................................................
   782    781   }
   783    782   
   784    783   RL2_DECLARE rl2GraphicsFontPtr
   785    784   rl2_search_TrueType_font (sqlite3 * handle, const void *priv_data,
   786    785   			  const char *facename, double size)
   787    786   {
   788    787   /* attempting to fetch and create a TrueType Font */
          788  +    rl2GraphicsFontPtr font;
   789    789       unsigned char *ttf = NULL;
   790    790       int ttf_sz;
   791    791       if (facename == NULL)
   792    792   	return NULL;
   793    793   
   794    794       if (rl2_get_TrueType_font (handle, facename, &ttf, &ttf_sz) != RL2_OK)
   795    795   	return NULL;
   796         -    return rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size);
          796  +    font = rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size);
          797  +    if (ttf != NULL)
          798  +	free (ttf);
          799  +    return font;
   797    800   }

Changes to src/rl2auxgeom.c.

   122    122   static rl2LinestringPtr
   123    123   rl2CreateLinestring (int vert)
   124    124   {
   125    125   /* LINESTRING object constructor */
   126    126       rl2LinestringPtr p = malloc (sizeof (rl2Linestring));
   127    127       p->coords = malloc (sizeof (double) * (vert * 2));
   128    128       p->points = vert;
          129  +    p->minx = DBL_MAX;
          130  +    p->miny = DBL_MAX;
          131  +    p->maxx = 0.0 - DBL_MAX;
          132  +    p->maxy = 0.0 - DBL_MAX;
   129    133       p->next = NULL;
   130    134       return p;
   131    135   }
   132    136   
   133         -static void
          137  +RL2_PRIVATE void
   134    138   rl2DestroyLinestring (rl2LinestringPtr ptr)
   135    139   {
   136    140   /* LINESTRING object desctructror */
   137    141       if (ptr)
   138    142         {
   139    143   	  if (ptr->coords)
   140    144   	      free (ptr->coords);
   141    145   	  free (ptr);
   142    146         }
   143    147   }
          148  +
          149  +RL2_PRIVATE rl2LinestringPtr
          150  +rl2_linestring_to_image (rl2LinestringPtr line, int height, double minx,
          151  +			 double miny, double x_res, double y_res)
          152  +{
          153  +/* creating a Linestring in image coordinates */
          154  +    rl2LinestringPtr out = NULL;
          155  +    int iv;
          156  +    double x;
          157  +    double y;
          158  +    double dx;
          159  +    double dy;
          160  +
          161  +    if (line == NULL)
          162  +	return NULL;
          163  +    out = rl2CreateLinestring (line->points);
          164  +    if (out == NULL)
          165  +	return out;
          166  +    for (iv = 0; iv < line->points; iv++)
          167  +      {
          168  +	  /* populating the X and Y arrays */
          169  +	  rl2GetPoint (line->coords, iv, &x, &y);
          170  +	  dx = (x - minx) / x_res;
          171  +	  dy = (double) height - ((y - miny) / y_res);
          172  +	  rl2SetPoint (out->coords, iv, dx, dy);
          173  +      }
          174  +    return out;
          175  +}
   144    176   
   145    177   static rl2RingPtr
   146    178   rl2CreateRing (int vert)
   147    179   {
   148    180   /* ring object constructor */
   149    181       rl2RingPtr p = malloc (sizeof (rl2Ring));
   150    182       p->coords = malloc (sizeof (double) * (vert * 2));
   151    183       p->points = vert;
          184  +    p->minx = DBL_MAX;
          185  +    p->miny = DBL_MAX;
          186  +    p->maxx = 0.0 - DBL_MAX;
          187  +    p->maxy = 0.0 - DBL_MAX;
   152    188       p->next = NULL;
   153    189       return p;
   154    190   }
   155    191   
   156         -static void
          192  +RL2_PRIVATE rl2RingPtr
          193  +rl2_ring_to_image (rl2RingPtr ring, int height, double minx, double miny,
          194  +		   double x_res, double y_res)
          195  +{
          196  +/* creating a Ring in image coordinates */
          197  +    rl2RingPtr out = NULL;
          198  +    int iv;
          199  +    double x;
          200  +    double y;
          201  +    double dx;
          202  +    double dy;
          203  +
          204  +    if (ring == NULL)
          205  +	return NULL;
          206  +    out = rl2CreateRing (ring->points);
          207  +    if (out == NULL)
          208  +	return out;
          209  +    for (iv = 0; iv < ring->points; iv++)
          210  +      {
          211  +	  /* populating the X and Y arrays */
          212  +	  rl2GetPoint (ring->coords, iv, &x, &y);
          213  +	  dx = (x - minx) / x_res;
          214  +	  dy = (double) height - ((y - miny) / y_res);
          215  +	  rl2SetPoint (out->coords, iv, dx, dy);
          216  +      }
          217  +    return out;
          218  +}
          219  +
          220  +RL2_PRIVATE void
   157    221   rl2DestroyRing (rl2RingPtr ptr)
   158    222   {
   159    223   /* ring object destructor */
   160    224       if (ptr)
   161    225         {
   162    226   	  if (ptr->coords)
   163    227   	      free (ptr->coords);
................................................................................
   181    245       else
   182    246   	p->interiors = malloc (sizeof (rl2Ring) * excl);
   183    247       for (ind = 0; ind < p->num_interiors; ind++)
   184    248         {
   185    249   	  pP = p->interiors + ind;
   186    250   	  pP->points = 0;
   187    251   	  pP->coords = NULL;
          252  +	  pP->minx = DBL_MAX;
          253  +	  pP->miny = DBL_MAX;
          254  +	  pP->maxx = 0.0 - DBL_MAX;
          255  +	  pP->maxy = 0.0 - DBL_MAX;
   188    256         }
   189    257       return p;
   190    258   }
   191    259   
   192    260   static void
   193    261   rl2DestroyPolygon (rl2PolygonPtr p)
   194    262   {
................................................................................
   622    690   	return;
   623    691       line = rl2AddLinestringToGeometry (geom, points);
   624    692       for (iv = 0; iv < points; iv++)
   625    693         {
   626    694   	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   627    695   	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   628    696   	  rl2SetPoint (line->coords, iv, x, y);
          697  +	  if (x < line->minx)
          698  +	      line->minx = x;
          699  +	  if (x > line->maxx)
          700  +	      line->maxx = x;
          701  +	  if (y < line->miny)
          702  +	      line->miny = y;
          703  +	  if (y > line->maxy)
          704  +	      line->maxy = y;
   629    705   	  *offset += 16;
   630    706         }
   631    707   }
   632    708   
   633    709   static void
   634    710   rl2ParseLineZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
   635    711   	       int endian, int endian_arch, int *offset)
................................................................................
   648    724   	return;
   649    725       line = rl2AddLinestringToGeometry (geom, points);
   650    726       for (iv = 0; iv < points; iv++)
   651    727         {
   652    728   	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   653    729   	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   654    730   	  rl2SetPoint (line->coords, iv, x, y);
          731  +	  if (x < line->minx)
          732  +	      line->minx = x;
          733  +	  if (x > line->maxx)
          734  +	      line->maxx = x;
          735  +	  if (y < line->miny)
          736  +	      line->miny = y;
          737  +	  if (y > line->maxy)
          738  +	      line->maxy = y;
   655    739   	  *offset += 24;
   656    740         }
   657    741   }
   658    742   
   659    743   static void
   660    744   rl2ParseLineM (rl2GeometryPtr geom, const unsigned char *blob, int size,
   661    745   	       int endian, int endian_arch, int *offset)
................................................................................
   674    758   	return;
   675    759       line = rl2AddLinestringToGeometry (geom, points);
   676    760       for (iv = 0; iv < points; iv++)
   677    761         {
   678    762   	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   679    763   	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   680    764   	  rl2SetPoint (line->coords, iv, x, y);
          765  +	  if (x < line->minx)
          766  +	      line->minx = x;
          767  +	  if (x > line->maxx)
          768  +	      line->maxx = x;
          769  +	  if (y < line->miny)
          770  +	      line->miny = y;
          771  +	  if (y > line->maxy)
          772  +	      line->maxy = y;
   681    773   	  *offset += 24;
   682    774         }
   683    775   }
   684    776   
   685    777   static void
   686    778   rl2ParseLineZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
   687    779   		int endian, int endian_arch, int *offset)
................................................................................
   700    792   	return;
   701    793       line = rl2AddLinestringToGeometry (geom, points);
   702    794       for (iv = 0; iv < points; iv++)
   703    795         {
   704    796   	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   705    797   	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   706    798   	  rl2SetPoint (line->coords, iv, x, y);
          799  +	  if (x < line->minx)
          800  +	      line->minx = x;
          801  +	  if (x > line->maxx)
          802  +	      line->maxx = x;
          803  +	  if (y < line->miny)
          804  +	      line->miny = y;
          805  +	  if (y > line->maxy)
          806  +	      line->maxy = y;
   707    807   	  *offset += 32;
   708    808         }
   709    809   }
   710    810   
   711    811   static rl2PolygonPtr
   712    812   rl2AddPolygonToGeometry (rl2GeometryPtr p, int vert, int interiors)
   713    813   {
................................................................................
   765    865   	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
   766    866   	  for (iv = 0; iv < nverts; iv++)
   767    867   	    {
   768    868   		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   769    869   		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   770    870   		*offset += 16;
   771    871   		rl2SetPoint (ring->coords, iv, x, y);
          872  +		if (x < ring->minx)
          873  +		    ring->minx = x;
          874  +		if (x > ring->maxx)
          875  +		    ring->maxx = x;
          876  +		if (y < ring->miny)
          877  +		    ring->miny = y;
          878  +		if (y > ring->maxy)
          879  +		    ring->maxy = y;
   772    880   	    }
   773    881         }
   774    882   }
   775    883   
   776    884   static void
   777    885   rl2ParsePolygonZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
   778    886   		  int endian, int endian_arch, int *offset)
................................................................................
   807    915   	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
   808    916   	  for (iv = 0; iv < nverts; iv++)
   809    917   	    {
   810    918   		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   811    919   		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   812    920   		*offset += 24;
   813    921   		rl2SetPoint (ring->coords, iv, x, y);
          922  +		if (x < ring->minx)
          923  +		    ring->minx = x;
          924  +		if (x > ring->maxx)
          925  +		    ring->maxx = x;
          926  +		if (y < ring->miny)
          927  +		    ring->miny = y;
          928  +		if (y > ring->maxy)
          929  +		    ring->maxy = y;
   814    930   	    }
   815    931         }
   816    932   }
   817    933   
   818    934   static void
   819    935   rl2ParsePolygonM (rl2GeometryPtr geom, const unsigned char *blob, int size,
   820    936   		  int endian, int endian_arch, int *offset)
................................................................................
   849    965   	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
   850    966   	  for (iv = 0; iv < nverts; iv++)
   851    967   	    {
   852    968   		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   853    969   		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   854    970   		*offset += 24;
   855    971   		rl2SetPoint (ring->coords, iv, x, y);
          972  +		if (x < ring->minx)
          973  +		    ring->minx = x;
          974  +		if (x > ring->maxx)
          975  +		    ring->maxx = x;
          976  +		if (y < ring->miny)
          977  +		    ring->miny = y;
          978  +		if (y > ring->maxy)
          979  +		    ring->maxy = y;
   856    980   	    }
   857    981         }
   858    982   }
   859    983   
   860    984   static void
   861    985   rl2ParsePolygonZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
   862    986   		   int endian, int endian_arch, int *offset)
................................................................................
   891   1015   	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
   892   1016   	  for (iv = 0; iv < nverts; iv++)
   893   1017   	    {
   894   1018   		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
   895   1019   		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
   896   1020   		*offset += 32;
   897   1021   		rl2SetPoint (ring->coords, iv, x, y);
         1022  +		if (x < ring->minx)
         1023  +		    ring->minx = x;
         1024  +		if (x > ring->maxx)
         1025  +		    ring->maxx = x;
         1026  +		if (y < ring->miny)
         1027  +		    ring->miny = y;
         1028  +		if (y > ring->maxy)
         1029  +		    ring->maxy = y;
   898   1030   	    }
   899   1031         }
   900   1032   }
   901   1033   
   902   1034   static void
   903   1035   rl2ParseCompressedLine (rl2GeometryPtr geom, const unsigned char *blob,
   904   1036   			int size, int endian, int endian_arch, int *offset)
................................................................................
   936   1068   		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
   937   1069   				       endian_arch);
   938   1070   		x = last_x + fx;
   939   1071   		y = last_y + fy;
   940   1072   		*offset += 8;
   941   1073   	    }
   942   1074   	  rl2SetPoint (line->coords, iv, x, y);
         1075  +	  if (x < line->minx)
         1076  +	      line->minx = x;
         1077  +	  if (x > line->maxx)
         1078  +	      line->maxx = x;
         1079  +	  if (y < line->miny)
         1080  +	      line->miny = y;
         1081  +	  if (y > line->maxy)
         1082  +	      line->maxy = y;
   943   1083   	  last_x = x;
   944   1084   	  last_y = y;
   945   1085         }
   946   1086   }
   947   1087   
   948   1088   static void
   949   1089   rl2ParseCompressedLineZ (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
   982   1122   		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
   983   1123   				       endian_arch);
   984   1124   		x = last_x + fx;
   985   1125   		y = last_y + fy;
   986   1126   		*offset += 12;
   987   1127   	    }
   988   1128   	  rl2SetPoint (line->coords, iv, x, y);
         1129  +	  if (x < line->minx)
         1130  +	      line->minx = x;
         1131  +	  if (x > line->maxx)
         1132  +	      line->maxx = x;
         1133  +	  if (y < line->miny)
         1134  +	      line->miny = y;
         1135  +	  if (y > line->maxy)
         1136  +	      line->maxy = y;
   989   1137   	  last_x = x;
   990   1138   	  last_y = y;
   991   1139         }
   992   1140   }
   993   1141   
   994   1142   static void
   995   1143   rl2ParseCompressedLineM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
  1028   1176   		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1029   1177   				       endian_arch);
  1030   1178   		x = last_x + fx;
  1031   1179   		y = last_y + fy;
  1032   1180   		*offset += 16;
  1033   1181   	    }
  1034   1182   	  rl2SetPoint (line->coords, iv, x, y);
         1183  +	  if (x < line->minx)
         1184  +	      line->minx = x;
         1185  +	  if (x > line->maxx)
         1186  +	      line->maxx = x;
         1187  +	  if (y < line->miny)
         1188  +	      line->miny = y;
         1189  +	  if (y > line->maxy)
         1190  +	      line->maxy = y;
  1035   1191   	  last_x = x;
  1036   1192   	  last_y = y;
  1037   1193         }
  1038   1194   }
  1039   1195   
  1040   1196   static void
  1041   1197   rl2ParseCompressedLineZM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
  1074   1230   		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1075   1231   				       endian_arch);
  1076   1232   		x = last_x + fx;
  1077   1233   		y = last_y + fy;
  1078   1234   		*offset += 20;
  1079   1235   	    }
  1080   1236   	  rl2SetPoint (line->coords, iv, x, y);
         1237  +	  if (x < line->minx)
         1238  +	      line->minx = x;
         1239  +	  if (x > line->maxx)
         1240  +	      line->maxx = x;
         1241  +	  if (y < line->miny)
         1242  +	      line->miny = y;
         1243  +	  if (y > line->maxy)
         1244  +	      line->maxy = y;
  1081   1245   	  last_x = x;
  1082   1246   	  last_y = y;
  1083   1247         }
  1084   1248   }
  1085   1249   
  1086   1250   static void
  1087   1251   rl2ParseCompressedPolygon (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
  1137   1301   		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1138   1302   					     endian_arch);
  1139   1303   		      x = last_x + fx;
  1140   1304   		      y = last_y + fy;
  1141   1305   		      *offset += 8;
  1142   1306   		  }
  1143   1307   		rl2SetPoint (ring->coords, iv, x, y);
         1308  +		if (x < ring->minx)
         1309  +		    ring->minx = x;
         1310  +		if (x > ring->maxx)
         1311  +		    ring->maxx = x;
         1312  +		if (y < ring->miny)
         1313  +		    ring->miny = y;
         1314  +		if (y > ring->maxy)
         1315  +		    ring->maxy = y;
  1144   1316   		last_x = x;
  1145   1317   		last_y = y;
  1146   1318   	    }
  1147   1319         }
  1148   1320   }
  1149   1321   
  1150   1322   static void
................................................................................
  1201   1373   		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1202   1374   					     endian_arch);
  1203   1375   		      x = last_x + fx;
  1204   1376   		      y = last_y + fy;
  1205   1377   		      *offset += 12;
  1206   1378   		  }
  1207   1379   		rl2SetPoint (ring->coords, iv, x, y);
         1380  +		if (x < ring->minx)
         1381  +		    ring->minx = x;
         1382  +		if (x > ring->maxx)
         1383  +		    ring->maxx = x;
         1384  +		if (y < ring->miny)
         1385  +		    ring->miny = y;
         1386  +		if (y > ring->maxy)
         1387  +		    ring->maxy = y;
  1208   1388   		last_x = x;
  1209   1389   		last_y = y;
  1210   1390   	    }
  1211   1391         }
  1212   1392   }
  1213   1393   
  1214   1394   static void
................................................................................
  1265   1445   		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1266   1446   					     endian_arch);
  1267   1447   		      x = last_x + fx;
  1268   1448   		      y = last_y + fy;
  1269   1449   		      *offset += 16;
  1270   1450   		  }
  1271   1451   		rl2SetPoint (ring->coords, iv, x, y);
         1452  +		if (x < ring->minx)
         1453  +		    ring->minx = x;
         1454  +		if (x > ring->maxx)
         1455  +		    ring->maxx = x;
         1456  +		if (y < ring->miny)
         1457  +		    ring->miny = y;
         1458  +		if (y > ring->maxy)
         1459  +		    ring->maxy = y;
  1272   1460   		last_x = x;
  1273   1461   		last_y = y;
  1274   1462   	    }
  1275   1463         }
  1276   1464   }
  1277   1465   
  1278   1466   static void
................................................................................
  1329   1517   		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
  1330   1518   					     endian_arch);
  1331   1519   		      x = last_x + fx;
  1332   1520   		      y = last_y + fy;
  1333   1521   		      *offset += 20;
  1334   1522   		  }
  1335   1523   		rl2SetPoint (ring->coords, iv, x, y);
         1524  +		if (x < ring->minx)
         1525  +		    ring->minx = x;
         1526  +		if (x > ring->maxx)
         1527  +		    ring->maxx = x;
         1528  +		if (y < ring->miny)
         1529  +		    ring->miny = y;
         1530  +		if (y > ring->maxy)
         1531  +		    ring->maxy = y;
  1336   1532   		last_x = x;
  1337   1533   		last_y = y;
  1338   1534   	    }
  1339   1535         }
  1340   1536   }
  1341   1537   
  1342   1538   static void
................................................................................
  1399   1595   				   offset);
  1400   1596   		break;
  1401   1597   	    case GAIA_COMPRESSED_LINESTRING:
  1402   1598   		rl2ParseCompressedLine (geom, blob, size, endian, endian_arch,
  1403   1599   					offset);
  1404   1600   		break;
  1405   1601   	    case GAIA_COMPRESSED_LINESTRINGZ:
  1406         -		rl2ParseCompressedLineZ (geom, blob, size, endian, endian_arch,
  1407         -					 offset);
         1602  +		rl2ParseCompressedLineZ (geom, blob, size, endian,
         1603  +					 endian_arch, offset);
  1408   1604   		break;
  1409   1605   	    case GAIA_COMPRESSED_LINESTRINGM:
  1410         -		rl2ParseCompressedLineM (geom, blob, size, endian, endian_arch,
  1411         -					 offset);
         1606  +		rl2ParseCompressedLineM (geom, blob, size, endian,
         1607  +					 endian_arch, offset);
  1412   1608   		break;
  1413   1609   	    case GAIA_COMPRESSED_LINESTRINGZM:
  1414         -		rl2ParseCompressedLineZM (geom, blob, size, endian, endian_arch,
  1415         -					  offset);
         1610  +		rl2ParseCompressedLineZM (geom, blob, size, endian,
         1611  +					  endian_arch, offset);
  1416   1612   		break;
  1417   1613   	    case GAIA_COMPRESSED_POLYGON:
  1418   1614   		rl2ParseCompressedPolygon (geom, blob, size, endian,
  1419   1615   					   endian_arch, offset);
  1420   1616   		break;
  1421   1617   	    case GAIA_COMPRESSED_POLYGONZ:
  1422   1618   		rl2ParseCompressedPolygonZ (geom, blob, size, endian,
................................................................................
  1506   1702   			    &offset);
  1507   1703   	  break;
  1508   1704         case GAIA_POLYGONZM:
  1509   1705   	  rl2ParsePolygonZM (geom, blob, size, little_endian, endian_arch,
  1510   1706   			     &offset);
  1511   1707   	  break;
  1512   1708         case GAIA_COMPRESSED_LINESTRING:
  1513         -	  rl2ParseCompressedLine (geom, blob, size, little_endian, endian_arch,
  1514         -				  &offset);
         1709  +	  rl2ParseCompressedLine (geom, blob, size, little_endian,
         1710  +				  endian_arch, &offset);
  1515   1711   	  break;
  1516   1712         case GAIA_COMPRESSED_LINESTRINGZ:
  1517         -	  rl2ParseCompressedLineZ (geom, blob, size, little_endian, endian_arch,
  1518         -				   &offset);
         1713  +	  rl2ParseCompressedLineZ (geom, blob, size, little_endian,
         1714  +				   endian_arch, &offset);
  1519   1715   	  break;
  1520   1716         case GAIA_COMPRESSED_LINESTRINGM:
  1521         -	  rl2ParseCompressedLineM (geom, blob, size, little_endian, endian_arch,
  1522         -				   &offset);
         1717  +	  rl2ParseCompressedLineM (geom, blob, size, little_endian,
         1718  +				   endian_arch, &offset);
  1523   1719   	  break;
  1524   1720         case GAIA_COMPRESSED_LINESTRINGZM:
  1525   1721   	  rl2ParseCompressedLineZM (geom, blob, size, little_endian,
  1526   1722   				    endian_arch, &offset);
  1527   1723   	  break;
  1528   1724         case GAIA_COMPRESSED_POLYGON:
  1529   1725   	  rl2ParseCompressedPolygon (geom, blob, size, little_endian,
................................................................................
  1719   1915   	  rl2GeomExport64 (ptr, x, 1, endian_arch);	/* X - exterior ring */
  1720   1916   	  rl2GeomExport64 (ptr + 8, y, 1, endian_arch);	/* Y - exterior ring */
  1721   1917   	  ptr += 16;
  1722   1918         }
  1723   1919       *ptr = GAIA_MARK_END;	/* END signature */
  1724   1920       return 1;
  1725   1921   }
         1922  +
         1923  +RL2_PRIVATE int
         1924  +rl2_serialize_ring_as_linestring (rl2RingPtr ring, unsigned char **result,
         1925  +				  int *size)
         1926  +{
         1927  +/* serializing a BLOB Geometry - polygon ring as linestring */
         1928  +    int iv;
         1929  +    unsigned char *ptr;
         1930  +    int endian_arch = rl2GeomEndianArch ();
         1931  +    double minx = DBL_MAX;
         1932  +    double maxx = 0.0 - DBL_MAX;
         1933  +    double miny = DBL_MAX;
         1934  +    double maxy = 0.0 - DBL_MAX;
         1935  +    double x;
         1936  +    double y;
         1937  +
         1938  +    *result = NULL;
         1939  +    *size = 0;
         1940  +    if (ring == NULL)
         1941  +	return 0;
         1942  +
         1943  +/* computing the MBR */
         1944  +    for (iv = 0; iv < ring->points; iv++)
         1945  +      {
         1946  +	  rl2GetPoint (ring->coords, iv, &x, &y);
         1947  +	  if (x < minx)
         1948  +	      minx = x;
         1949  +	  if (x > maxx)
         1950  +	      maxx = x;
         1951  +	  if (y < miny)
         1952  +	      miny = y;
         1953  +	  if (y > maxy)
         1954  +	      maxy = y;
         1955  +      }
         1956  +/* computing the size of BLOB */
         1957  +    *size = 44;			/* header size */
         1958  +    *size += (4 + ((sizeof (double) * 2) * ring->points));	/* # points + [x,y] for each vertex */
         1959  +    *result = malloc (*size);
         1960  +    ptr = *result;
         1961  +/* building the BLOB */
         1962  +    *ptr = GAIA_MARK_START;	/* START signature */
         1963  +    *(ptr + 1) = GAIA_LITTLE_ENDIAN;	/* byte ordering */
         1964  +    rl2GeomExport32 (ptr + 2, 4326, 1, endian_arch);	/* the SRID */
         1965  +    rl2GeomExport64 (ptr + 6, minx, 1, endian_arch);	/* MBR - minimum X */
         1966  +    rl2GeomExport64 (ptr + 14, miny, 1, endian_arch);	/* MBR - minimum Y */
         1967  +    rl2GeomExport64 (ptr + 22, maxx, 1, endian_arch);	/* MBR - maximum X */
         1968  +    rl2GeomExport64 (ptr + 30, maxy, 1, endian_arch);	/* MBR - maximum Y */
         1969  +    *(ptr + 38) = GAIA_MARK_MBR;	/* MBR signature */
         1970  +    rl2GeomExport32 (ptr + 39, GAIA_LINESTRING, 1, endian_arch);	/* class LINESTRING */
         1971  +    rl2GeomExport32 (ptr + 43, ring->points, 1, endian_arch);	/* # points */
         1972  +    ptr += 47;
         1973  +    for (iv = 0; iv < ring->points; iv++)
         1974  +      {
         1975  +	  rl2GetPoint (ring->coords, iv, &x, &y);
         1976  +	  rl2GeomExport64 (ptr, x, 1, endian_arch);
         1977  +	  rl2GeomExport64 (ptr + 8, y, 1, endian_arch);
         1978  +	  ptr += 16;
         1979  +      }
         1980  +    *ptr = GAIA_MARK_END;	/* END signature */
         1981  +    return 1;
         1982  +}
  1726   1983   
  1727   1984   RL2_PRIVATE rl2GeometryPtr
  1728   1985   rl2_curve_from_XY (int points, double *x, double *y)
  1729   1986   {
  1730   1987   /* creating a Linestring Geometry from X,Y coordinate arrays */
  1731   1988       rl2GeometryPtr geom = NULL;
  1732   1989       rl2LinestringPtr ln;
................................................................................
  1733   1990       int iv;
  1734   1991   
  1735   1992       if (points <= 0 || x == NULL || y == NULL)
  1736   1993   	return 0;
  1737   1994       geom = rl2CreateGeometry ();
  1738   1995       ln = rl2AddLinestringToGeometry (geom, points);
  1739   1996       for (iv = 0; iv < points; iv++)
  1740         -	rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv));
         1997  +      {
         1998  +	  rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv));
         1999  +	  if (*(x + iv) < ln->minx)
         2000  +	      ln->minx = *(x + iv);
         2001  +	  if (*(x + iv) > ln->maxx)
         2002  +	      ln->maxx = *(x + iv);
         2003  +	  if (*(y + iv) < ln->miny)
         2004  +	      ln->miny = *(y + iv);
         2005  +	  if (*(y + iv) > ln->maxy)
         2006  +	      ln->maxy = *(y + iv);
         2007  +      }
  1741   2008       return geom;
  1742   2009   }
  1743   2010   
  1744   2011   RL2_PRIVATE double
  1745   2012   rl2_compute_curve_length (rl2GeometryPtr geom)
  1746   2013   {
  1747   2014   /* computing the total length of some curve (single linestring expected) */
................................................................................
  1850   2117       ln_out = rl2AddLinestringToGeometry (out, ln_in->points);
  1851   2118       for (iv = 0; iv < ln_in->points; iv++)
  1852   2119         {
  1853   2120   	  double x;
  1854   2121   	  double y;
  1855   2122   	  rl2GetPoint (ln_in->coords, iv, &x, &y);
  1856   2123   	  rl2SetPoint (ln_out->coords, iv, x, y);
         2124  +	  if (x < ln_out->minx)
         2125  +	      ln_out->minx = x;
         2126  +	  if (x > ln_out->maxx)
         2127  +	      ln_out->maxx = x;
         2128  +	  if (y < ln_out->miny)
         2129  +	      ln_out->miny = y;
         2130  +	  if (y > ln_out->maxy)
         2131  +	      ln_out->maxy = y;
  1857   2132         }
  1858   2133       return out;
  1859   2134   }
  1860   2135   
  1861   2136   RL2_PRIVATE rl2GeometryPtr
  1862   2137   rl2_clone_linestring (rl2LinestringPtr in)
  1863   2138   {
................................................................................
  1870   2145       ln_out = rl2AddLinestringToGeometry (out, in->points);
  1871   2146       for (iv = 0; iv < in->points; iv++)
  1872   2147         {
  1873   2148   	  double x;
  1874   2149   	  double y;
  1875   2150   	  rl2GetPoint (in->coords, iv, &x, &y);
  1876   2151   	  rl2SetPoint (ln_out->coords, iv, x, y);
         2152  +	  if (x < ln_out->minx)
         2153  +	      ln_out->minx = x;
         2154  +	  if (x > ln_out->maxx)
         2155  +	      ln_out->maxx = x;
         2156  +	  if (y < ln_out->miny)
         2157  +	      ln_out->miny = y;
         2158  +	  if (y > ln_out->maxy)
         2159  +	      ln_out->maxy = y;
  1877   2160         }
  1878   2161       return out;
  1879   2162   }
  1880   2163   
  1881   2164   RL2_PRIVATE rl2GeometryPtr
  1882   2165   rl2_build_circle (double cx, double cy, double radius)
  1883   2166   {
  1884         -/* creating a cicrle */
         2167  +/* creating a circle */
  1885   2168       int iv = 0;
  1886   2169       double pi = 3.14159265359;
  1887   2170       double rads;
  1888   2171       double x;
  1889   2172       double y;
  1890   2173       rl2LinestringPtr ln;
  1891   2174       rl2GeometryPtr out = rl2CreateGeometry ();
  1892   2175       ln = rl2AddLinestringToGeometry (out, 129);
  1893   2176       for (rads = 0.0; rads <= (pi * 2.0); rads += pi / 64.0)
  1894   2177         {
  1895   2178   	  x = cx + (radius * cos (rads));
  1896   2179   	  y = cy + (radius * sin (rads));
  1897   2180   	  rl2SetPoint (ln->coords, iv, x, y);
         2181  +	  if (x < ln->minx)
         2182  +	      ln->minx = x;
         2183  +	  if (x > ln->maxx)
         2184  +	      ln->maxx = x;
         2185  +	  if (y < ln->miny)
         2186  +	      ln->miny = y;
         2187  +	  if (y > ln->maxy)
         2188  +	      ln->maxy = y;
  1898   2189   	  iv++;
  1899   2190         }
  1900   2191       /* closure */
  1901   2192       rl2GetPoint (ln->coords, 0, &x, &y);
  1902   2193       rl2SetPoint (ln->coords, 128, x, y);
  1903   2194       return out;
  1904   2195   }

Changes to src/rl2auxrender.c.

   288    288   		  }
   289    289   	    }
   290    290         }
   291    291   }
   292    292   
   293    293   static void
   294    294   copy_palette (unsigned char *rgba, unsigned int width, unsigned int height,
   295         -	      unsigned char *inbuf, rl2PalettePtr palette, unsigned char bg_red,
   296         -	      unsigned char bg_green, unsigned char bg_blue)
          295  +	      unsigned char *inbuf, rl2PalettePtr palette,
          296  +	      unsigned char bg_red, unsigned char bg_green,
          297  +	      unsigned char bg_blue)
   297    298   {
   298    299   /* copying from Palette to RGBA */
   299    300       unsigned int x;
   300    301       unsigned int y;
   301    302       rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
   302    303       unsigned char *p_in = inbuf;
   303    304       unsigned char *p_out = rgba;
................................................................................
   450    451   	goto error;
   451    452   
   452    453       if (aux->base_width == aux->width && aux->base_height == aux->height)
   453    454         {
   454    455   	  if (aux->out_pixel == RL2_PIXEL_MONOCHROME)
   455    456   	    {
   456    457   		/* Monochrome */
   457         -		copy_monochrome (aggreg_rgba, aux->base_width, aux->base_height,
   458         -				 aux->outbuf);
          458  +		copy_monochrome (aggreg_rgba, aux->base_width,
          459  +				 aux->base_height, aux->outbuf);
   459    460   		aux->outbuf = NULL;
   460    461   	    }
   461    462   	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
   462    463   	    {
   463    464   		/* Palette */
   464    465   		copy_palette (aggreg_rgba, aux->base_width, aux->base_height,
   465    466   			      aux->outbuf, aux->palette, aux->bg_red,
   466    467   			      aux->bg_green, aux->bg_blue);
   467    468   		aux->outbuf = NULL;
   468    469   	    }
   469    470   	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
   470    471   	    {
   471    472   		/* Grayscale */
   472         -		copy_grayscale (aggreg_rgba, aux->base_width, aux->base_height,
   473         -				aux->outbuf, aux->bg_red);
          473  +		copy_grayscale (aggreg_rgba, aux->base_width,
          474  +				aux->base_height, aux->outbuf, aux->bg_red);
   474    475   		aux->outbuf = NULL;
   475    476   	    }
   476    477   	  else
   477    478   	    {
   478    479   		/* RGB */
   479    480   		copy_rgb (aggreg_rgba, aux->base_width, aux->base_height,
   480    481   			  aux->outbuf, aux->bg_red, aux->bg_green,
................................................................................
   607    608   			}
   608    609   		  }
   609    610   		else
   610    611   		  {
   611    612   		      if (!get_payload_from_monochrome_opaque
   612    613   			  (aux->base_width, aux->base_height, aux->sqlite,
   613    614   			   aux->minx, aux->miny, aux->maxx, aux->maxy,
   614         -			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
   615         -			   &image, &image_size))
          615  +			   aux->srid, aux->outbuf, aux->format_id,
          616  +			   aux->quality, &image, &image_size))
   616    617   			{
   617    618   			    aux->outbuf = NULL;
   618    619   			    goto error;
   619    620   			}
   620    621   		  }
   621    622   		aux->outbuf = NULL;
   622    623   	    }
................................................................................
   636    637   			}
   637    638   		  }
   638    639   		else
   639    640   		  {
   640    641   		      if (!get_payload_from_palette_opaque
   641    642   			  (aux->base_width, aux->base_height, aux->sqlite,
   642    643   			   aux->minx, aux->miny, aux->maxx, aux->maxy,
   643         -			   aux->srid, aux->outbuf, aux->palette, aux->format_id,
   644         -			   aux->quality, &image, &image_size))
          644  +			   aux->srid, aux->outbuf, aux->palette,
          645  +			   aux->format_id, aux->quality, &image, &image_size))
   645    646   			{
   646    647   			    aux->outbuf = NULL;
   647    648   			    goto error;
   648    649   			}
   649    650   		  }
   650    651   		aux->outbuf = NULL;
   651    652   	    }
................................................................................
   664    665   			}
   665    666   		  }
   666    667   		else
   667    668   		  {
   668    669   		      if (!get_payload_from_grayscale_opaque
   669    670   			  (aux->base_width, aux->base_height, aux->sqlite,
   670    671   			   aux->minx, aux->miny, aux->maxx, aux->maxy,
   671         -			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
   672         -			   &image, &image_size))
          672  +			   aux->srid, aux->outbuf, aux->format_id,
          673  +			   aux->quality, &image, &image_size))
   673    674   			{
   674    675   			    aux->outbuf = NULL;
   675    676   			    goto error;
   676    677   			}
   677    678   		  }
   678    679   		aux->outbuf = NULL;
   679    680   	    }
................................................................................
   693    694   			}
   694    695   		  }
   695    696   		else
   696    697   		  {
   697    698   		      if (!get_payload_from_rgb_opaque
   698    699   			  (aux->base_width, aux->base_height, aux->sqlite,
   699    700   			   aux->minx, aux->miny, aux->maxx, aux->maxy,
   700         -			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
   701         -			   &image, &image_size))
          701  +			   aux->srid, aux->outbuf, aux->format_id,
          702  +			   aux->quality, &image, &image_size))
   702    703   			{
   703    704   			    aux->outbuf = NULL;
   704    705   			    goto error;
   705    706   			}
   706    707   		  }
   707    708   		aux->outbuf = NULL;
   708    709   	    }
................................................................................
   739    740   			    goto error;
   740    741   			}
   741    742   		  }
   742    743   		aux->outbuf = NULL;
   743    744   	    }
   744    745   	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
   745    746   	    {
   746         -		/* Monochrome - upsampled */
          747  +		/* Palette - upsampled */
   747    748   		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
   748    749   		  {
   749    750   		      if (!get_rgba_from_palette_transparent
   750    751   			  (aux->base_width, aux->base_height, aux->outbuf,
   751    752   			   aux->palette, rgba, aux->bg_red, aux->bg_green,
   752    753   			   aux->bg_blue))
   753    754   			{
................................................................................
   769    770   	    }
   770    771   	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
   771    772   	    {
   772    773   		/* Grayscale */
   773    774   		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
   774    775   		  {
   775    776   		      if (!get_rgba_from_grayscale_transparent
   776         -			  (aux->base_width, aux->base_height, aux->outbuf, rgba,
   777         -			   aux->bg_red))
          777  +			  (aux->base_width, aux->base_height, aux->outbuf,
          778  +			   rgba, aux->bg_red))
   778    779   			{
   779    780   			    aux->outbuf = NULL;
   780    781   			    goto error;
   781    782   			}
   782    783   		  }
   783    784   		else
   784    785   		  {
................................................................................
   794    795   	    }
   795    796   	  else
   796    797   	    {
   797    798   		/* RGB */
   798    799   		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
   799    800   		  {
   800    801   		      if (!get_rgba_from_rgb_transparent
   801         -			  (aux->base_width, aux->base_height, aux->outbuf, rgba,
   802         -			   aux->bg_red, aux->bg_green, aux->bg_blue))
          802  +			  (aux->base_width, aux->base_height, aux->outbuf,
          803  +			   rgba, aux->bg_red, aux->bg_green, aux->bg_blue))
   803    804   			{
   804    805   			    aux->outbuf = NULL;
   805    806   			    goto error;
   806    807   			}
   807    808   		  }
   808    809   		else
   809    810   		  {
................................................................................
   838    839   	    {
   839    840   		/* Grayscale or Monochrome upsampled */
   840    841   		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
   841    842   		  {
   842    843   		      if (alpha == NULL)
   843    844   			  goto error;
   844    845   		      if (!get_payload_from_gray_rgba_transparent
   845         -			  (aux->width, aux->height, rgb, alpha, aux->format_id,
   846         -			   aux->quality, &image, &image_size, aux->opacity))
          846  +			  (aux->width, aux->height, rgb, alpha,
          847  +			   aux->format_id, aux->quality, &image, &image_size,
          848  +			   aux->opacity))
   847    849   			  goto error;
   848    850   		  }
   849    851   		else
   850    852   		  {
   851    853   		      if (alpha != NULL)
   852    854   			  free (alpha);
   853    855   		      alpha = NULL;
................................................................................
   862    864   	    {
   863    865   		/* RGB */
   864    866   		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
   865    867   		  {
   866    868   		      if (alpha == NULL)
   867    869   			  goto error;
   868    870   		      if (!get_payload_from_rgb_rgba_transparent
   869         -			  (aux->width, aux->height, rgb, alpha, aux->format_id,
   870         -			   aux->quality, &image, &image_size, aux->opacity, 0))
          871  +			  (aux->width, aux->height, rgb, alpha,
          872  +			   aux->format_id, aux->quality, &image, &image_size,
          873  +			   aux->opacity, 0))
   871    874   			  goto error;
   872    875   		  }
   873    876   		else
   874    877   		  {
   875    878   		      if (alpha != NULL)
   876    879   			  free (alpha);
   877    880   		      alpha = NULL;
................................................................................
   951    954   	free (rgb);
   952    955       if (alpha != NULL)
   953    956   	free (alpha);
   954    957       return 0;
   955    958   }
   956    959   
   957    960   static int
   958         -aux_shaded_relief_mask (struct aux_renderer *aux, double relief_factor,
   959         -			unsigned char **shaded_relief)
          961  +aux_shaded_relief_mask (struct aux_renderer *aux,
          962  +			int by_section, sqlite3_int64 section_id,
          963  +			double relief_factor, unsigned char **shaded_relief)
   960    964   {
   961    965   /* attempting to create a Shaded Relief brightness-only mask */
   962    966       rl2GraphicsBitmapPtr base_img = NULL;
   963    967       rl2GraphicsContextPtr ctx = NULL;
   964    968       float *shr_mask;
   965    969       int shr_size;
   966    970       const char *coverage;
................................................................................
   977    981       *shaded_relief = NULL;
   978    982       coverage = rl2_get_coverage_name (aux->coverage);
   979    983       if (coverage == NULL)
   980    984   	return 0;
   981    985       scale_factor = rl2_get_shaded_relief_scale_factor (aux->sqlite, coverage);
   982    986   
   983    987       if (rl2_build_shaded_relief_mask
   984         -	(aux->sqlite, aux->max_threads, aux->coverage, relief_factor,
   985         -	 scale_factor, aux->base_width, aux->base_height, aux->minx, aux->miny,
   986         -	 aux->maxx, aux->maxy, aux->xx_res, aux->yy_res, &shr_mask,
   987         -	 &shr_size) != RL2_OK)
          988  +	(aux->sqlite, aux->max_threads, aux->coverage, by_section, section_id,
          989  +	 relief_factor, scale_factor, aux->base_width, aux->base_height,
          990  +	 aux->minx, aux->miny, aux->maxx, aux->maxy, aux->xx_res, aux->yy_res,
          991  +	 &shr_mask, &shr_size) != RL2_OK)
   988    992   	return 0;
   989    993   
   990    994   /* allocating the RGBA buffer */
   991    995       rgba = malloc (aux->base_width * aux->base_height * 4);
   992    996       if (rgba == NULL)
   993    997   	return 0;
   994    998   
................................................................................
  1325   1329   	  aux.out_pixel = out_pixel;
  1326   1330   	  if (is_shaded_relief)
  1327   1331   	    {
  1328   1332   		/* requesting a shaded relief mask */
  1329   1333   		if (shaded_relief_mask != NULL)
  1330   1334   		    free (shaded_relief_mask);
  1331   1335   		if (!aux_shaded_relief_mask
  1332         -		    (&aux, symbolizer->reliefFactor, &shaded_relief_mask))
         1336  +		    (&aux, 0, 0, symbolizer->reliefFactor, &shaded_relief_mask))
  1333   1337   		    goto error;
  1334   1338   	    }
  1335   1339   	  else
  1336   1340   	    {
  1337   1341   		/* rendering an image */
  1338   1342   		if (!aux_render_composed_image (&aux, rgba))
  1339   1343   		    goto error;
................................................................................
  1534   1538   RL2_DECLARE int
  1535   1539   rl2_get_raw_raster_data_mixed_resolutions (sqlite3 * handle, int max_threads,
  1536   1540   					   rl2CoveragePtr cvg,
  1537   1541   					   unsigned int width,
  1538   1542   					   unsigned int height, double minx,
  1539   1543   					   double miny, double maxx,
  1540   1544   					   double maxy, double x_res,
  1541         -					   double y_res, unsigned char **buffer,
         1545  +					   double y_res,
         1546  +					   unsigned char **buffer,
  1542   1547   					   int *buf_size,
  1543   1548   					   rl2PalettePtr * palette,
  1544   1549   					   unsigned char *out_pixel,
  1545   1550   					   unsigned char bg_red,
  1546   1551   					   unsigned char bg_green,
  1547   1552   					   unsigned char bg_blue,
  1548   1553   					   rl2RasterSymbolizerPtr style,
................................................................................
  1672   1677   		double xx_res;
  1673   1678   		double yy_res;
  1674   1679   		int level_id;
  1675   1680   		int scale;
  1676   1681   		int xscale;
  1677   1682   		unsigned int w;
  1678   1683   		unsigned int h;
         1684  +		unsigned int w2;
         1685  +		unsigned int h2;
  1679   1686   		int base_x;
  1680   1687   		int base_y;
  1681   1688   		unsigned char *bufpix = NULL;
  1682   1689   		int bufpix_size;
  1683   1690   		double img_res_x = (maxx - minx) / (double) width;
  1684   1691   		double img_res_y = (maxy - miny) / (double) height;
  1685   1692   		double mnx = minx;
  1686   1693   		double mny = miny;
  1687   1694   		double mxx = maxx;
  1688   1695   		double mxy = maxy;
  1689         -		if (section_id > 3)
  1690         -		    continue;
  1691   1696   		/* normalizing the visible portion of the Section */
  1692   1697   		if (mnx < section_minx)
  1693   1698   		    mnx = section_minx;
  1694   1699   		if (mny < section_miny)
  1695   1700   		    mny = section_miny;
  1696   1701   		if (mxx > section_maxx)
  1697   1702   		    mxx = section_maxx;
................................................................................
  1706   1711   		if (((double) w * xx_res) < (mxx - mnx))
  1707   1712   		    w++;
  1708   1713   		h = (unsigned int) ((mxy - mny) / yy_res);
  1709   1714   		if (((double) h * yy_res) < (mxy - mny))
  1710   1715   		    h++;
  1711   1716   		base_x = (int) ((mnx - minx) / img_res_x);
  1712   1717   		base_y = (int) ((maxy - mxy) / img_res_y);
         1718  +
  1713   1719   		if (rl2_get_raw_raster_data_common
  1714   1720   		    (handle, max_threads, cvg, 1, section_id, w, h, mnx, mny,
  1715   1721   		     mxx, mxy, xx_res, yy_res, &bufpix, &bufpix_size, palette,
  1716   1722   		     *out_pixel, no_data, xstyle, stats) != RL2_OK)
  1717   1723   		    goto error;
         1724  +
         1725  +		w2 = (unsigned int) ((mxx - mnx) / img_res_x);
         1726  +		if (((double) w2 * img_res_x) < (mxx - mnx))
         1727  +		    w2++;
         1728  +		h2 = (unsigned int) ((mxy - mny) / img_res_y);
         1729  +		if (((double) h2 * img_res_y) < (mxy - mny))
         1730  +		    h2++;
         1731  +		if (w == w2 && h == h2)
         1732  +		  {
         1733  +		      /* already rescaled */
         1734  +		  }
         1735  +		else
         1736  +		  {
         1737  +		      /* rescaling the pixbuf */
         1738  +		      unsigned char *rescaled = NULL;
         1739  +		      int pix_sz = 1;
         1740  +		      if (*out_pixel == RL2_PIXEL_RGB)
         1741  +			  pix_sz = 3;
         1742  +		      rescaled = malloc (pix_sz * w2 * h2);
         1743  +		      if (rescaled == NULL)
         1744  +			{
         1745  +			    fprintf (stderr,
         1746  +				     "rl2_get_raw_raster_data_mixed_resolutions: Insufficient Memory !!!\n");
         1747  +			    goto error;
         1748  +			}
         1749  +		      if (!rl2_rescale_pixbuf
         1750  +			  (bufpix, w, h, *out_pixel, rescaled, w2, h2))
         1751  +			  goto error;
         1752  +		      free (bufpix);
         1753  +		      bufpix = rescaled;
         1754  +		  }
         1755  +
  1718   1756   		if (*out_pixel == RL2_PIXEL_RGB)
  1719         -		    do_copy_rgb (outbuf, bufpix, width, height, w, h, base_x,
         1757  +		    do_copy_rgb (outbuf, bufpix, width, height, w2, h2, base_x,
  1720   1758   				 base_y, bg_red, bg_green, bg_blue);
  1721   1759   		else
  1722         -		    do_copy_gray (outbuf, bufpix, width, height, w, h, base_x,
         1760  +		    do_copy_gray (outbuf, bufpix, width, height, w2, h2, base_x,
  1723   1761   				  base_y, bg_red);
  1724   1762   		free (bufpix);
  1725   1763   	    }
  1726   1764   	  else
  1727   1765   	    {
  1728   1766   		fprintf (stderr, "SQL error: %s\n%s\n", sql,
  1729   1767   			 sqlite3_errmsg (handle));
................................................................................
  1745   1783       if (no_data != NULL)
  1746   1784   	rl2_destroy_pixel (no_data);
  1747   1785       if (outbuf != NULL)
  1748   1786   	free (outbuf);
  1749   1787       return RL2_ERROR;
  1750   1788   }
  1751   1789   
  1752         -static rl2GraphicsPatternPtr
  1753         -load_external_graphic_from_dbms (sqlite3 * handle, rl2PrivGraphicPtr graphic)
  1754         -{
  1755         -/* attempting to load an External Graphic from the DBMS */
  1756         -    int ret;
  1757         -    sqlite3_stmt *stmt = NULL;
  1758         -    const char *sql;
  1759         -    const char *xlink_href = NULL;
  1760         -    rl2GraphicsPatternPtr pattern = NULL;
  1761         -    rl2PrivGraphicItemPtr item;
  1762         -
  1763         -    if (graphic == NULL)
  1764         -	return NULL;
  1765         -    /* searching for an xlink_href pseudo-URL */
  1766         -    item = graphic->first;
  1767         -    while (item != NULL)
  1768         -      {
  1769         -	  if (item->type == RL2_EXTERNAL_GRAPHIC && item->item != NULL)
  1770         -	    {
  1771         -		rl2PrivExternalGraphicPtr ext =
  1772         -		    (rl2PrivExternalGraphicPtr) (item->item);
  1773         -		if (ext->xlink_href != NULL)
  1774         -		  {
  1775         -		      xlink_href = ext->xlink_href;
  1776         -		      break;
  1777         -		  }
  1778         -	    }
  1779         -	  item = item->next;
  1780         -      }
  1781         -    if (xlink_href == NULL)
  1782         -	return NULL;
  1783         -
  1784         -    sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics "
  1785         -	"WHERE xlink_href = ?";
  1786         -    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  1787         -    if (ret != SQLITE_OK)
  1788         -	return NULL;
  1789         -
  1790         -    sqlite3_reset (stmt);
  1791         -    sqlite3_clear_bindings (stmt);
  1792         -    sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC);
  1793         -    while (1)
  1794         -      {
  1795         -	  /* scrolling the result set rows */
  1796         -	  ret = sqlite3_step (stmt);
  1797         -	  if (ret == SQLITE_DONE)
  1798         -	      break;		/* end of result set */
  1799         -	  if (ret == SQLITE_ROW)
  1800         -	    {
  1801         -		rl2RasterPtr raster = NULL;
  1802         -		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB
  1803         -		    && sqlite3_column_type (stmt, 1) == SQLITE_TEXT)
  1804         -		  {
  1805         -		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
  1806         -		      int blob_sz = sqlite3_column_bytes (stmt, 0);
  1807         -		      const char *mime_type =
  1808         -			  (const char *) sqlite3_column_text (stmt, 1);
  1809         -		      if (strcmp (mime_type, "image/gif") == 0)
  1810         -			  raster = rl2_raster_from_gif (blob, blob_sz);
  1811         -		      if (strcmp (mime_type, "image/png") == 0)
  1812         -			  raster = rl2_raster_from_png (blob, blob_sz, 1);
  1813         -		      if (strcmp (mime_type, "image/jpeg") == 0)
  1814         -			  raster = rl2_raster_from_jpeg (blob, blob_sz);
  1815         -		      if (strcmp (mime_type, "image/tiff") == 0)
  1816         -			  raster = rl2_raster_from_tiff (blob, blob_sz);
  1817         -		  }
  1818         -		if (raster != NULL)
  1819         -		  {
  1820         -		      unsigned char *rgba;
  1821         -		      int rgba_sz;
  1822         -		      unsigned int width;
  1823         -		      unsigned int height;
  1824         -		      if (rl2_get_raster_size (raster, &width, &height) !=
  1825         -			  RL2_OK)
  1826         -			{
  1827         -			    rl2_destroy_raster (raster);
  1828         -			    goto error;
  1829         -			}
  1830         -		      if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) !=
  1831         -			  RL2_OK)
  1832         -			{
  1833         -			    rl2_destroy_raster (raster);
  1834         -			    goto error;
  1835         -			}
  1836         -		      pattern =
  1837         -			  rl2_graph_create_pattern (rgba, width, height, 0);
  1838         -		      rl2_destroy_raster (raster);
  1839         -		  }
  1840         -	    }
  1841         -	  else
  1842         -	    {
  1843         -		fprintf (stderr, "SQL error: %s\n%s\n", sql,
  1844         -			 sqlite3_errmsg (handle));
  1845         -		goto error;
  1846         -	    }
  1847         -      }
  1848         -    return pattern;
  1849         -
  1850         -  error:
  1851         -    if (stmt != NULL)
  1852         -	sqlite3_finalize (stmt);
  1853         -    return NULL;
  1854         -}
  1855         -
  1856         -static rl2GraphicsBitmapPtr
  1857         -load_external_bitmap_from_dbms (sqlite3 * handle, const char *xlink_href)
  1858         -{
  1859         -/* attempting to load an External Graphic from the DBMS */
  1860         -    int ret;
  1861         -    sqlite3_stmt *stmt = NULL;
  1862         -    const char *sql;
  1863         -    rl2GraphicsBitmapPtr bitmap = NULL;
  1864         -
  1865         -    if (xlink_href == NULL)
  1866         -	return NULL;
  1867         -
  1868         -    sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics "
  1869         -	"WHERE xlink_href = ?";
  1870         -    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  1871         -    if (ret != SQLITE_OK)
  1872         -	return NULL;
  1873         -
  1874         -    sqlite3_reset (stmt);
  1875         -    sqlite3_clear_bindings (stmt);
  1876         -    sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC);
  1877         -    while (1)
  1878         -      {
  1879         -	  /* scrolling the result set rows */
  1880         -	  ret = sqlite3_step (stmt);
  1881         -	  if (ret == SQLITE_DONE)
  1882         -	      break;		/* end of result set */
  1883         -	  if (ret == SQLITE_ROW)
  1884         -	    {
  1885         -		rl2RasterPtr raster = NULL;
  1886         -		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB
  1887         -		    && sqlite3_column_type (stmt, 1) == SQLITE_TEXT)
  1888         -		  {
  1889         -		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
  1890         -		      int blob_sz = sqlite3_column_bytes (stmt, 0);
  1891         -		      const char *mime_type =
  1892         -			  (const char *) sqlite3_column_text (stmt, 1);
  1893         -		      if (strcmp (mime_type, "image/gif") == 0)
  1894         -			  raster = rl2_raster_from_gif (blob, blob_sz);
  1895         -		      if (strcmp (mime_type, "image/png") == 0)
  1896         -			  raster = rl2_raster_from_png (blob, blob_sz, 1);
  1897         -		      if (strcmp (mime_type, "image/jpeg") == 0)
  1898         -			  raster = rl2_raster_from_jpeg (blob, blob_sz);
  1899         -		      if (strcmp (mime_type, "image/tiff") == 0)
  1900         -			  raster = rl2_raster_from_tiff (blob, blob_sz);
  1901         -		  }
  1902         -		if (raster != NULL)
  1903         -		  {
  1904         -		      unsigned char *rgba;
  1905         -		      int rgba_sz;
  1906         -		      unsigned int width;
  1907         -		      unsigned int height;
  1908         -		      if (rl2_get_raster_size (raster, &width, &height) !=
  1909         -			  RL2_OK)
  1910         -			{
  1911         -			    rl2_destroy_raster (raster);
  1912         -			    goto error;
  1913         -			}
  1914         -		      if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) !=
  1915         -			  RL2_OK)
  1916         -			{
  1917         -			    rl2_destroy_raster (raster);
  1918         -			    goto error;
  1919         -			}
  1920         -		      bitmap = rl2_graph_create_bitmap (rgba, width, height);
  1921         -		      rl2_destroy_raster (raster);
  1922         -		  }
  1923         -	    }
  1924         -	  else
  1925         -	    {
  1926         -		fprintf (stderr, "SQL error: %s\n%s\n", sql,
  1927         -			 sqlite3_errmsg (handle));
  1928         -		goto error;
  1929         -	    }
  1930         -      }
  1931         -    return bitmap;
  1932         -
  1933         -  error:
  1934         -    if (stmt != NULL)
  1935         -	sqlite3_finalize (stmt);
  1936         -    return NULL;
         1790  +static int
         1791  +point_bbox_matches (rl2PointPtr point, double minx, double miny, double maxx,
         1792  +		    double maxy)
         1793  +{
         1794  +/* checks if the Point is visible */
         1795  +    if (minx > point->x)
         1796  +	return 0;
         1797  +    if (maxx < point->x)
         1798  +	return 0;
         1799  +    if (miny > point->y)
         1800  +	return 0;
         1801  +    if (maxy < point->y)
         1802  +	return 0;
         1803  +    return 1;
  1937   1804   }
  1938   1805   
  1939   1806   static void
  1940   1807   draw_points (rl2GraphicsContextPtr ctx, sqlite3 * handle,
  1941   1808   	     rl2PrivVectorSymbolizerPtr sym, int height, double minx,
  1942         -	     double miny, double x_res, double y_res, rl2GeometryPtr geom)
         1809  +	     double miny, double maxx, double maxy, double x_res,
         1810  +	     double y_res, rl2GeometryPtr geom)
  1943   1811   {
  1944   1812   /* drawing Point-type features */
  1945   1813       rl2PrivVectorSymbolizerItemPtr item;
  1946   1814       rl2PointPtr point;
  1947   1815   
  1948   1816       item = sym->first;
  1949   1817       while (item != NULL)
................................................................................
  1968   1836   		      unsigned char well_known_type;
  1969   1837   		      int fill = 0;
  1970   1838   		      int stroke = 0;
  1971   1839   		      int pen_cap;
  1972   1840   		      int pen_join;
  1973   1841   		      double opacity;
  1974   1842   		      unsigned char norm_opacity;
  1975         -		      rl2GraphicsBitmapPtr pattern = NULL;
         1843  +		      rl2GraphicsPatternPtr pattern = NULL;
  1976   1844   		      rl2GraphicsPatternPtr pattern_fill = NULL;
  1977   1845   		      rl2GraphicsPatternPtr pattern_stroke = NULL;
  1978   1846   
  1979   1847   		      if (graphic->type == RL2_MARK_GRAPHIC)
  1980   1848   			{
  1981   1849   			    rl2PrivMarkPtr mark =
  1982   1850   				(rl2PrivMarkPtr) (graphic->item);
................................................................................
  1985   1853   				  well_known_type = mark->well_known_type;
  1986   1854   				  is_mark = 1;
  1987   1855   				  if (mark->fill != NULL)
  1988   1856   				    {
  1989   1857   					if (mark->fill->graphic != NULL)
  1990   1858   					  {
  1991   1859   					      /* external Graphic fill */
  1992         -					      pattern_fill =
  1993         -						  load_external_graphic_from_dbms
  1994         -						  (handle, mark->fill->graphic);
         1860  +					      const char *xlink_href = NULL;
         1861  +					      int recolor = 0;
         1862  +					      unsigned char red;
         1863  +					      unsigned char green;
         1864  +					      unsigned char blue;
         1865  +					      pattern_fill = NULL;
         1866  +					      if (mark->fill->graphic->first !=
         1867  +						  NULL)
         1868  +						{
         1869  +						    if (mark->fill->
         1870  +							graphic->first->type ==
         1871  +							RL2_EXTERNAL_GRAPHIC)
         1872  +						      {
         1873  +							  rl2PrivExternalGraphicPtr
         1874  +							      ext =
         1875  +							      (rl2PrivExternalGraphicPtr)
         1876  +							      (mark->
         1877  +							       fill->graphic->
         1878  +							       first->item);
         1879  +							  xlink_href =
         1880  +							      ext->xlink_href;
         1881  +							  if (ext->first !=
         1882  +							      NULL)
         1883  +							    {
         1884  +								recolor = 1;
         1885  +								red =
         1886  +								    ext->
         1887  +								    first->red;
         1888  +								green =
         1889  +								    ext->
         1890  +								    first->green;
         1891  +								blue =
         1892  +								    ext->
         1893  +								    first->blue;
         1894  +							    }
         1895  +						      }
         1896  +						}
         1897  +					      if (xlink_href != NULL)
         1898  +						  pattern_fill =
         1899  +						      rl2_create_pattern_from_external_graphic
         1900  +						      (handle, xlink_href, 1);
  1995   1901   					      if (pattern_fill != NULL)
  1996   1902   						{
         1903  +						    if (recolor)
         1904  +						      {
         1905  +							  /* attempting to recolor the External Graphic resource */
         1906  +							  rl2_graph_pattern_recolor
         1907  +							      (pattern_fill,
         1908  +							       red, green,
         1909  +							       blue);
         1910  +						      }
         1911  +						    if (mark->fill->opacity <=
         1912  +							0.0)
         1913  +							norm_opacity = 0;
         1914  +						    else if (mark->
         1915  +							     fill->opacity >=
         1916  +							     1.0)
         1917  +							norm_opacity = 255;
         1918  +						    else
         1919  +						      {
         1920  +							  opacity =
         1921  +							      255.0 *
         1922  +							      mark->
         1923  +							      fill->opacity;
         1924  +							  if (opacity <= 0.0)
         1925  +							      norm_opacity = 0;
         1926  +							  else if (opacity >=
         1927  +								   255.0)
         1928  +							      norm_opacity =
         1929  +								  255;
         1930  +							  else
         1931  +							      norm_opacity =
         1932  +								  opacity;
         1933  +						      }
         1934  +						    if (norm_opacity < 1.0)
         1935  +							rl2_graph_pattern_transparency
         1936  +							    (pattern_fill,
         1937  +							     norm_opacity);
  1997   1938   						    rl2_graph_set_pattern_brush
  1998   1939   							(ctx, pattern_fill);
  1999         -						    fill = 1;
         1940  +						}
         1941  +					      else
         1942  +						{
         1943  +						    /* invalid Pattern: defaulting to a Gray brush */
         1944  +						    rl2_graph_set_brush (ctx,
         1945  +									 128,
         1946  +									 128,
         1947  +									 128,
         1948  +									 255);
  2000   1949   						}
         1950  +					      fill = 1;
  2001   1951   					  }
  2002   1952   					else
  2003   1953   					  {
  2004   1954   					      /* solid RGB fill */
  2005   1955   					      if (gr->opacity <= 0.0)
  2006   1956   						  norm_opacity = 0;
  2007   1957   					      else if (gr->opacity >= 1.0)
................................................................................
  2028   1978   					      fill = 1;
  2029   1979   					  }
  2030   1980   				    }
  2031   1981   				  if (mark->stroke != NULL)
  2032   1982   				    {
  2033   1983   					if (mark->stroke->graphic != NULL)
  2034   1984   					  {
  2035         -					      /* external Graphic stroke */
  2036         -					      pattern_stroke =
  2037         -						  load_external_graphic_from_dbms
  2038         -						  (handle,
  2039         -						   mark->stroke->graphic);
  2040         -					      if (pattern_stroke != NULL)
         1985  +					      const char *xlink_href = NULL;
         1986  +					      int recolor = 0;
         1987  +					      unsigned char red;
         1988  +					      unsigned char green;
         1989  +					      unsigned char blue;
         1990  +					      pattern_stroke = NULL;
         1991  +					      if (mark->stroke->
         1992  +						  graphic->first != NULL)
  2041   1993   						{
  2042         -						    switch (mark->
  2043         -							    stroke->linecap)
         1994  +						    if (mark->stroke->
         1995  +							graphic->first->type ==
         1996  +							RL2_EXTERNAL_GRAPHIC)
  2044   1997   						      {
  2045         -						      case RL2_STROKE_LINECAP_ROUND:
  2046         -							  pen_cap =
  2047         -							      RL2_PEN_CAP_ROUND;
  2048         -							  break;
  2049         -						      case RL2_STROKE_LINECAP_SQUARE:
  2050         -							  pen_cap =
  2051         -							      RL2_PEN_CAP_SQUARE;
  2052         -							  break;
  2053         -						      default:
  2054         -							  pen_cap =
  2055         -							      RL2_PEN_CAP_BUTT;
  2056         -							  break;
  2057         -						      };
  2058         -						    switch (mark->
  2059         -							    stroke->linejoin)
         1998  +							  rl2PrivExternalGraphicPtr
         1999  +							      ext =
         2000  +							      (rl2PrivExternalGraphicPtr)
         2001  +							      (mark->
         2002  +							       stroke->graphic->
         2003  +							       first->item);
         2004  +							  xlink_href =
         2005  +							      ext->xlink_href;
         2006  +							  if (ext->first !=
         2007  +							      NULL)
         2008  +							    {
         2009  +								recolor = 1;
         2010  +								red =
         2011  +								    ext->
         2012  +								    first->red;
         2013  +								green =
         2014  +								    ext->
         2015  +								    first->green;
         2016  +								blue =
         2017  +								    ext->
         2018  +								    first->blue;
         2019  +							    }
         2020  +						      }
         2021  +						}
         2022  +					      if (xlink_href != NULL)
         2023  +						  pattern_stroke =
         2024  +						      rl2_create_pattern_from_external_graphic
         2025  +						      (handle, xlink_href, 1);
         2026  +					      if (pattern != NULL)
         2027  +						{
         2028  +						    if (recolor)
  2060   2029   						      {
  2061         -						      case RL2_STROKE_LINEJOIN_BEVEL:
  2062         -							  pen_join =
  2063         -							      RL2_PEN_JOIN_BEVEL;
  2064         -							  break;
  2065         -						      case RL2_STROKE_LINEJOIN_ROUND:
  2066         -							  pen_join =
  2067         -							      RL2_PEN_JOIN_ROUND;
  2068         -							  break;
  2069         -						      default:
  2070         -							  pen_join =
  2071         -							      RL2_PEN_JOIN_MITER;
  2072         -							  break;
  2073         -						      };
  2074         -						    if (mark->
  2075         -							stroke->dash_count > 0
  2076         -							&& mark->
  2077         -							stroke->dash_list !=
  2078         -							NULL)
  2079         -							rl2_graph_set_pattern_dashed_pen
  2080         -							    (ctx,
  2081         -							     pattern_stroke,
  2082         -							     mark->
  2083         -							     stroke->width,
  2084         -							     pen_cap, pen_join,
  2085         -							     mark->
  2086         -							     stroke->dash_count,
  2087         -							     mark->
  2088         -							     stroke->dash_list,
  2089         -							     mark->
  2090         -							     stroke->dash_offset);
         2030  +							  /* attempting to recolor the External Graphic resource */
         2031  +							  rl2_graph_pattern_recolor
         2032  +							      (pattern_stroke,
         2033  +							       red, green,
         2034  +							       blue);
         2035  +						      }
         2036  +						    if (mark->stroke->opacity <=
         2037  +							0.0)
         2038  +							norm_opacity = 0;
         2039  +						    else if (mark->
         2040  +							     stroke->opacity >=
         2041  +							     1.0)
         2042  +							norm_opacity = 255;
  2091   2043   						    else
  2092         -							rl2_graph_set_pattern_solid_pen
  2093         -							    (ctx,
  2094         -							     pattern_stroke,
  2095         -							     mark->
  2096         -							     stroke->width,
  2097         -							     pen_cap, pen_join);
  2098         -						    stroke = 1;
         2044  +						      {
         2045  +							  opacity =
         2046  +							      255.0 *
         2047  +							      mark->
         2048  +							      stroke->opacity;
         2049  +							  if (opacity <= 0.0)
         2050  +							      norm_opacity = 0;
         2051  +							  else if (opacity >=
         2052  +								   255.0)
         2053  +							      norm_opacity =
         2054  +								  255;
         2055  +							  else
         2056  +							      norm_opacity =
         2057  +								  opacity;
         2058  +						      }
         2059  +						    if (norm_opacity < 1.0)
         2060  +							rl2_graph_pattern_transparency
         2061  +							    (pattern_stroke,
         2062  +							     norm_opacity);
         2063  +						    if (pattern_stroke != NULL)
         2064  +						      {
         2065  +							  switch
         2066  +							      (mark->
         2067  +							       stroke->linecap)
         2068  +							    {
         2069  +							    case RL2_STROKE_LINECAP_ROUND:
         2070  +								pen_cap =
         2071  +								    RL2_PEN_CAP_ROUND;
         2072  +								break;
         2073  +							    case RL2_STROKE_LINECAP_SQUARE:
         2074  +								pen_cap =
         2075  +								    RL2_PEN_CAP_SQUARE;
         2076  +								break;
         2077  +							    default:
         2078  +								pen_cap =
         2079  +								    RL2_PEN_CAP_BUTT;
         2080  +								break;
         2081  +							    };
         2082  +							  switch
         2083  +							      (mark->
         2084  +							       stroke->linejoin)
         2085  +							    {
         2086  +							    case RL2_STROKE_LINEJOIN_BEVEL:
         2087  +								pen_join =
         2088  +								    RL2_PEN_JOIN_BEVEL;
         2089  +								break;
         2090  +							    case RL2_STROKE_LINEJOIN_ROUND:
         2091  +								pen_join =
         2092  +								    RL2_PEN_JOIN_ROUND;
         2093  +								break;
         2094  +							    default:
         2095  +								pen_join =
         2096  +								    RL2_PEN_JOIN_MITER;
         2097  +								break;
         2098  +							    };
         2099  +							  if (mark->
         2100  +							      stroke->dash_count
         2101  +							      > 0
         2102  +							      && mark->
         2103  +							      stroke->dash_list
         2104  +							      != NULL)
         2105  +							      rl2_graph_set_pattern_dashed_pen
         2106  +								  (ctx,
         2107  +								   pattern_stroke,
         2108  +								   mark->
         2109  +								   stroke->width,
         2110  +								   pen_cap,
         2111  +								   pen_join,
         2112  +								   mark->
         2113  +								   stroke->dash_count,
         2114  +								   mark->
         2115  +								   stroke->dash_list,
         2116  +								   mark->
         2117  +								   stroke->dash_offset);
         2118  +							  else
         2119  +							      rl2_graph_set_pattern_solid_pen
         2120  +								  (ctx,
         2121  +								   pattern_stroke,
         2122  +								   mark->
         2123  +								   stroke->width,
         2124  +								   pen_cap,
         2125  +								   pen_join);
         2126  +							  stroke = 1;
         2127  +						      }
  2099   2128   						}
  2100   2129   					  }
  2101   2130   					else
  2102   2131   					  {
  2103   2132   					      /* solid RGB stroke */
  2104   2133   					      if (gr->opacity <= 0.0)
  2105   2134   						  norm_opacity = 0;
................................................................................
  2151   2180   									    mark->stroke->red,
  2152   2181   									    mark->stroke->green,
  2153   2182   									    mark->stroke->blue,
  2154   2183   									    norm_opacity,
  2155   2184   									    mark->stroke->width,
  2156   2185   									    pen_cap,
  2157   2186   									    pen_join,
  2158         -									    mark->stroke->dash_count,
  2159         -									    mark->stroke->dash_list,
  2160         -									    mark->stroke->dash_offset);
         2187  +									    mark->
         2188  +									    stroke->dash_count,
         2189  +									    mark->
         2190  +									    stroke->dash_list,
         2191  +									    mark->
         2192  +									    stroke->dash_offset);
  2161   2193   					      else
  2162         -						  rl2_graph_set_solid_pen (ctx,
  2163         -									   mark->stroke->red,
  2164         -									   mark->stroke->green,
  2165         -									   mark->stroke->blue,
  2166         -									   norm_opacity,
  2167         -									   mark->stroke->width,
  2168         -									   pen_cap,
  2169         -									   pen_join);
         2194  +						  rl2_graph_set_solid_pen
         2195  +						      (ctx, mark->stroke->red,
         2196  +						       mark->stroke->green,
         2197  +						       mark->stroke->blue,
         2198  +						       norm_opacity,
         2199  +						       mark->stroke->width,
         2200  +						       pen_cap, pen_join);
  2170   2201   					      stroke = 1;
  2171   2202   					  }
  2172   2203   				    }
  2173   2204   			      }
  2174   2205   			}
  2175   2206   		      if (graphic->type == RL2_EXTERNAL_GRAPHIC)
  2176   2207   			{
  2177   2208   			    rl2PrivExternalGraphicPtr ext =
  2178   2209   				(rl2PrivExternalGraphicPtr) (graphic->item);
         2210  +			    const char *xlink_href = NULL;
         2211  +			    int recolor = 0;
         2212  +			    unsigned char red;
         2213  +			    unsigned char green;
         2214  +			    unsigned char blue;
         2215  +			    pattern = NULL;
  2179   2216   			    if (ext != NULL)
  2180   2217   			      {
  2181   2218   				  is_external = 1;
  2182         -				  pattern =
  2183         -				      load_external_bitmap_from_dbms (handle,
  2184         -								      ext->xlink_href);
         2219  +				  if (ext->xlink_href != NULL)
         2220  +				      xlink_href = ext->xlink_href;
         2221  +				  if (ext->first != NULL)
         2222  +				    {
         2223  +					recolor = 1;
         2224  +					red = ext->first->red;
         2225  +					green = ext->first->green;
         2226  +					blue = ext->first->blue;
         2227  +				    }
         2228  +				  if (xlink_href != NULL)
         2229  +				    {
         2230  +					/* first attempt: Bitmap */
         2231  +					pattern =
         2232  +					    rl2_create_pattern_from_external_graphic
         2233  +					    (handle, xlink_href, 1);
         2234  +					if (pattern == NULL)
         2235  +					  {
         2236  +					      /* second attempt: SVG */
         2237  +					      pattern =
         2238  +						  rl2_create_pattern_from_external_svg
         2239  +						  (handle, xlink_href,
         2240  +						   point_sym->graphic->size);
         2241  +					  }
         2242  +				    }
         2243  +			      }
         2244  +			    if (pattern != NULL)
         2245  +			      {
         2246  +				  if (recolor)
         2247  +				    {
         2248  +					/* attempting to recolor the External Graphic resource */
         2249  +					rl2_graph_pattern_recolor (pattern,
         2250  +								   red, green,
         2251  +								   blue);
         2252  +				    }
         2253  +				  if (point_sym->graphic->opacity <= 0.0)
         2254  +				      norm_opacity = 0;
         2255  +				  else if (point_sym->graphic->opacity >= 1.0)
         2256  +				      norm_opacity = 255;
         2257  +				  else
         2258  +				    {
         2259  +					opacity =
         2260  +					    255.0 * point_sym->graphic->opacity;
         2261  +					if (opacity <= 0.0)
         2262  +					    norm_opacity = 0;
         2263  +					else if (opacity >= 255.0)
         2264  +					    norm_opacity = 255;
         2265  +					else
         2266  +					    norm_opacity = opacity;
         2267  +				    }
         2268  +				  if (norm_opacity < 1.0)
         2269  +				      rl2_graph_pattern_transparency
         2270  +					  (pattern, norm_opacity);
         2271  +				  rl2_graph_set_pattern_brush (ctx, pattern);
         2272  +			      }
         2273  +			    else
         2274  +			      {
         2275  +				  /* invalid Pattern: defaulting to a Gray brush */
         2276  +				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
  2185   2277   			      }
  2186   2278   			}
  2187   2279   
  2188   2280   		      /* actual Point rendering */
  2189   2281   		      point = geom->first_point;
  2190   2282   		      while (point)
  2191   2283   			{
  2192   2284   			    /* drawing a POINT */
  2193         -			    double x = (point->x - minx) / x_res;
  2194         -			    double y =
  2195         -				(double) height - ((point->y - miny) / y_res);
  2196         -			    double size2 = gr->size / 2.0;
  2197         -			    double size4 = gr->size / 4.0;
  2198         -			    double size6 = gr->size / 6.0;
  2199         -			    double size13 = gr->size / 3.0;
  2200         -			    double size23 = (gr->size / 3.0) * 2.0;
  2201         -			    int i;
  2202         -			    double rads;
  2203         -			    if (size2 <= 0.0)
  2204         -				size2 = 1.0;
  2205         -			    if (size4 <= 0.0)
  2206         -				size4 = 1.0;
  2207         -			    if (size6 <= 0.0)
  2208         -				size6 = 1.0;
  2209         -			    if (size13 <= 0.0)
  2210         -				size13 = 1.0;
  2211         -			    if (size23 <= 0.0)
  2212         -				size23 = 1.0;
  2213         -			    if (is_mark)
  2214         -			      {
  2215         -				  /* drawing a well-known Mark */
  2216         -				  switch (well_known_type)
  2217         -				    {
  2218         -				    case RL2_GRAPHIC_MARK_CIRCLE:
  2219         -					rads = 0.0;
  2220         -					for (i = 0; i < 32; i++)
         2285  +			    if (point_bbox_matches
         2286  +				(point, minx, miny, maxx, maxy))
         2287  +			      {
         2288  +				  double x = (point->x - minx) / x_res;
         2289  +				  double y =
         2290  +				      (double) height -
         2291  +				      ((point->y - miny) / y_res);
         2292  +				  double size2 = gr->size / 2.0;
         2293  +				  double size4 = gr->size / 4.0;
         2294  +				  double size6 = gr->size / 6.0;
         2295  +				  double size13 = gr->size / 3.0;
         2296  +				  double size23 = (gr->size / 3.0) * 2.0;
         2297  +				  int i;
         2298  +				  double rads;
         2299  +				  if (size2 <= 0.0)
         2300  +				      size2 = 1.0;
         2301  +				  if (size4 <= 0.0)
         2302  +				      size4 = 1.0;
         2303  +				  if (size6 <= 0.0)
         2304  +				      size6 = 1.0;
         2305  +				  if (size13 <= 0.0)
         2306  +				      size13 = 1.0;
         2307  +				  if (size23 <= 0.0)
         2308  +				      size23 = 1.0;
         2309  +				  if (is_mark)
         2310  +				    {
         2311  +					/* drawing a well-known Mark */
         2312  +					switch (well_known_type)
  2221   2313   					  {
  2222         -					      double tic = 6.28318530718 / 32.0;
  2223         -					      double cx =
  2224         -						  x + (size2 * sin (rads));
  2225         -					      double cy =
  2226         -						  y + (size2 * cos (rads));
  2227         -					      if (i == 0)
  2228         -						  rl2_graph_move_to_point (ctx,
  2229         -									   cx,
  2230         -									   cy);
  2231         -					      else
  2232         -						  rl2_graph_add_line_to_path
  2233         -						      (ctx, cx, cy);
  2234         -					      rads += tic;
  2235         -					  }
  2236         -					rl2_graph_close_subpath (ctx);
  2237         -					break;
  2238         -				    case RL2_GRAPHIC_MARK_TRIANGLE:
  2239         -					rl2_graph_move_to_point (ctx, x,
  2240         -								 y - size23);
  2241         -					rl2_graph_add_line_to_path (ctx,
  2242         -								    x - size2,
  2243         -								    y + size13);
  2244         -					rl2_graph_add_line_to_path (ctx,
  2245         -								    x + size2,
  2246         -								    y + size13);
  2247         -					rl2_graph_close_subpath (ctx);
  2248         -					break;
  2249         -				    case RL2_GRAPHIC_MARK_STAR:
  2250         -					rads = 3.14159265359;
  2251         -					for (i = 0; i < 10; i++)
         2314  +					  case RL2_GRAPHIC_MARK_CIRCLE:
         2315  +					      rads = 0.0;
         2316  +					      for (i = 0; i < 32; i++)
         2317  +						{
         2318  +						    double tic =
         2319  +							6.28318530718 / 32.0;
         2320  +						    double cx =
         2321  +							x +
         2322  +							(size2 * sin (rads));
         2323  +						    double cy =
         2324  +							y +
         2325  +							(size2 * cos (rads));
         2326  +						    if (i == 0)
         2327  +							rl2_graph_move_to_point
         2328  +							    (ctx, cx, cy);
         2329  +						    else
         2330  +							rl2_graph_add_line_to_path
         2331  +							    (ctx, cx, cy);
         2332  +						    rads += tic;
         2333  +						}
         2334  +					      rl2_graph_close_subpath (ctx);
         2335  +					      break;
         2336  +					  case RL2_GRAPHIC_MARK_TRIANGLE:
         2337  +					      rl2_graph_move_to_point (ctx, x,
         2338  +								       y -
         2339  +								       size23);
         2340  +					      rl2_graph_add_line_to_path (ctx,
         2341  +									  x -
         2342  +									  size2,
         2343  +									  y +
         2344  +									  size13);
         2345  +					      rl2_graph_add_line_to_path (ctx,
         2346  +									  x +
         2347  +									  size2,
         2348  +									  y +
         2349  +									  size13);
         2350  +					      rl2_graph_close_subpath (ctx);
         2351  +					      break;
         2352  +					  case RL2_GRAPHIC_MARK_STAR:
         2353  +					      rads = 3.14159265359;
         2354  +					      for (i = 0; i < 10; i++)
         2355  +						{
         2356  +						    double tic =
         2357  +							(i % 2) ? size6 : size2;
         2358  +						    double cx =
         2359  +							x + (tic * sin (rads));
         2360  +						    double cy =
         2361  +							y + (tic * cos (rads));
         2362  +						    if (i == 0)
         2363  +							rl2_graph_move_to_point
         2364  +							    (ctx, cx, cy);
         2365  +						    else
         2366  +							rl2_graph_add_line_to_path
         2367  +							    (ctx, cx, cy);
         2368  +						    rads += 0.628318530718;
         2369  +						}
         2370  +					      rl2_graph_close_subpath (ctx);
         2371  +					      break;
         2372  +					  case RL2_GRAPHIC_MARK_CROSS:
         2373  +					      rl2_graph_move_to_point (ctx,
         2374  +								       x -
         2375  +								       size6,
         2376  +								       y -
         2377  +								       size2);
         2378  +					      rl2_graph_add_line_to_path (ctx,
         2379  +									  x +
         2380  +									  size6,
         2381  +									  y -
         2382  +									  size2);
         2383  +					      rl2_graph_add_line_to_path (ctx,
         2384  +									  x +
         2385  +									  size6,
         2386  +									  y -
         2387  +									  size6);
         2388  +					      rl2_graph_add_line_to_path (ctx,
         2389  +									  x +
         2390  +									  size2,
         2391  +									  y -
         2392  +									  size6);
         2393  +					      rl2_graph_add_line_to_path (ctx,
         2394  +									  x +
         2395  +									  size2,
         2396  +									  y +
         2397  +									  size6);
         2398  +					      rl2_graph_add_line_to_path (ctx,
         2399  +									  x +
         2400  +									  size6,
         2401  +									  y +
         2402  +									  size6);
         2403  +					      rl2_graph_add_line_to_path (ctx,
         2404  +									  x +
         2405  +									  size6,
         2406  +									  y +
         2407  +									  size2);
         2408  +					      rl2_graph_add_line_to_path (ctx,
         2409  +									  x -
         2410  +									  size6,
         2411  +									  y +
         2412  +									  size2);
         2413  +					      rl2_graph_add_line_to_path (ctx,
         2414  +									  x -
         2415  +									  size6,
         2416  +									  y +
         2417  +									  size6);
         2418  +					      rl2_graph_add_line_to_path (ctx,
         2419  +									  x -
         2420  +									  size2,
         2421  +									  y +
         2422  +									  size6);
         2423  +					      rl2_graph_add_line_to_path (ctx,
         2424  +									  x -
         2425  +									  size2,
         2426  +									  y -
         2427  +									  size6);
         2428  +					      rl2_graph_add_line_to_path (ctx,
         2429  +									  x -
         2430  +									  size6,
         2431  +									  y -
         2432  +									  size6);
         2433  +					      rl2_graph_close_subpath (ctx);
         2434  +					      break;
         2435  +					  case RL2_GRAPHIC_MARK_X:
         2436  +					      rl2_graph_move_to_point (ctx,
         2437  +								       x -
         2438  +								       size2,
         2439  +								       y -
         2440  +								       size2);
         2441  +					      rl2_graph_add_line_to_path (ctx,
         2442  +									  x -
         2443  +									  size4,
         2444  +									  y -
         2445  +									  size2);
         2446  +					      rl2_graph_add_line_to_path (ctx,
         2447  +									  x,
         2448  +									  y -
         2449  +									  size6);
         2450  +					      rl2_graph_add_line_to_path (ctx,
         2451  +									  x +
         2452  +									  size6,
         2453  +									  y -
         2454  +									  size2);
         2455  +					      rl2_graph_add_line_to_path (ctx,
         2456  +									  x +
         2457  +									  size2,
         2458  +									  y -
         2459  +									  size2);
         2460  +					      rl2_graph_add_line_to_path (ctx,
         2461  +									  x +
         2462  +									  size4,
         2463  +									  y);
         2464  +					      rl2_graph_add_line_to_path (ctx,
         2465  +									  x +
         2466  +									  size2,
         2467  +									  y +
         2468  +									  size2);
         2469  +					      rl2_graph_add_line_to_path (ctx,
         2470  +									  x +
         2471  +									  size4,
         2472  +									  y +
         2473  +									  size2);
         2474  +					      rl2_graph_add_line_to_path (ctx,
         2475  +									  x,
         2476  +									  y +
         2477  +									  size6);
         2478  +					      rl2_graph_add_line_to_path (ctx,
         2479  +									  x -
         2480  +									  size6,
         2481  +									  y +
         2482  +									  size2);
         2483  +					      rl2_graph_add_line_to_path (ctx,
         2484  +									  x -
         2485  +									  size2,
         2486  +									  y +
         2487  +									  size2);
         2488  +					      rl2_graph_add_line_to_path (ctx,
         2489  +									  x -
         2490  +									  size4,
         2491  +									  y);
         2492  +					      rl2_graph_close_subpath (ctx);
         2493  +					      break;
         2494  +					  case RL2_GRAPHIC_MARK_SQUARE:
         2495  +					  default:
         2496  +					      rl2_graph_move_to_point (ctx,
         2497  +								       x -
         2498  +								       size2,
         2499  +								       y -
         2500  +								       size2);
         2501  +					      rl2_graph_add_line_to_path (ctx,
         2502  +									  x -
         2503  +									  size2,
         2504  +									  y +
         2505  +									  size2);
         2506  +					      rl2_graph_add_line_to_path (ctx,
         2507  +									  x +
         2508  +									  size2,
         2509  +									  y +
         2510  +									  size2);
         2511  +					      rl2_graph_add_line_to_path (ctx,
         2512  +									  x +
         2513  +									  size2,
         2514  +									  y -
         2515  +									  size2);
         2516  +					      rl2_graph_close_subpath (ctx);
         2517  +					      break;
         2518  +					  };
         2519  +					if (fill)
  2252   2520   					  {
  2253         -					      double tic =
  2254         -						  (i % 2) ? size6 : size2;
  2255         -					      double cx =
  2256         -						  x + (tic * sin (rads));
  2257         -					      double cy =
  2258         -						  y + (tic * cos (rads));
  2259         -					      if (i == 0)
  2260         -						  rl2_graph_move_to_point (ctx,
  2261         -									   cx,
  2262         -									   cy);
         2521  +					      if (stroke)
         2522  +						  rl2_graph_fill_path (ctx,
         2523  +								       RL2_PRESERVE_PATH);
  2263   2524   					      else
  2264         -						  rl2_graph_add_line_to_path
  2265         -						      (ctx, cx, cy);
  2266         -					      rads += 0.628318530718;
         2525  +						  rl2_graph_fill_path (ctx,
         2526  +								       RL2_CLEAR_PATH);
  2267   2527   					  }
  2268         -					rl2_graph_close_subpath (ctx);
  2269         -					break;
  2270         -				    case RL2_GRAPHIC_MARK_CROSS:
  2271         -					rl2_graph_move_to_point (ctx, x - size6,
  2272         -								 y - size2);
  2273         -					rl2_graph_add_line_to_path (ctx,
  2274         -								    x + size6,
  2275         -								    y - size2);
  2276         -					rl2_graph_add_line_to_path (ctx,
  2277         -								    x + size6,
  2278         -								    y - size6);
  2279         -					rl2_graph_add_line_to_path (ctx,
  2280         -								    x + size2,
  2281         -								    y - size6);
  2282         -					rl2_graph_add_line_to_path (ctx,
  2283         -								    x + size2,
  2284         -								    y + size6);
  2285         -					rl2_graph_add_line_to_path (ctx,
  2286         -								    x + size6,
  2287         -								    y + size6);
  2288         -					rl2_graph_add_line_to_path (ctx,
  2289         -								    x + size6,
  2290         -								    y + size2);
  2291         -					rl2_graph_add_line_to_path (ctx,
  2292         -								    x - size6,
  2293         -								    y + size2);
  2294         -					rl2_graph_add_line_to_path (ctx,
  2295         -								    x - size6,
  2296         -								    y + size6);
  2297         -					rl2_graph_add_line_to_path (ctx,
  2298         -								    x - size2,
  2299         -								    y + size6);
  2300         -					rl2_graph_add_line_to_path (ctx,
  2301         -								    x - size2,
  2302         -								    y - size6);
  2303         -					rl2_graph_add_line_to_path (ctx,
  2304         -								    x - size6,
  2305         -								    y - size6);
  2306         -					rl2_graph_close_subpath (ctx);
  2307         -					break;
  2308         -				    case RL2_GRAPHIC_MARK_X:
  2309         -					rl2_graph_move_to_point (ctx, x - size2,
  2310         -								 y - size2);
  2311         -					rl2_graph_add_line_to_path (ctx,
  2312         -								    x - size4,
  2313         -								    y - size2);
  2314         -					rl2_graph_add_line_to_path (ctx, x,
  2315         -								    y - size6);
  2316         -					rl2_graph_add_line_to_path (ctx,
  2317         -								    x + size6,
  2318         -								    y - size2);
  2319         -					rl2_graph_add_line_to_path (ctx,
  2320         -								    x + size2,
  2321         -								    y - size2);
  2322         -					rl2_graph_add_line_to_path (ctx,
  2323         -								    x + size4,
  2324         -								    y);
  2325         -					rl2_graph_add_line_to_path (ctx,
  2326         -								    x + size2,
  2327         -								    y + size2);
  2328         -					rl2_graph_add_line_to_path (ctx,
  2329         -								    x + size4,
  2330         -								    y + size2);
  2331         -					rl2_graph_add_line_to_path (ctx, x,
  2332         -								    y + size6);
  2333         -					rl2_graph_add_line_to_path (ctx,
  2334         -								    x - size6,
  2335         -								    y + size2);
  2336         -					rl2_graph_add_line_to_path (ctx,
  2337         -								    x - size2,
  2338         -								    y + size2);
  2339         -					rl2_graph_add_line_to_path (ctx,
  2340         -								    x - size4,
  2341         -								    y);
  2342         -					rl2_graph_close_subpath (ctx);
  2343         -					break;
  2344         -				    case RL2_GRAPHIC_MARK_SQUARE:
  2345         -				    default:
  2346         -					rl2_graph_move_to_point (ctx, x - size2,
  2347         -								 y - size2);
  2348         -					rl2_graph_add_line_to_path (ctx,
  2349         -								    x - size2,
  2350         -								    y + size2);
  2351         -					rl2_graph_add_line_to_path (ctx,
  2352         -								    x + size2,
  2353         -								    y + size2);
  2354         -					rl2_graph_add_line_to_path (ctx,
  2355         -								    x + size2,
  2356         -								    y - size2);
  2357         -					rl2_graph_close_subpath (ctx);
  2358         -					break;
  2359         -				    };
  2360         -				  if (fill)
  2361         -				    {
  2362   2528   					if (stroke)
  2363         -					    rl2_graph_fill_path (ctx,
  2364         -								 RL2_PRESERVE_PATH);
  2365         -					else
  2366         -					    rl2_graph_fill_path (ctx,
  2367         -								 RL2_CLEAR_PATH);
         2529  +					    rl2_graph_stroke_path (ctx,
         2530  +								   RL2_CLEAR_PATH);
  2368   2531   				    }
  2369         -				  if (stroke)
  2370         -				      rl2_graph_stroke_path (ctx,
  2371         -							     RL2_CLEAR_PATH);
  2372         -			      }
  2373         -			    if (is_external && pattern != NULL)
  2374         -			      {
  2375         -				  /* drawing an External Graphic bitmap */
  2376         -				  rl2_graph_draw_bitmap (ctx, pattern, x, y);
         2532  +				  if (is_external && pattern != NULL)
         2533  +				    {
         2534  +					/* drawing an External Graphic pattern */
         2535  +					unsigned int width;
         2536  +					unsigned int height;
         2537  +					rl2_graph_get_pattern_size (pattern,
         2538  +								    &width,
         2539  +								    &height);
         2540  +					double out_width = width;
         2541  +					double out_height = height;
         2542  +					rl2_graph_draw_graphic_symbol (ctx,
         2543  +								       pattern,
         2544  +								       out_width,
         2545  +								       out_height,
         2546  +								       x +
         2547  +								       point_sym->graphic->displacement_x,
         2548  +								       y -
         2549  +								       point_sym->graphic->displacement_y,
         2550  +								       point_sym->graphic->rotation,
         2551  +								       point_sym->graphic->anchor_point_x,
         2552  +								       point_sym->graphic->anchor_point_y);
         2553  +				    }
  2377   2554   			      }
  2378   2555   			    point = point->next;
  2379   2556   			}
  2380   2557   
  2381   2558   		      /* releasing Patterns */
  2382   2559   		      if (pattern != NULL)
  2383         -			  rl2_graph_destroy_bitmap (pattern);
         2560  +			  rl2_graph_destroy_pattern (pattern);
  2384   2561   		      if (pattern_fill != NULL)
  2385   2562   			{
  2386   2563   			    rl2_graph_release_pattern_pen (ctx);
  2387   2564   			    rl2_graph_destroy_pattern (pattern_fill);
  2388   2565   			}
  2389   2566   		      if (pattern_stroke != NULL)
  2390   2567   			{
................................................................................
  2393   2570   			}
  2394   2571   		      graphic = graphic->next;
  2395   2572   		  }
  2396   2573   	    }
  2397   2574   	  item = item->next;
  2398   2575         }
  2399   2576   }
         2577  +
         2578  +static int
         2579  +linestring_bbox_matches (rl2LinestringPtr ring, double minx, double miny,
         2580  +			 double maxx, double maxy)
         2581  +{
         2582  +/* checks if the Linestring BBOX is visible */
         2583  +    if (minx > ring->maxx)
         2584  +	return 0;
         2585  +    if (maxx < ring->minx)
         2586  +	return 0;
         2587  +    if (miny > ring->maxy)
         2588  +	return 0;
         2589  +    if (maxy < ring->miny)
         2590  +	return 0;
         2591  +    return 1;
         2592  +}
  2400   2593   
  2401   2594   static void
  2402   2595   draw_lines (rl2GraphicsContextPtr ctx, sqlite3 * handle,
  2403   2596   	    rl2PrivVectorSymbolizerPtr sym, int height, double minx,
  2404         -	    double miny, double x_res, double y_res, rl2GeometryPtr geom)
         2597  +	    double miny, double maxx, double maxy, double x_res, double y_res,
         2598  +	    rl2GeometryPtr geom)
  2405   2599   {
  2406   2600   /* drawing Linear-type features */
  2407   2601       rl2PrivVectorSymbolizerItemPtr item;
  2408         -    int pen_cap;
  2409         -    int pen_join;
         2602  +    int pen_cap = RL2_PEN_CAP_BUTT;
         2603  +    int pen_join = RL2_PEN_JOIN_MITER;
  2410   2604       double opacity;
  2411   2605       unsigned char norm_opacity;
  2412   2606       rl2LinestringPtr line;
  2413   2607       rl2GraphicsPatternPtr pattern = NULL;
  2414   2608       rl2PrivMultiStrokePtr multi_stroke = rl2_create_multi_stroke ();
  2415   2609   
  2416   2610       item = sym->first;
................................................................................
  2421   2615   		rl2PrivLineSymbolizerPtr line_sym =
  2422   2616   		    (rl2PrivLineSymbolizerPtr) (item->symbolizer);
  2423   2617   		if (line_sym->stroke != NULL)
  2424   2618   		  {
  2425   2619   		      if (line_sym->stroke->graphic != NULL)
  2426   2620   			{
  2427   2621   			    /* external Graphic stroke */
  2428         -			    pattern = load_external_graphic_from_dbms (handle,
  2429         -								       line_sym->stroke->graphic);
         2622  +			    const char *xlink_href = NULL;
         2623  +			    int recolor = 0;
         2624  +			    unsigned char red;
         2625  +			    unsigned char green;
         2626  +			    unsigned char blue;
         2627  +			    pattern = NULL;
         2628  +			    if (line_sym->stroke->graphic->first != NULL)
         2629  +			      {
         2630  +				  if (line_sym->stroke->graphic->first->type ==
         2631  +				      RL2_EXTERNAL_GRAPHIC)
         2632  +				    {
         2633  +					rl2PrivExternalGraphicPtr ext =
         2634  +					    (rl2PrivExternalGraphicPtr)
         2635  +					    (line_sym->stroke->graphic->
         2636  +					     first->item);
         2637  +					xlink_href = ext->xlink_href;
         2638  +					if (ext->first != NULL)
         2639  +					  {
         2640  +					      recolor = 1;
         2641  +					      red = ext->first->red;
         2642  +					      green = ext->first->green;
         2643  +					      blue = ext->first->blue;
         2644  +					  }
         2645  +				    }
         2646  +			      }
         2647  +			    if (xlink_href != NULL)
         2648  +				pattern =
         2649  +				    rl2_create_pattern_from_external_graphic
         2650  +				    (handle, xlink_href, 1);
  2430   2651   			    if (pattern != NULL)
  2431   2652   			      {
  2432         -				  switch (line_sym->stroke->linecap)
  2433         -				    {
  2434         -				    case RL2_STROKE_LINECAP_ROUND:
  2435         -					pen_cap = RL2_PEN_CAP_ROUND;
  2436         -					break;
  2437         -				    case RL2_STROKE_LINECAP_SQUARE:
  2438         -					pen_cap = RL2_PEN_CAP_SQUARE;
  2439         -					break;
  2440         -				    default:
  2441         -					pen_cap = RL2_PEN_CAP_BUTT;
  2442         -					break;
  2443         -				    };
  2444         -				  switch (line_sym->stroke->linejoin)
  2445         -				    {
  2446         -				    case RL2_STROKE_LINEJOIN_BEVEL:
  2447         -					pen_join = RL2_PEN_JOIN_BEVEL;
  2448         -					break;
  2449         -				    case RL2_STROKE_LINEJOIN_ROUND:
  2450         -					pen_join = RL2_PEN_JOIN_ROUND;
  2451         -					break;
  2452         -				    default:
  2453         -					pen_join = RL2_PEN_JOIN_MITER;
  2454         -					break;
  2455         -				    };
         2653  +				  if (recolor)
         2654  +				    {
         2655  +					/* attempting to recolor the External Graphic resource */
         2656  +					rl2_graph_pattern_recolor (pattern,
         2657  +								   red, green,
         2658  +								   blue);
         2659  +				    }
         2660  +				  if (line_sym->stroke->opacity <= 0.0)
         2661  +				      norm_opacity = 0;
         2662  +				  else if (line_sym->stroke->opacity >= 1.0)
         2663  +				      norm_opacity = 255;
         2664  +				  else
         2665  +				    {
         2666  +					opacity =
         2667  +					    255.0 * line_sym->stroke->opacity;
         2668  +					if (opacity <= 0.0)
         2669  +					    norm_opacity = 0;
         2670  +					else if (opacity >= 255.0)
         2671  +					    norm_opacity = 255;
         2672  +					else
         2673  +					    norm_opacity = opacity;
         2674  +				    }
         2675  +				  if (norm_opacity < 1.0)
         2676  +				      rl2_graph_pattern_transparency
         2677  +					  (pattern, norm_opacity);
  2456   2678   				  if (line_sym->stroke->dash_count > 0
  2457   2679   				      && line_sym->stroke->dash_list != NULL)
  2458   2680   				      rl2_add_pattern_to_multi_stroke_dash
  2459   2681   					  (multi_stroke, pattern,
  2460   2682   					   line_sym->stroke->width, pen_cap,
  2461   2683   					   pen_join,
  2462   2684   					   line_sym->stroke->dash_count,
................................................................................
  2464   2686   					   line_sym->stroke->dash_offset);
  2465   2687   				  else
  2466   2688   				      rl2_add_pattern_to_multi_stroke
  2467   2689   					  (multi_stroke, pattern,
  2468   2690   					   line_sym->stroke->width, pen_cap,
  2469   2691   					   pen_join);
  2470   2692   			      }
         2693  +			    else
         2694  +			      {
         2695  +				  /* invalid Pattern: defaulting to a Gray brush */
         2696  +				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
         2697  +			      }
  2471   2698   			}
  2472   2699   		      else
  2473   2700   			{
  2474   2701   			    /* solid RGB stroke */
  2475   2702   			    if (line_sym->stroke->opacity <= 0.0)
  2476   2703   				norm_opacity = 0;
  2477   2704   			    else if (line_sym->stroke->opacity >= 1.0)
................................................................................
  2547   2774       if (multi_stroke == NULL)
  2548   2775   	return;
  2549   2776   
  2550   2777       line = geom->first_linestring;
  2551   2778       while (line)
  2552   2779         {
  2553   2780   	  /* drawing a LINESTRING */
  2554         -	  rl2PrivMultiStrokeItemPtr stroke_item;
  2555         -	  int iv;
  2556         -	  double dx;
  2557         -	  double dy;
  2558         -	  int x;
  2559         -	  int y;
  2560         -	  int lastX = 0;
  2561         -	  int lastY = 0;
  2562         -	  for (iv = 0; iv < line->points; iv++)
  2563         -	    {
  2564         -		rl2GetPoint (line->coords, iv, &dx, &dy);
  2565         -		x = (int) ((dx - minx) / x_res);
  2566         -		y = height - (int) ((dy - miny) / y_res);
  2567         -		if (iv == 0)
  2568         -		  {
  2569         -		      rl2_graph_move_to_point (ctx, x, y);
  2570         -		      lastX = x;
  2571         -		      lastY = y;
  2572         -		  }
  2573         -		else
  2574         -		  {
  2575         -		      if (x == lastX && y == lastY)
  2576         -			  ;
  2577         -		      else
  2578         -			{
  2579         -			    rl2_graph_add_line_to_path (ctx, x, y);
         2781  +	  if (linestring_bbox_matches (line, minx, miny, maxx, maxy))
         2782  +	    {
         2783  +		rl2PrivMultiStrokeItemPtr stroke_item;
         2784  +		int iv;
         2785  +		double dx;
         2786  +		double dy;
         2787  +		int x;
         2788  +		int y;
         2789  +		int lastX = 0;
         2790  +		int lastY = 0;
         2791  +		for (iv = 0; iv < line->points; iv++)
         2792  +		  {
         2793  +		      rl2GetPoint (line->coords, iv, &dx, &dy);
         2794  +		      x = (int) ((dx - minx) / x_res);
         2795  +		      y = height - (int) ((dy - miny) / y_res);
         2796  +		      if (iv == 0)
         2797  +			{
         2798  +			    rl2_graph_move_to_point (ctx, x, y);
  2580   2799   			    lastX = x;
  2581   2800   			    lastY = y;
  2582   2801   			}
  2583         -		  }
  2584         -	    }
  2585         -	  stroke_item = multi_stroke->first;
  2586         -	  while (stroke_item != NULL)
  2587         -	    {
  2588         -		/* applying all strokes, one after the other */
  2589         -		if (stroke_item->dash_count > 0
  2590         -		    && stroke_item->dash_list != NULL)
  2591         -		  {
  2592         -		      if (stroke_item->pattern != NULL)
  2593         -			  rl2_graph_set_pattern_dashed_pen (ctx,
  2594         -							    stroke_item->pattern,
  2595         -							    stroke_item->width,
  2596         -							    stroke_item->pen_cap,
  2597         -							    stroke_item->pen_join,
  2598         -							    stroke_item->dash_count,
  2599         -							    stroke_item->dash_list,
  2600         -							    stroke_item->dash_offset);
         2802  +		      else
         2803  +			{
         2804  +			    if (x == lastX && y == lastY)
         2805  +				;
         2806  +			    else
         2807  +			      {
         2808  +				  rl2_graph_add_line_to_path (ctx, x, y);
         2809  +				  lastX = x;
         2810  +				  lastY = y;
         2811  +			      }
         2812  +			}
         2813  +		  }
         2814  +		stroke_item = multi_stroke->first;
         2815  +		while (stroke_item != NULL)
         2816  +		  {
         2817  +		      /* applying all strokes, one after the other */
         2818  +		      if (stroke_item->dash_count > 0
         2819  +			  && stroke_item->dash_list != NULL)
         2820  +			{
         2821  +			    if (stroke_item->pattern != NULL)
         2822  +				rl2_graph_set_pattern_dashed_pen (ctx,
         2823  +								  stroke_item->pattern,
         2824  +								  stroke_item->width,
         2825  +								  stroke_item->pen_cap,
         2826  +								  stroke_item->pen_join,
         2827  +								  stroke_item->dash_count,
         2828  +								  stroke_item->dash_list,
         2829  +								  stroke_item->dash_offset);
         2830  +			    else
         2831  +				rl2_graph_set_dashed_pen (ctx,
         2832  +							  stroke_item->red,
         2833  +							  stroke_item->green,
         2834  +							  stroke_item->blue,
         2835  +							  stroke_item->opacity,
         2836  +							  stroke_item->width,
         2837  +							  stroke_item->pen_cap,
         2838  +							  stroke_item->pen_join,
         2839  +							  stroke_item->dash_count,
         2840  +							  stroke_item->dash_list,
         2841  +							  stroke_item->dash_offset);
         2842  +			}
  2601   2843   		      else
  2602         -			  rl2_graph_set_dashed_pen (ctx, stroke_item->red,
  2603         -						    stroke_item->green,
  2604         -						    stroke_item->blue,
  2605         -						    stroke_item->opacity,
  2606         -						    stroke_item->width,
  2607         -						    stroke_item->pen_cap,
  2608         -						    stroke_item->pen_join,
  2609         -						    stroke_item->dash_count,
  2610         -						    stroke_item->dash_list,
  2611         -						    stroke_item->dash_offset);
  2612         -		  }
  2613         -		else
  2614         -		  {
  2615         -		      if (stroke_item->pattern != NULL)
  2616         -			  rl2_graph_set_pattern_solid_pen (ctx,
  2617         -							   stroke_item->pattern,
  2618         -							   stroke_item->width,
  2619         -							   stroke_item->pen_cap,
  2620         -							   stroke_item->pen_join);
         2844  +			{
         2845  +			    if (stroke_item->pattern != NULL)
         2846  +				rl2_graph_set_pattern_solid_pen (ctx,
         2847  +								 stroke_item->pattern,
         2848  +								 stroke_item->width,
         2849  +								 stroke_item->pen_cap,
         2850  +								 stroke_item->pen_join);
         2851  +			    else
         2852  +				rl2_graph_set_solid_pen (ctx,
         2853  +							 stroke_item->red,
         2854  +							 stroke_item->green,
         2855  +							 stroke_item->blue,
         2856  +							 stroke_item->opacity,
         2857  +							 stroke_item->width,
         2858  +							 stroke_item->pen_cap,
         2859  +							 stroke_item->pen_join);
         2860  +			}
         2861  +
         2862  +		      if (stroke_item == multi_stroke->last)
         2863  +			  rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH);
  2621   2864   		      else
  2622         -			  rl2_graph_set_solid_pen (ctx, stroke_item->red,
  2623         -						   stroke_item->green,
  2624         -						   stroke_item->blue,
  2625         -						   stroke_item->opacity,
  2626         -						   stroke_item->width,
  2627         -						   stroke_item->pen_cap,
  2628         -						   stroke_item->pen_join);
         2865  +			  rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH);
         2866  +
         2867  +		      stroke_item = stroke_item->next;
         2868  +		      if (stroke_item == multi_stroke->last)
         2869  +			  rl2_graph_release_pattern_pen (ctx);
  2629   2870   		  }
  2630         -
  2631         -		if (stroke_item == multi_stroke->last)
  2632         -		    rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH);
  2633         -		else
  2634         -		    rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH);
  2635         -
  2636         -		stroke_item = stroke_item->next;
  2637         -		if (stroke_item == multi_stroke->last)
  2638         -		    rl2_graph_release_pattern_pen (ctx);
  2639   2871   	    }
  2640   2872   	  line = line->next;
  2641   2873         }
  2642   2874       rl2_destroy_multi_stroke (multi_stroke);
  2643   2875   }
         2876  +
         2877  +static int
         2878  +ring_bbox_matches (rl2RingPtr ring, double minx, double miny, double maxx,
         2879  +		   double maxy)
         2880  +{
         2881  +/* checks if the Ring BBOX is visible */
         2882  +    if (minx > ring->maxx)
         2883  +	return 0;
         2884  +    if (maxx < ring->minx)
         2885  +	return 0;
         2886  +    if (miny > ring->maxy)
         2887  +	return 0;
         2888  +    if (maxy < ring->miny)
         2889  +	return 0;
         2890  +    return 1;
         2891  +}
  2644   2892   
  2645   2893   static void
  2646   2894   draw_polygons (rl2GraphicsContextPtr ctx, sqlite3 * handle,
  2647   2895   	       rl2PrivVectorSymbolizerPtr sym, int height, double minx,
  2648         -	       double miny, double x_res, double y_res, rl2GeometryPtr geom)
         2896  +	       double miny, double maxx, double maxy, double x_res,
         2897  +	       double y_res, rl2GeometryPtr geom)
  2649   2898   {
  2650   2899   /* drawing Polygonal-type features */
  2651   2900       rl2PrivVectorSymbolizerItemPtr item;
  2652   2901       int stroke = 0;
  2653   2902       int fill = 0;
  2654   2903       int pen_cap;
  2655   2904       int pen_join;
................................................................................
  2704   2953   				    rl2_create_pattern_from_external_graphic
  2705   2954   				    (handle, xlink_href, 1);
  2706   2955   			    if (pattern_fill != NULL)
  2707   2956   			      {
  2708   2957   				  if (recolor)
  2709   2958   				    {
  2710   2959   					/* attempting to recolor the External Graphic resource */
  2711         -					rl2_graph_pattern_recolor (pattern_fill,
  2712         -								   red, green,
  2713         -								   blue);
         2960  +					rl2_graph_pattern_recolor
         2961  +					    (pattern_fill, red, green, blue);
  2714   2962   				    }
  2715   2963   				  if (polyg_sym->fill->opacity <= 0.0)
  2716   2964   				      norm_opacity = 0;
  2717   2965   				  else if (polyg_sym->fill->opacity >= 1.0)
  2718   2966   				      norm_opacity = 255;
  2719   2967   				  else
  2720   2968   				    {
................................................................................
  2765   3013   			}
  2766   3014   		  }
  2767   3015   		if (polyg_sym->stroke != NULL)
  2768   3016   		  {
  2769   3017   		      if (polyg_sym->stroke->graphic != NULL)
  2770   3018   			{
  2771   3019   			    /* external Graphic stroke */
  2772         -			    pattern_stroke =
  2773         -				load_external_graphic_from_dbms (handle,
  2774         -								 polyg_sym->stroke->graphic);
         3020  +			    const char *xlink_href = NULL;
         3021  +			    int recolor = 0;
         3022  +			    unsigned char red;
         3023  +			    unsigned char green;
         3024  +			    unsigned char blue;
         3025  +			    pattern_stroke = NULL;
         3026  +			    if (polyg_sym->stroke->graphic->first != NULL)
         3027  +			      {
         3028  +				  if (polyg_sym->stroke->graphic->first->type ==
         3029  +				      RL2_EXTERNAL_GRAPHIC)
         3030  +				    {
         3031  +					rl2PrivExternalGraphicPtr ext =
         3032  +					    (rl2PrivExternalGraphicPtr)
         3033  +					    (polyg_sym->stroke->graphic->
         3034  +					     first->item);
         3035  +					xlink_href = ext->xlink_href;
         3036  +					if (ext->first != NULL)
         3037  +					  {
         3038  +					      recolor = 1;
         3039  +					      red = ext->first->red;
         3040  +					      green = ext->first->green;
         3041  +					      blue = ext->first->blue;
         3042  +					  }
         3043  +				    }
         3044  +			      }
         3045  +			    if (xlink_href != NULL)
         3046  +				pattern_stroke =
         3047  +				    rl2_create_pattern_from_external_graphic
         3048  +				    (handle, xlink_href, 1);
  2775   3049   			    if (pattern_stroke != NULL)
  2776   3050   			      {
  2777         -				  switch (polyg_sym->stroke->linecap)
         3051  +				  if (recolor)
  2778   3052   				    {
  2779         -				    case RL2_STROKE_LINECAP_ROUND:
  2780         -					pen_cap = RL2_PEN_CAP_ROUND;
  2781         -					break;
  2782         -				    case RL2_STROKE_LINECAP_SQUARE:
  2783         -					pen_cap = RL2_PEN_CAP_SQUARE;
  2784         -					break;
  2785         -				    default:
  2786         -					pen_cap = RL2_PEN_CAP_BUTT;
  2787         -					break;
  2788         -				    };
  2789         -				  switch (polyg_sym->stroke->linejoin)
         3053  +					/* attempting to recolor the External Graphic resource */
         3054  +					rl2_graph_pattern_recolor
         3055  +					    (pattern_stroke, red, green, blue);
         3056  +				    }
         3057  +				  if (polyg_sym->stroke->opacity <= 0.0)
         3058  +				      norm_opacity = 0;
         3059  +				  else if (polyg_sym->stroke->opacity >= 1.0)
         3060  +				      norm_opacity = 255;
         3061  +				  else
  2790   3062   				    {
  2791         -				    case RL2_STROKE_LINEJOIN_BEVEL:
  2792         -					pen_join = RL2_PEN_JOIN_BEVEL;
  2793         -					break;
  2794         -				    case RL2_STROKE_LINEJOIN_ROUND:
  2795         -					pen_join = RL2_PEN_JOIN_ROUND;
  2796         -					break;
  2797         -				    default:
  2798         -					pen_join = RL2_PEN_JOIN_MITER;
  2799         -					break;
  2800         -				    };
  2801         -				  if (polyg_sym->stroke->dash_count > 0
  2802         -				      && polyg_sym->stroke->dash_list != NULL)
  2803         -				      rl2_graph_set_pattern_dashed_pen (ctx,
  2804         -									pattern_stroke,
  2805         -									polyg_sym->
  2806         -									stroke->width,
  2807         -									pen_cap,
  2808         -									pen_join,
  2809         -									polyg_sym->stroke->dash_count,
  2810         -									polyg_sym->stroke->dash_list,
  2811         -									polyg_sym->stroke->dash_offset);
  2812         -				  else
  2813         -				      rl2_graph_set_pattern_solid_pen (ctx,
  2814         -								       pattern_stroke,
  2815         -								       polyg_sym->
  2816         -								       stroke->width,
  2817         -								       pen_cap,
  2818         -								       pen_join);
  2819         -				  stroke = 1;
         3063  +					opacity =
         3064  +					    255.0 * polyg_sym->stroke->opacity;
         3065  +					if (opacity <= 0.0)
         3066  +					    norm_opacity = 0;
         3067  +					else if (opacity >= 255.0)
         3068  +					    norm_opacity = 255;
         3069  +					else
         3070  +					    norm_opacity = opacity;
         3071  +				    }
         3072  +				  if (norm_opacity < 1.0)
         3073  +				      rl2_graph_pattern_transparency
         3074  +					  (pattern_stroke, norm_opacity);
         3075  +				  rl2_graph_set_pattern_brush (ctx,
         3076  +							       pattern_stroke);
         3077  +			      }
         3078  +			    else
         3079  +			      {
         3080  +				  /* invalid Pattern: defaulting to a Gray brush */
         3081  +				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
  2820   3082   			      }
         3083  +			    stroke = 1;
  2821   3084   			}
  2822   3085   		      else
  2823   3086   			{
  2824   3087   			    /* solid RGB stroke */
  2825   3088   			    if (polyg_sym->stroke->opacity <= 0.0)
  2826   3089   				norm_opacity = 0;
  2827   3090   			    else if (polyg_sym->stroke->opacity >= 1.0)
................................................................................
  2910   3173   		int x;
  2911   3174   		int y;
  2912   3175   		int lastX = 0;
  2913   3176   		int lastY = 0;
  2914   3177   		int ib;
  2915   3178   		rl2RingPtr ring = polyg->exterior;
  2916   3179   		/* exterior border */
  2917         -		for (iv = 0; iv < ring->points; iv++)
         3180  +		if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
  2918   3181   		  {
  2919         -		      rl2GetPoint (ring->coords, iv, &dx, &dy);
  2920         -		      x = (int) ((dx - minx) / x_res);
  2921         -		      y = height - (int) ((dy - miny) / y_res);
  2922         -		      if (iv == 0)
  2923         -			{
  2924         -			    rl2_graph_move_to_point (ctx, x, y);
  2925         -			    lastX = x;
  2926         -			    lastY = y;
  2927         -			}
  2928         -		      else
  2929         -			{
  2930         -			    if (x == lastX && y == lastY)
  2931         -				;
  2932         -			    else
  2933         -			      {
  2934         -				  rl2_graph_add_line_to_path (ctx, x, y);
  2935         -				  lastX = x;
  2936         -				  lastY = y;
  2937         -			      }
  2938         -			}
  2939         -		  }
  2940         -		rl2_graph_close_subpath (ctx);
  2941         -		for (ib = 0; ib < polyg->num_interiors; ib++)
  2942         -		  {
  2943         -		      /* interior borders */
  2944         -		      ring = polyg->interiors + ib;
  2945   3182   		      for (iv = 0; iv < ring->points; iv++)
  2946   3183   			{
  2947   3184   			    rl2GetPoint (ring->coords, iv, &dx, &dy);
  2948   3185   			    x = (int) ((dx - minx) / x_res);
  2949   3186   			    y = height - (int) ((dy - miny) / y_res);
  2950   3187   			    if (iv == 0)
  2951   3188   			      {
................................................................................
  2962   3199   					rl2_graph_add_line_to_path (ctx, x, y);
  2963   3200   					lastX = x;
  2964   3201   					lastY = y;
  2965   3202   				    }
  2966   3203   			      }
  2967   3204   			}
  2968   3205   		      rl2_graph_close_subpath (ctx);
         3206  +		  }
         3207  +		else
         3208  +		  {
         3209  +		      /* if the exterior ring is invisible we'll ignore all internal rings */
         3210  +		      polyg = polyg->next;
         3211  +		      continue;
         3212  +		  }
         3213  +		for (ib = 0; ib < polyg->num_interiors; ib++)
         3214  +		  {
         3215  +		      /* interior borders */
         3216  +		      ring = polyg->interiors + ib;
         3217  +		      if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
         3218  +			{
         3219  +			    for (iv = 0; iv < ring->points; iv++)
         3220  +			      {
         3221  +				  rl2GetPoint (ring->coords, iv, &dx, &dy);
         3222  +				  x = (int) ((dx - minx) / x_res);
         3223  +				  y = height - (int) ((dy - miny) / y_res);
         3224  +				  if (iv == 0)
         3225  +				    {
         3226  +					rl2_graph_move_to_point (ctx, x, y);
         3227  +					lastX = x;
         3228  +					lastY = y;
         3229  +				    }
         3230  +				  else
         3231  +				    {
         3232  +					if (x == lastX && y == lastY)
         3233  +					    ;
         3234  +					else
         3235  +					  {
         3236  +					      rl2_graph_add_line_to_path (ctx,
         3237  +									  x, y);
         3238  +					      lastX = x;
         3239  +					      lastY = y;
         3240  +					  }
         3241  +				    }
         3242  +			      }
         3243  +			    rl2_graph_close_subpath (ctx);
         3244  +			}
  2969   3245   		  }
  2970   3246   		if (fill)
  2971   3247   		  {
  2972   3248   		      if (stroke)
  2973   3249   			  rl2_graph_fill_path (ctx, RL2_PRESERVE_PATH);
  2974   3250   		      else
  2975   3251   			  rl2_graph_fill_path (ctx, RL2_CLEAR_PATH);
................................................................................
  2989   3265   		rl2_graph_destroy_pattern (pattern_stroke);
  2990   3266   	    }
  2991   3267   	  item = item->next;
  2992   3268         }
  2993   3269   }
  2994   3270   
  2995   3271   static int
  2996         -label_get_xy (sqlite3 * handle, const unsigned char *blob, int size, double *x,
  2997         -	      double *y)
         3272  +label_get_xy (sqlite3 * handle, const unsigned char *blob, int size,
         3273  +	      double *x, double *y)
  2998   3274   {
  2999   3275   /* resolving Point XY coords */
  3000   3276       const char *sql;
  3001   3277       int ret;
  3002   3278       sqlite3_stmt *stmt = NULL;
  3003   3279       int ok = 0;
  3004   3280   
................................................................................
  3061   3337   	  if (ret == SQLITE_DONE)
  3062   3338   	      break;		/* end of result set */
  3063   3339   	  if (ret == SQLITE_ROW)
  3064   3340   	    {
  3065   3341   		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
  3066   3342   		  {
  3067   3343   		      const unsigned char *g_blob =
  3068         -			  (const unsigned char *) sqlite3_column_blob (stmt, 0);
         3344  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3345  +								       0);
  3069   3346   		      int g_size = sqlite3_column_bytes (stmt, 0);
  3070   3347   		      if (label_get_xy (handle, g_blob, g_size, x, y))
  3071   3348   			  ok = 1;
  3072   3349   		  }
  3073   3350   	    }
  3074   3351         }
  3075   3352       sqlite3_finalize (stmt);
................................................................................
  3108   3385   	  if (ret == SQLITE_DONE)
  3109   3386   	      break;		/* end of result set */
  3110   3387   	  if (ret == SQLITE_ROW)
  3111   3388   	    {
  3112   3389   		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
  3113   3390   		  {
  3114   3391   		      const unsigned char *g_blob =
  3115         -			  (const unsigned char *) sqlite3_column_blob (stmt, 0);
         3392  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3393  +								       0);
         3394  +		      int g_size = sqlite3_column_bytes (stmt, 0);
         3395  +		      if (label_get_xy (handle, g_blob, g_size, x, y))
         3396  +			  ok = 1;
         3397  +		  }
         3398  +	    }
         3399  +      }
         3400  +    sqlite3_finalize (stmt);
         3401  +    return ok;
         3402  +}
         3403  +
         3404  +static int
         3405  +label_get_ring_midpoint (sqlite3 * handle, rl2RingPtr ring, double *x,
         3406  +			 double *y)
         3407  +{
         3408  +/* computing a Ring MidPoint */
         3409  +    unsigned char *blob;
         3410  +    int blob_sz;
         3411  +    const char *sql;
         3412  +    int ret;
         3413  +    sqlite3_stmt *stmt = NULL;
         3414  +    int ok = 0;
         3415  +
         3416  +    if (ring == NULL)
         3417  +	return 0;
         3418  +    if (!rl2_serialize_ring_as_linestring (ring, &blob, &blob_sz))
         3419  +	return 0;
         3420  +
         3421  +    sql = "SELECT ST_Line_Interpolate_Point(?, 0.5)";
         3422  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         3423  +    if (ret != SQLITE_OK)
         3424  +	return 0;
         3425  +
         3426  +    sqlite3_reset (stmt);
         3427  +    sqlite3_clear_bindings (stmt);
         3428  +    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
         3429  +    while (1)
         3430  +      {
         3431  +	  /* scrolling the result set rows */
         3432  +	  ret = sqlite3_step (stmt);
         3433  +	  if (ret == SQLITE_DONE)
         3434  +	      break;		/* end of result set */
         3435  +	  if (ret == SQLITE_ROW)
         3436  +	    {
         3437  +		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
         3438  +		  {
         3439  +		      const unsigned char *g_blob =
         3440  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3441  +								       0);
  3116   3442   		      int g_size = sqlite3_column_bytes (stmt, 0);
  3117   3443   		      if (label_get_xy (handle, g_blob, g_size, x, y))
  3118   3444   			  ok = 1;
  3119   3445   		  }
  3120   3446   	    }
  3121   3447         }
  3122   3448       sqlite3_finalize (stmt);
  3123   3449       return ok;
  3124   3450   }
         3451  +
         3452  +static rl2GeometryPtr
         3453  +do_generalize_linestring (sqlite3 * handle, rl2LinestringPtr line,
         3454  +			  double generalize_factor)
         3455  +{
         3456  +/* simplifying a Linestring */
         3457  +    rl2GeometryPtr geom = NULL;
         3458  +    unsigned char *blob;
         3459  +    int blob_sz;
         3460  +    const char *sql;
         3461  +    int ret;
         3462  +    sqlite3_stmt *stmt = NULL;
         3463  +
         3464  +    if (line == NULL)
         3465  +	return NULL;
         3466  +    if (line->points < 2)
         3467  +	return NULL;
         3468  +    if (!rl2_serialize_linestring (line, &blob, &blob_sz))
         3469  +	return NULL;
         3470  +
         3471  +    sql = "SELECT ST_Simplify(?, ?)";
         3472  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         3473  +    if (ret != SQLITE_OK)
         3474  +	return NULL;
         3475  +
         3476  +    sqlite3_reset (stmt);
         3477  +    sqlite3_clear_bindings (stmt);
         3478  +    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
         3479  +    sqlite3_bind_double (stmt, 2, generalize_factor);
         3480  +    while (1)
         3481  +      {
         3482  +	  /* scrolling the result set rows */
         3483  +	  ret = sqlite3_step (stmt);
         3484  +	  if (ret == SQLITE_DONE)
         3485  +	      break;		/* end of result set */
         3486  +	  if (ret == SQLITE_ROW)
         3487  +	    {
         3488  +		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
         3489  +		  {
         3490  +		      const unsigned char *g_blob =
         3491  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3492  +								       0);
         3493  +		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
         3494  +		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
         3495  +		  }
         3496  +	    }
         3497  +      }
         3498  +    sqlite3_finalize (stmt);
         3499  +    return geom;
         3500  +}
         3501  +
         3502  +static rl2GeometryPtr
         3503  +do_generalize_ring (sqlite3 * handle, rl2RingPtr ring, double generalize_factor)
         3504  +{
         3505  +/* simplifying a Ring */
         3506  +    rl2GeometryPtr geom = NULL;
         3507  +    unsigned char *blob;
         3508  +    int blob_sz;
         3509  +    const char *sql;
         3510  +    int ret;
         3511  +    sqlite3_stmt *stmt = NULL;
         3512  +
         3513  +    if (ring == NULL)
         3514  +	return NULL;
         3515  +    if (ring->points < 2)
         3516  +	return NULL;
         3517  +    if (!rl2_serialize_ring (ring, &blob, &blob_sz))
         3518  +	return NULL;
         3519  +
         3520  +    sql = "SELECT ST_SimplifyPreserveTopology(?, ?)";
         3521  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         3522  +    if (ret != SQLITE_OK)
         3523  +	return NULL;
         3524  +
         3525  +    sqlite3_reset (stmt);
         3526  +    sqlite3_clear_bindings (stmt);
         3527  +    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
         3528  +    sqlite3_bind_double (stmt, 2, generalize_factor);
         3529  +    while (1)
         3530  +      {
         3531  +	  /* scrolling the result set rows */
         3532  +	  ret = sqlite3_step (stmt);
         3533  +	  if (ret == SQLITE_DONE)
         3534  +	      break;		/* end of result set */
         3535  +	  if (ret == SQLITE_ROW)
         3536  +	    {
         3537  +		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
         3538  +		  {
         3539  +		      const unsigned char *g_blob =
         3540  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3541  +								       0);
         3542  +		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
         3543  +		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
         3544  +		  }
         3545  +	    }
         3546  +      }
         3547  +    sqlite3_finalize (stmt);
         3548  +    return geom;
         3549  +}
         3550  +
         3551  +static int
         3552  +check_valid_line (rl2LinestringPtr line)
         3553  +{
         3554  +/* testing for a valid linestring */
         3555  +    int iv;
         3556  +    int pts = 0;
         3557  +    double x;
         3558  +    double y;
         3559  +    double x0;
         3560  +    double y0;
         3561  +
         3562  +    if (line == NULL)
         3563  +	return 0;
         3564  +    if (line->points < 2)
         3565  +	return 0;
         3566  +    rl2GetPoint (line->coords, 0, &x0, &y0);
         3567  +    for (iv = 1; iv < line->points; iv++)
         3568  +      {
         3569  +	  rl2GetPoint (line->coords, iv, &x, &y);
         3570  +	  if (x != x0 || y != y0)
         3571  +	    {
         3572  +		pts++;
         3573  +		break;
         3574  +	    }
         3575  +      }
         3576  +    if (pts == 0)
         3577  +	return 0;
         3578  +    return 1;
         3579  +}
         3580  +
         3581  +static rl2GeometryPtr
         3582  +do_offset_linestring (sqlite3 * handle, rl2LinestringPtr line,
         3583  +		      double perpendicular_offset)
         3584  +{
         3585  +/* Offest Curve (from Linestring) */
         3586  +    rl2GeometryPtr geom = NULL;
         3587  +    unsigned char *blob;
         3588  +    int blob_sz;
         3589  +    const char *sql;
         3590  +    int ret;
         3591  +    sqlite3_stmt *stmt = NULL;
         3592  +
         3593  +    if (!check_valid_line (line))
         3594  +	return NULL;
         3595  +    if (!rl2_serialize_linestring (line, &blob, &blob_sz))
         3596  +	return NULL;
         3597  +
         3598  +    sql = "SELECT ST_OffsetCurve(?, ?)";
         3599  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         3600  +    if (ret != SQLITE_OK)
         3601  +	return NULL;
         3602  +
         3603  +    sqlite3_reset (stmt);
         3604  +    sqlite3_clear_bindings (stmt);
         3605  +    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
         3606  +    sqlite3_bind_double (stmt, 2, perpendicular_offset);
         3607  +    while (1)
         3608  +      {
         3609  +	  /* scrolling the result set rows */
         3610  +	  ret = sqlite3_step (stmt);
         3611  +	  if (ret == SQLITE_DONE)
         3612  +	      break;		/* end of result set */
         3613  +	  if (ret == SQLITE_ROW)
         3614  +	    {
         3615  +		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
         3616  +		  {
         3617  +		      const unsigned char *g_blob =
         3618  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3619  +								       0);
         3620  +		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
         3621  +		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
         3622  +		  }
         3623  +	    }
         3624  +      }
         3625  +    sqlite3_finalize (stmt);
         3626  +    return geom;
         3627  +}
         3628  +
         3629  +static int
         3630  +check_valid_ring (rl2RingPtr ring)
         3631  +{
         3632  +/* testing for a valid ring */
         3633  +    int iv;
         3634  +    int pts = 0;
         3635  +    int last;
         3636  +    double x;
         3637  +    double y;
         3638  +    double x0;
         3639  +    double y0;
         3640  +    double x1;
         3641  +    double y1;
         3642  +
         3643  +    if (ring == NULL)
         3644  +	return 0;
         3645  +    if (ring->points < 4)
         3646  +	return 0;
         3647  +    rl2GetPoint (ring->coords, 0, &x0, &y0);
         3648  +    for (iv = 1; iv < ring->points; iv++)
         3649  +      {
         3650  +	  rl2GetPoint (ring->coords, iv, &x, &y);
         3651  +	  if (pts == 0)
         3652  +	    {
         3653  +		if (x != x0 || y != y0)
         3654  +		  {
         3655  +		      pts++;
         3656  +		      x1 = x;
         3657  +		      y1 = y;
         3658  +		  }
         3659  +	    }
         3660  +	  else
         3661  +	    {
         3662  +		if ((x != x0 || y != y0) && (x != x1 || y != y1))
         3663  +		  {
         3664  +		      pts++;
         3665  +		      break;
         3666  +		  }
         3667  +	    }
         3668  +      }
         3669  +    last = ring->points - 1;
         3670  +    rl2GetPoint (ring->coords, last, &x1, &y1);
         3671  +    if (pts == 2 && x0 == x1 && y0 == y1)
         3672  +	return 1;
         3673  +    return 0;
         3674  +}
         3675  +
         3676  +static rl2GeometryPtr
         3677  +do_buffered_ring (sqlite3 * handle, rl2RingPtr ring,
         3678  +		  double perpendicular_offset)
         3679  +{
         3680  +/* Buffer (from Ring) */
         3681  +    rl2GeometryPtr geom = NULL;
         3682  +    unsigned char *blob;
         3683  +    int blob_sz;
         3684  +    const char *sql;
         3685  +    int ret;
         3686  +    sqlite3_stmt *stmt = NULL;
         3687  +
         3688  +    if (!check_valid_ring (ring))
         3689  +	return NULL;
         3690  +    if (!rl2_serialize_ring (ring, &blob, &blob_sz))
         3691  +	return NULL;
         3692  +
         3693  +    sql = "SELECT ST_Buffer(?, ?)";
         3694  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         3695  +    if (ret != SQLITE_OK)
         3696  +	return NULL;
         3697  +
         3698  +    sqlite3_reset (stmt);
         3699  +    sqlite3_clear_bindings (stmt);
         3700  +    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
         3701  +    sqlite3_bind_double (stmt, 2, perpendicular_offset);
         3702  +    while (1)
         3703  +      {
         3704  +	  /* scrolling the result set rows */
         3705  +	  ret = sqlite3_step (stmt);
         3706  +	  if (ret == SQLITE_DONE)
         3707  +	      break;		/* end of result set */
         3708  +	  if (ret == SQLITE_ROW)
         3709  +	    {
         3710  +		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
         3711  +		  {
         3712  +		      const unsigned char *g_blob =
         3713  +			  (const unsigned char *) sqlite3_column_blob (stmt,
         3714  +								       0);
         3715  +		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
         3716  +		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
         3717  +		  }
         3718  +	    }
         3719  +      }
         3720  +    sqlite3_finalize (stmt);
         3721  +    return geom;
         3722  +}
         3723  +
         3724  +static void
         3725  +create_line_array_from_linestring (sqlite3 * handle, rl2LinestringPtr line,
         3726  +				   double perpendicular_offset, int *points,
         3727  +				   double **x_array, double **y_array,
         3728  +				   int generalize_line,
         3729  +				   double generalize_factor, int height,
         3730  +				   double minx, double miny, double x_res,
         3731  +				   double y_res)
         3732  +{
         3733  +/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */
         3734  +    rl2GeometryPtr geom = NULL;
         3735  +    rl2GeometryPtr geom2 = NULL;
         3736  +    rl2LinestringPtr aux_line;
         3737  +    rl2LinestringPtr in_line;
         3738  +    double *xx = NULL;
         3739  +    double *yy = NULL;
         3740  +    int iv;
         3741  +    double x;
         3742  +    double y;
         3743  +
         3744  +    *points = 0;
         3745  +    *x_array = NULL;
         3746  +    *y_array = NULL;
         3747  +    if (line == NULL)
         3748  +	goto error;
         3749  +
         3750  +    aux_line = rl2_linestring_to_image (line, height, minx, miny, x_res, y_res);
         3751  +    if (aux_line == NULL)
         3752  +	goto error;
         3753  +    in_line = aux_line;
         3754  +    if (generalize_line)
         3755  +      {
         3756  +	  geom = do_generalize_linestring (handle, in_line, generalize_factor);
         3757  +	  if (geom == NULL)
         3758  +	      goto error;
         3759  +	  in_line = geom->first_linestring;
         3760  +	  if (in_line == NULL)
         3761  +	      goto error;
         3762  +      }
         3763  +    if (perpendicular_offset != 0.0)
         3764  +      {
         3765  +	  geom2 = do_offset_linestring (handle, in_line, perpendicular_offset);
         3766  +	  if (geom2 == NULL)
         3767  +	      goto error;
         3768  +	  in_line = geom2->first_linestring;
         3769  +	  if (in_line == NULL)
         3770  +	      goto error;
         3771  +      }
         3772  +
         3773  +/* allocating the X and Y arrays */
         3774  +    if (in_line->points < 2)
         3775  +	goto error;
         3776  +    xx = malloc (sizeof (double) * in_line->points);
         3777  +    yy = malloc (sizeof (double) * in_line->points);
         3778  +    if (xx == NULL || yy == NULL)
         3779  +      {
         3780  +	  if (xx != NULL)
         3781  +	      free (xx);
         3782  +	  if (yy != NULL)
         3783  +	      free (yy);
         3784  +	  goto error;
         3785  +      }
         3786  +    for (iv = 0; iv < in_line->points; iv++)
         3787  +      {
         3788  +	  /* populating the X and Y arrays */
         3789  +	  rl2GetPoint (in_line->coords, iv, &x, &y);
         3790  +	  *(xx + iv) = x;
         3791  +	  *(yy + iv) = y;
         3792  +      }
         3793  +    *points = in_line->points;
         3794  +    *x_array = xx;
         3795  +    *y_array = yy;
         3796  +
         3797  +  error:
         3798  +    if (aux_line)
         3799  +	rl2DestroyLinestring (aux_line);
         3800  +    if (geom)
         3801  +	rl2_destroy_geometry (geom);
         3802  +    if (geom2)
         3803  +	rl2_destroy_geometry (geom2);
         3804  +}
         3805  +
         3806  +static void
         3807  +create_line_array_from_ring (sqlite3 * handle, rl2RingPtr ring,
         3808  +			     double perpendicular_offset, int *points,
         3809  +			     double **x_array, double **y_array,
         3810  +			     int generalize_line, double generalize_factor,
         3811  +			     int height, double minx, double miny, double x_res,
         3812  +			     double y_res)
         3813  +{
         3814  +/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */
         3815  +    rl2GeometryPtr geom = NULL;
         3816  +    rl2GeometryPtr geom2 = NULL;
         3817  +    rl2PolygonPtr pg;
         3818  +    rl2RingPtr aux_ring;
         3819  +    rl2RingPtr in_ring;
         3820  +    double *xx = NULL;
         3821  +    double *yy = NULL;
         3822  +    int iv;
         3823  +    double x;
         3824  +    double y;
         3825  +
         3826  +    *points = 0;
         3827  +    *x_array = NULL;
         3828  +    *y_array = NULL;
         3829  +    if (ring == NULL)
         3830  +	goto error;
         3831  +
         3832  +    aux_ring = rl2_ring_to_image (ring, height, minx, miny, x_res, y_res);
         3833  +    if (aux_ring == NULL)
         3834  +	goto error;
         3835  +    in_ring = aux_ring;
         3836  +    if (generalize_line)
         3837  +      {
         3838  +	  geom = do_generalize_ring (handle, in_ring, generalize_factor);
         3839  +	  if (geom == NULL)
         3840  +	      goto error;
         3841  +	  pg = geom->first_polygon;
         3842  +	  if (pg == NULL)
         3843  +	      goto error;
         3844  +	  in_ring = pg->exterior;
         3845  +	  if (in_ring == NULL)
         3846  +	      goto error;
         3847  +      }
         3848  +    if (perpendicular_offset != 0.0)
         3849  +      {
         3850  +	  geom2 = do_buffered_ring (handle, in_ring, perpendicular_offset);
         3851  +	  if (geom2 == NULL)
         3852  +	      goto error;
         3853  +	  pg = geom2->first_polygon;
         3854  +	  if (pg == NULL)
         3855  +	      goto error;
         3856  +	  in_ring = pg->exterior;
         3857  +	  if (in_ring == NULL)
         3858  +	      goto error;
         3859  +      }
         3860  +
         3861  +/* allocating the X and Y arrays */
         3862  +    if (in_ring->points < 2)
         3863  +	goto error;
         3864  +    xx = malloc (sizeof (double) * in_ring->points);
         3865  +    yy = malloc (sizeof (double) * in_ring->points);
         3866  +    if (xx == NULL || yy == NULL)
         3867  +      {
         3868  +	  if (xx != NULL)
         3869  +	      free (xx);
         3870  +	  if (yy != NULL)
         3871  +	      free (yy);
         3872  +	  goto error;
         3873  +      }
         3874  +    for (iv = 0; iv < in_ring->points; iv++)
         3875  +      {
         3876  +	  /* populating the X and Y arrays */
         3877  +	  rl2GetPoint (in_ring->coords, iv, &x, &y);
         3878  +	  *(xx + iv) = x;
         3879  +	  *(yy + iv) = y;
         3880  +      }
         3881  +    *points = in_ring->points;
         3882  +    *x_array = xx;
         3883  +    *y_array = yy;
         3884  +
         3885  +  error:
         3886  +    if (aux_ring)
         3887  +	rl2DestroyRing (aux_ring);
         3888  +    if (geom)
         3889  +	rl2_destroy_geometry (geom);
         3890  +    if (geom2)
         3891  +	rl2_destroy_geometry (geom2);
         3892  +}
  3125   3893   
  3126   3894   static void
  3127   3895   draw_labels (rl2GraphicsContextPtr ctx, sqlite3 * handle,
  3128         -	     rl2PrivTextSymbolizerPtr sym, int height, double minx, double miny,
  3129         -	     double x_res, double y_res, rl2GeometryPtr geom,
  3130         -	     rl2PrivVariantValuePtr value)
         3896  +	     const void *priv_data, rl2PrivTextSymbolizerPtr sym, int height,
         3897  +	     double minx, double miny, double maxx, double maxy, double x_res,
         3898  +	     double y_res, rl2GeometryPtr geom, rl2PrivVariantValuePtr value)
  3131   3899   {
  3132   3900   /* drawing TextLabels */
  3133   3901       rl2GraphicsFontPtr font = NULL;
  3134   3902       char *dummy = NULL;
  3135   3903       const char *label = NULL;
  3136   3904       int font_style;
  3137   3905       int font_weight;
  3138   3906       double opacity;
  3139   3907       unsigned char norm_opacity;
  3140   3908       rl2PointPtr point;
  3141   3909       rl2LinestringPtr line;
  3142   3910       rl2PolygonPtr polyg;
         3911  +    double rotation = 0.0;
         3912  +    double anchor_point_x = 0.0;
         3913  +    double anchor_point_y = 0.0;
         3914  +    double displacement_x = 0.0;
         3915  +    double displacement_y = 0.0;
         3916  +    double perpendicular_offset = 0.0;
         3917  +    int is_repeated = 0;
         3918  +    double initial_gap = 0.0;
         3919  +    double gap = 0.0;
         3920  +    int is_aligned = 0;
         3921  +    int generalize_line = 0;
         3922  +    int i;
  3143   3923   
  3144   3924   /* preparing the Text */
  3145   3925       if (value->sqlite3_type == SQLITE_INTEGER)
  3146   3926         {
  3147   3927   	  dummy = sqlite3_malloc (1024);
  3148   3928   #if defined(_WIN32) && !defined(__MINGW32__)
  3149   3929   	  sprintf (dummy, "%I64d", value->int_value);
................................................................................
  3182   3962   	  font_weight = RL2_FONTWEIGHT_BOLD;
  3183   3963   	  break;
  3184   3964         case RL2_FONT_WEIGHT_NORMAL:
  3185   3965         default:
  3186   3966   	  font_weight = RL2_FONTWEIGHT_NORMAL;
  3187   3967   	  break;
  3188   3968         };
  3189         -    font =
  3190         -	rl2_graph_create_toy_font (NULL, sym->font_size, font_style,
  3191         -				   font_weight);
         3969  +    for (i = 0; i < RL2_MAX_FONT_FAMILIES; i++)
         3970  +      {
         3971  +	  const char *facename = sym->font_families[i];
         3972  +	  if (facename != NULL)
         3973  +	      font =
         3974  +		  rl2_search_TrueType_font (handle, priv_data, facename,
         3975  +					    sym->font_size);
         3976  +	  if (font != NULL)
         3977  +	      break;
         3978  +      }
         3979  +    if (font == NULL)
         3980  +      {
         3981  +	  /* defaulting to a toy font */
         3982  +	  font =
         3983  +	      rl2_graph_create_toy_font (NULL, sym->font_size, font_style,
         3984  +					 font_weight);
         3985  +      }
  3192   3986       if (font == NULL)
  3193   3987   	goto stop;
  3194   3988       if (sym->fill != NULL)
  3195   3989         {
  3196   3990   	  if (sym->fill->opacity <= 0.0)
  3197   3991   	      norm_opacity = 0;
  3198   3992   	  else if (sym->fill->opacity >= 1.0)
................................................................................
  3223   4017   		    norm_opacity = 0;
  3224   4018   		else if (opacity >= 255.0)
  3225   4019   		    norm_opacity = 255;
  3226   4020   		else
  3227   4021   		    norm_opacity = opacity;
  3228   4022   	    }
  3229   4023   	  rl2_graph_font_set_halo (font, sym->halo->radius,
  3230         -				   sym->halo->fill->red, sym->halo->fill->green,
         4024  +				   sym->halo->fill->red,
         4025  +				   sym->halo->fill->green,
  3231   4026   				   sym->halo->fill->blue, norm_opacity);
  3232   4027         }
  3233   4028       rl2_graph_set_font (ctx, font);
  3234   4029   
  3235         -    polyg = geom->first_polygon;
  3236         -    while (polyg)
         4030  +    if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT)
         4031  +      {
         4032  +	  /* retrieving eventual Point Placement arguments */
         4033  +	  rl2PrivPointPlacementPtr ptpl =
         4034  +	      (rl2PrivPointPlacementPtr) (sym->label_placement);
         4035  +	  if (ptpl != NULL)
         4036  +	    {
         4037  +		anchor_point_x = ptpl->anchor_point_x;
         4038  +		anchor_point_y = ptpl->anchor_point_y;
         4039  +		displacement_x = ptpl->displacement_x;
         4040  +		displacement_y = ptpl->displacement_y;
         4041  +		rotation = ptpl->rotation;
         4042  +	    }
         4043  +      }
         4044  +    else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE)
         4045  +      {
         4046  +	  /* retrieving eventual Lineo Placement arguments */
         4047  +	  rl2PrivLinePlacementPtr lnpl =
         4048  +	      (rl2PrivLinePlacementPtr) (sym->label_placement);
         4049  +	  if (lnpl != NULL)
         4050  +	    {
         4051  +		perpendicular_offset = lnpl->perpendicular_offset;
         4052  +		is_repeated = lnpl->is_repeated;
         4053  +		initial_gap = lnpl->initial_gap;
         4054  +		gap = lnpl->gap;
         4055  +		is_aligned = lnpl->is_aligned;
         4056  +		generalize_line = lnpl->generalize_line;
         4057  +	    }
         4058  +      }
         4059  +
         4060  +    if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT)
  3237   4061         {
  3238         -	  /* drawing a POLYGON-based text label */
  3239         -	  double pre_x;
  3240         -	  double pre_y;
  3241         -	  double lbl_width = 0.0;
  3242         -	  double lbl_height = 0.0;
  3243         -	  double post_x;
  3244         -	  double post_y;
  3245         -	  double shift_x;
  3246         -	  double shift_y;
         4062  +	  /* POINT PLACEMENT */
         4063  +	  rl2Point pt;
  3247   4064   	  double cx;
  3248   4065   	  double cy;
  3249   4066   	  double x;
  3250   4067   	  double y;
  3251         -	  if (!label_get_centroid (handle, polyg, &cx, &cy))
         4068  +
         4069  +	  polyg = geom->first_polygon;
         4070  +	  while (polyg)
  3252   4071   	    {
         4072  +		/* drawing a POLYGON-based text label */
         4073  +		if (!label_get_centroid (handle, polyg, &cx, &cy))
         4074  +		  {
         4075  +		      polyg = polyg->next;
         4076  +		      continue;
         4077  +		  }
         4078  +		pt.x = cx;
         4079  +		pt.y = cy;
         4080  +		if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
         4081  +		  {
         4082  +		      x = (cx - minx) / x_res;
         4083  +		      y = (double) height - ((cy - miny) / y_res);
         4084  +		      rl2_graph_draw_text (ctx, label, x + displacement_x,
         4085  +					   y - displacement_y, rotation,
         4086  +					   anchor_point_x, anchor_point_y);
         4087  +		  }
  3253   4088   		polyg = polyg->next;
  3254         -		continue;
         4089  +	    }
         4090  +
         4091  +	  line = geom->first_linestring;
         4092  +	  while (line)
         4093  +	    {
         4094  +		/* drawing a LINESTRING-based text label */
         4095  +		label_get_midpoint (handle, line, &cx, &cy);
         4096  +		pt.x = cx;
         4097  +		pt.y = cy;
         4098  +		if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
         4099  +		  {
         4100  +		      x = (cx - minx) / x_res;
         4101  +		      y = (double) height - ((cy - miny) / y_res);
         4102  +		      rl2_graph_draw_text (ctx, label, x + displacement_x,
         4103  +					   y - displacement_y, rotation,
         4104  +					   anchor_point_x, anchor_point_y);
         4105  +		  }
         4106  +		line = line->next;
         4107  +	    }
         4108  +
         4109  +	  point = geom->first_point;
         4110  +	  while (point)
         4111  +	    {
         4112  +		/* drawing a POINT-based text label */
         4113  +		if (point_bbox_matches (point, minx, miny, maxx, maxy))
         4114  +		  {
         4115  +		      double x = (point->x - minx) / x_res;
         4116  +		      double y = (double) height - ((point->y - miny) / y_res);
         4117  +		      rl2_graph_draw_text (ctx, label, x + displacement_x,
         4118  +					   y - displacement_y, rotation,
         4119  +					   anchor_point_x, anchor_point_y);
         4120  +		  }
         4121  +		point = point->next;
  3255   4122   	    }
  3256         -	  x = (cx - minx) / x_res;
  3257         -	  y = (double) height - ((cy - miny) / y_res);
  3258         -	  rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width,
  3259         -				     &lbl_height, &post_x, &post_y);
  3260         -	  shift_x = 0.0 - (lbl_width / 2.0);
  3261         -	  shift_y = 0.0 + (lbl_height / 2.0);
  3262         -	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
  3263         -			       0.0);
  3264         -	  polyg = polyg->next;
         4123  +
  3265   4124         }
  3266         -
  3267         -    line = geom->first_linestring;
  3268         -    while (line)
         4125  +    else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE)
  3269   4126         {
  3270         -	  /* drawing a LINESTRING-based text label */
  3271         -	  double pre_x;
  3272         -	  double pre_y;
  3273         -	  double lbl_width = 0.0;
  3274         -	  double lbl_height = 0.0;
  3275         -	  double post_x;
  3276         -	  double post_y;
  3277         -	  double shift_x;
  3278         -	  double shift_y;
         4127  +	  /* LINE PLACEMENT */
         4128  +	  rl2Point pt;
         4129  +	  int ib;
  3279   4130   	  double cx;
  3280   4131   	  double cy;
  3281   4132   	  double x;
  3282   4133   	  double y;
  3283         -	  label_get_midpoint (handle, line, &cx, &cy);
  3284         -	  if (!rl2_graph_get_text_extent
  3285         -	      (ctx, label, &pre_x, &pre_y, &lbl_width, &lbl_height, &post_x,
  3286         -	       &post_y))
         4134  +	  double generalize_factor = 8.0;
         4135  +
         4136  +	  line = geom->first_linestring;
         4137  +	  while (line)
  3287   4138   	    {
         4139  +		/* drawing a LINESTRING-based text label */
         4140  +		if (!is_aligned)
         4141  +		  {
         4142  +		      /* horizontal label aligned to center point */
         4143  +		      label_get_midpoint (handle, line, &cx, &cy);
         4144  +		      pt.x = cx;
         4145  +		      pt.y = cy;
         4146  +		      if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
         4147  +			{
         4148  +			    x = (cx - minx) / x_res;
         4149  +			    y = (double) height - ((cy - miny) / y_res);
         4150  +			    rl2_graph_draw_text (ctx, label, x, y, 0.0, 0.5,
         4151  +						 0.5);
         4152  +			}
         4153  +		  }
         4154  +		else
         4155  +		  {
         4156  +		      /* label is warped along the line */
         4157  +		      double *x_array = NULL;
         4158  +		      double *y_array = NULL;
         4159  +		      int points;
         4160  +		      if (linestring_bbox_matches
         4161  +			  (line, minx, miny, maxx, maxy))
         4162  +			{
         4163  +			    create_line_array_from_linestring (handle, line,
         4164  +							       perpendicular_offset,
         4165  +							       &points,
         4166  +							       &x_array,
         4167  +							       &y_array,
         4168  +							       generalize_line,
         4169  +							       generalize_factor,
         4170  +							       height, minx,
         4171  +							       miny, x_res,
         4172  +							       y_res);
         4173  +			    if (x_array != NULL && y_array != NULL)
         4174  +				rl2_graph_draw_warped_text (handle, ctx, label,
         4175  +							    points, x_array,
         4176  +							    y_array,
         4177  +							    initial_gap, gap,
         4178  +							    is_repeated);
         4179  +			    if (x_array)
         4180  +				free (x_array);
         4181  +			    if (y_array)
         4182  +				free (y_array);
         4183  +			}
         4184  +		  }
  3288   4185   		line = line->next;
  3289         -		continue;
  3290   4186   	    }
  3291         -	  x = (cx - minx) / x_res;
  3292         -	  y = (double) height - ((cy - miny) / y_res);
  3293         -	  shift_x = 0.0 - (lbl_width / 2.0);
  3294         -	  shift_y = 0.0 + (lbl_height / 2.0);
  3295         -	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
  3296         -			       0.0);
  3297         -	  line = line->next;
  3298         -      }
  3299         -
  3300         -    point = geom->first_point;
  3301         -    while (point)
  3302         -      {
  3303         -	  /* drawing a POINT-based text label */
  3304         -	  double pre_x;
  3305         -	  double pre_y;
  3306         -	  double lbl_width = 0.0;
  3307         -	  double lbl_height = 0.0;
  3308         -	  double post_x;
  3309         -	  double post_y;
  3310         -	  double shift_x;
  3311         -	  double shift_y;
  3312         -	  double x = (point->x - minx) / x_res;
  3313         -	  double y = (double) height - ((point->y - miny) / y_res);
  3314         -	  rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width,
  3315         -				     &lbl_height, &post_x, &post_y);
  3316         -	  shift_x = 0.0 - (lbl_width / 2.0);
  3317         -	  shift_y = 0.0 + (lbl_height / 2.0);
  3318         -	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
  3319         -			       0.0);
  3320         -	  point = point->next;
         4187  +
         4188  +	  polyg = geom->first_polygon;
         4189  +	  while (polyg)
         4190  +	    {
         4191  +		/* drawing a POLYGON-based text label */
         4192  +		rl2RingPtr ring = polyg->exterior;
         4193  +		/* exterior border */
         4194  +		if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
         4195  +		  {
         4196  +		      if (!is_aligned)
         4197  +			{
         4198  +			    /* horizontal label aligned to Ring's center point */
         4199  +			    label_get_ring_midpoint (handle, ring, &cx, &cy);
         4200  +			    pt.x = cx;
         4201  +			    pt.y = cy;
         4202  +			    if (point_bbox_matches
         4203  +				(&pt, minx, miny, maxx, maxy))
         4204  +			      {
         4205  +				  x = (cx - minx) / x_res;
         4206  +				  y = (double) height - ((cy - miny) / y_res);
         4207  +				  rl2_graph_draw_text (ctx, label, x, y, 0.0,
         4208  +						       0.5, 0.5);
         4209  +			      }
         4210  +			}
         4211  +		      else
         4212  +			{
         4213  +			    /* label is warped along the Ring */
         4214  +			    double *x_array = NULL;
         4215  +			    double *y_array = NULL;
         4216  +			    int points;
         4217  +			    if (ring_bbox_matches
         4218  +				(ring, minx, miny, maxx, maxy))
         4219  +			      {
         4220  +				  create_line_array_from_ring (handle, ring,
         4221  +							       perpendicular_offset,
         4222  +							       &points,
         4223  +							       &x_array,
         4224  +							       &y_array,
         4225  +							       generalize_line,
         4226  +							       generalize_factor,
         4227  +							       height, minx,
         4228  +							       miny, x_res,
         4229  +							       y_res);
         4230  +				  if (x_array != NULL && y_array != NULL)
         4231  +				    {
         4232  +					rl2_graph_draw_warped_text (handle, ctx,
         4233  +								    label,
         4234  +								    points,
         4235  +								    x_array,
         4236  +								    y_array,
         4237  +								    initial_gap,
         4238  +								    gap,
         4239  +								    is_repeated);
         4240  +				    }
         4241  +				  if (x_array)
         4242  +				      free (x_array);
         4243  +				  if (y_array)
         4244  +				      free (y_array);
         4245  +			      }
         4246  +			}
         4247  +		  }
         4248  +		else
         4249  +		  {
         4250  +		      /* if the exterior ring is invisible we'll ignore all internal rings */
         4251  +		      polyg = polyg->next;
         4252  +		      continue;
         4253  +		  }
         4254  +		for (ib = 0; ib < polyg->num_interiors; ib++)
         4255  +		  {
         4256  +		      /* interior borders */
         4257  +		      ring = polyg->interiors + ib;
         4258  +		      if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
         4259  +			{
         4260  +			    if (!is_aligned)
         4261  +			      {
         4262  +				  /* horizontal label aligned to Ring's center point */
         4263  +				  label_get_ring_midpoint (handle, ring, &cx,
         4264  +							   &cy);
         4265  +				  pt.x = cx;
         4266  +				  pt.y = cy;
         4267  +				  if (point_bbox_matches
         4268  +				      (&pt, minx, miny, maxx, maxy))
         4269  +				    {
         4270  +					x = (cx - minx) / x_res;
         4271  +					y = (double) height -
         4272  +					    ((cy - miny) / y_res);
         4273  +					rl2_graph_draw_text (ctx, label, x, y,
         4274  +							     0.0, 0.5, 0.5);
         4275  +				    }
         4276  +			      }
         4277  +			    else
         4278  +			      {
         4279  +				  /* label is warped along the Ring */
         4280  +				  double *x_array = NULL;
         4281  +				  double *y_array = NULL;
         4282  +				  int points;
         4283  +				  if (ring_bbox_matches
         4284  +				      (ring, minx, miny, maxx, maxy))
         4285  +				    {
         4286  +					create_line_array_from_ring (handle,
         4287  +								     ring,
         4288  +								     perpendicular_offset,
         4289  +								     &points,
         4290  +								     &x_array,
         4291  +								     &y_array,
         4292  +								     generalize_line,
         4293  +								     generalize_factor,
         4294  +								     height,
         4295  +								     minx, miny,
         4296  +								     x_res,
         4297  +								     y_res);
         4298  +					if (x_array != NULL && y_array != NULL)
         4299  +					    rl2_graph_draw_warped_text (handle,
         4300  +									ctx,
         4301  +									label,
         4302  +									points,
         4303  +									x_array,
         4304  +									y_array,
         4305  +									initial_gap,
         4306  +									gap,
         4307  +									is_repeated);
         4308  +					if (x_array)
         4309  +					    free (x_array);
         4310  +					if (y_array)
         4311  +					    free (y_array);
         4312  +				    }
         4313  +			      }
         4314  +			}
         4315  +		  }
         4316  +		polyg = polyg->next;
         4317  +	    }
  3321   4318         }
  3322   4319   
  3323   4320   /* final cleanup - relasing resources */
  3324   4321     stop:
  3325   4322       if (dummy != NULL)
  3326   4323   	sqlite3_free (dummy);
  3327   4324       if (font != NULL)
  3328         -	rl2_graph_destroy_font (font);
         4325  +      {
         4326  +	  rl2_graph_release_font (ctx);
         4327  +	  rl2_graph_destroy_font (font);
         4328  +      }
  3329   4329   }
  3330   4330   
  3331   4331   RL2_PRIVATE void
  3332         -rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle,
         4332  +rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle, const void *priv_data,
  3333   4333   			 rl2VectorSymbolizerPtr symbolizer, int height,
  3334         -			 double minx, double miny, double x_res, double y_res,
  3335         -			 rl2GeometryPtr geom, rl2VariantArrayPtr variant)
         4334  +			 double minx, double miny, double maxx, double maxy,
         4335  +			 double x_res, double y_res, rl2GeometryPtr geom,
         4336  +			 rl2VariantArrayPtr variant)
  3336   4337   {
  3337   4338   /* drawing a vector feature on the current canvass */
  3338   4339       rl2PrivVectorSymbolizerItemPtr item;
  3339   4340       rl2GraphicsContextPtr ctx = (rl2GraphicsContextPtr) p_ctx;
  3340   4341       rl2PrivVectorSymbolizerPtr sym = (rl2PrivVectorSymbolizerPtr) symbolizer;
  3341   4342       rl2PrivVectorSymbolizerPtr default_symbolizer = NULL;
  3342   4343   
................................................................................
  3419   4420   	      default_symbolizer->last->next = item;
  3420   4421   	  default_symbolizer->last = item;
  3421   4422   	  sym = default_symbolizer;
  3422   4423         }
  3423   4424   
  3424   4425   /* we'll render all geometries first */
  3425   4426       if (geom->first_polygon != NULL)
  3426         -	draw_polygons (ctx, handle, sym, height, minx, miny, x_res, y_res,
  3427         -		       geom);
         4427  +	draw_polygons (ctx, handle, sym, height, minx, miny, maxx, maxy,
         4428  +		       x_res, y_res, geom);
  3428   4429       if (geom->first_linestring != NULL)
  3429         -	draw_lines (ctx, handle, sym, height, minx, miny, x_res, y_res, geom);
         4430  +	draw_lines (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res,
         4431  +		    y_res, geom);
  3430   4432       if (geom->first_point != NULL)
  3431         -	draw_points (ctx, handle, sym, height, minx, miny, x_res, y_res, geom);
         4433  +	draw_points (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res,
         4434  +		     y_res, geom);
  3432   4435   
  3433   4436       if (sym != NULL)
  3434   4437         {
  3435   4438   	  /* then we'll render any eventual TextSymbolizer */
  3436   4439   	  item = sym->first;
  3437   4440   	  while (item != NULL)
  3438   4441   	    {
................................................................................
  3442   4445   		      rl2PrivTextSymbolizerPtr text =
  3443   4446   			  (rl2PrivTextSymbolizerPtr) (item->symbolizer);
  3444   4447   		      if (text->label != NULL)
  3445   4448   			{
  3446   4449   			    int v;
  3447   4450   			    rl2PrivVariantArrayPtr var =
  3448   4451   				(rl2PrivVariantArrayPtr) variant;
  3449         -			    for (v = 0; v < var->count; v++)
         4452  +			    if (var != NULL)
  3450   4453   			      {
  3451         -				  rl2PrivVariantValuePtr val =
  3452         -				      *(var->array + v);
  3453         -				  if (val == NULL)
  3454         -				      continue;
  3455         -				  if (val->column_name == NULL)
  3456         -				      continue;
  3457         -				  if (strcasecmp (text->label, val->column_name)
  3458         -				      != 0)
  3459         -				      continue;
  3460         -				  draw_labels (ctx, handle, text, height, minx,
  3461         -					       miny, x_res, y_res, geom, val);
         4454  +				  for (v = 0; v < var->count; v++)
         4455  +				    {
         4456  +					rl2PrivVariantValuePtr val =
         4457  +					    *(var->array + v);
         4458  +					if (val == NULL)
         4459  +					    continue;
         4460  +					if (val->column_name == NULL)
         4461  +					    continue;
         4462  +					if (strcasecmp
         4463  +					    (text->label,
         4464  +					     val->column_name) != 0)
         4465  +					    continue;
         4466  +/* to be fixed - sometimes it raises a Cairo exception about Fonts 
         4467  +					draw_labels (ctx, handle, priv_data,
         4468  +						     text, height, minx, miny,
         4469  +						     maxx, maxy, x_res, y_res,
         4470  +						     geom, val);
         4471  +
         4472  +*/
         4473  +				    }
  3462   4474   			      }
  3463   4475   			}
  3464   4476   		  }
  3465   4477   		item = item->next;
  3466   4478   	    }
  3467   4479         }
  3468   4480   
  3469   4481       if (default_symbolizer != NULL)
  3470   4482   	rl2_destroy_vector_symbolizer (default_symbolizer);
  3471   4483   }
         4484  +
         4485  +RL2_PRIVATE int
         4486  +rl2_aux_default_image (unsigned int width, unsigned int height,
         4487  +		       unsigned char red, unsigned char green,
         4488  +		       unsigned char blue, int format, int transparent,
         4489  +		       int quality, unsigned char **ximage, int *ximage_sz)
         4490  +{
         4491  +/* creating a default image */
         4492  +    unsigned int x;
         4493  +    unsigned int y;
         4494  +    unsigned char *pixels = malloc (width * height * 3);
         4495  +    unsigned char *po = pixels;
         4496  +    unsigned char *mask = NULL;
         4497  +    unsigned char *pm;
         4498  +
         4499  +    *ximage = NULL;
         4500  +    *ximage_sz = 0;
         4501  +    if (pixels == NULL)
         4502  +	return 0;
         4503  +
         4504  +    mask = malloc (width * height);
         4505  +    if (mask == NULL)
         4506  +	goto error;
         4507  +    pm = mask;
         4508  +
         4509  +/* priming the image buffer to background color */
         4510  +    for (y = 0; y < height; y++)
         4511  +      {
         4512  +	  for (x = 0; x < width; x++)
         4513  +	    {
         4514  +		*po++ = red;
         4515  +		*po++ = green;
         4516  +		*po++ = blue;
         4517  +		if (mask != NULL)
         4518  +		    *pm++ = 0;
         4519  +	    }
         4520  +      }
         4521  +
         4522  +    if (format == RL2_OUTPUT_FORMAT_PNG)
         4523  +      {
         4524  +	  if (transparent)
         4525  +	    {
         4526  +		if (rl2_rgb_alpha_to_png
         4527  +		    (width, height, pixels, mask, ximage, ximage_sz,
         4528  +		     1.0) != RL2_OK)
         4529  +		    goto error;
         4530  +	    }
         4531  +	  else
         4532  +	    {
         4533  +		if (rl2_rgb_to_png (width, height, pixels, ximage, ximage_sz)
         4534  +		    != RL2_OK)
         4535  +		    goto error;
         4536  +	    }
         4537  +      }
         4538  +    else if (format == RL2_OUTPUT_FORMAT_JPEG)
         4539  +      {
         4540  +	  if (rl2_rgb_to_jpeg
         4541  +	      (width, height, pixels, quality, ximage, ximage_sz) != RL2_OK)
         4542  +	      goto error;
         4543  +      }
         4544  +    else if (format == RL2_OUTPUT_FORMAT_TIFF)
         4545  +      {
         4546  +	  if (rl2_rgb_to_tiff (width, height, pixels, ximage, ximage_sz) !=
         4547  +	      RL2_OK)
         4548  +	      goto error;
         4549  +      }
         4550  +    else
         4551  +	goto error;
         4552  +    free (pixels);
         4553  +    if (mask != NULL)
         4554  +	free (mask);
         4555  +    return 1;
         4556  +
         4557  +  error:
         4558  +    if (pixels != NULL)
         4559  +	free (pixels);
         4560  +    if (mask != NULL)
         4561  +	free (mask);
         4562  +    return 0;
         4563  +}

Changes to src/rl2charls.c.

    52     52   #endif
    53     53   
    54     54   #include "rasterlite2/rasterlite2.h"
    55     55   #include "rasterlite2_private.h"
    56     56   
    57     57   #ifndef OMIT_CHARLS		/* only if CharLS is enabled */
    58     58   
           59  +#ifdef __ANDROID__		/* Android specific */
           60  +#include <interface.h>
           61  +#else
    59     62   #include <CharLS/interface.h>
           63  +#endif
    60     64   
    61     65   static int
    62     66   endianness ()
    63     67   {
    64     68   /* checking if target CPU is a little-endian one */
    65     69       union cvt
    66     70       {
................................................................................
   278    282   		      p_out += num_bands;
   279    283   		  }
   280    284   	    }
   281    285         }
   282    286   }
   283    287   
   284    288   static void
   285         -from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width, int height,
   286         -		   int num_bands)
          289  +from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width,
          290  +		   int height, int num_bands)
   287    291   {
   288    292   /* rearranging pixels from separate LINE components - UINT 8 */
   289    293       int x;
   290    294       int y;
   291    295       int ib;
   292    296       unsigned char *p_in = in;
   293    297   
................................................................................
   449    453         {
   450    454   	  if (*sample_type == RL2_SAMPLE_UINT16)
   451    455   	      from_ilv_buffer_16 ((unsigned short *) (*pixels),
   452    456   				  (unsigned short *) out_buffer, *width,
   453    457   				  *height, *num_bands);
   454    458   	  else
   455    459   	      from_ilv_buffer_8 ((unsigned char *) (*pixels),
   456         -				 (unsigned char *) out_buffer, *width, *height,
   457         -				 *num_bands);
          460  +				 (unsigned char *) out_buffer, *width,
          461  +				 *height, *num_bands);
   458    462         }
   459    463       free (out_buffer);
   460    464       return RL2_OK;
   461    465   
   462    466     error:
   463    467       if (out_buffer != NULL)
   464    468   	free (out_buffer);
   465    469       return RL2_ERROR;
   466    470   }
   467    471   
   468    472   #endif /* end CharLS conditional */

Changes to src/rl2codec.c.

  2018   2018       *pixels_even = pix_even;
  2019   2019       *size_odd = o_size;
  2020   2020       *size_even = e_size;
  2021   2021       return 1;
  2022   2022   }
  2023   2023   
  2024   2024   RL2_DECLARE int
  2025         -rl2_raster_encode (rl2RasterPtr rst, int compression, unsigned char **blob_odd,
  2026         -		   int *blob_odd_sz, unsigned char **blob_even,
  2027         -		   int *blob_even_sz, int quality, int little_endian)
         2025  +rl2_raster_encode (rl2RasterPtr rst, int compression,
         2026  +		   unsigned char **blob_odd, int *blob_odd_sz,
         2027  +		   unsigned char **blob_even, int *blob_even_sz, int quality,
         2028  +		   int little_endian)
  2028   2029   {
  2029   2030   /* encoding a Raster into the internal RL2 binary format */
  2030   2031       rl2PrivRasterPtr raster = (rl2PrivRasterPtr) rst;
  2031   2032       int odd_rows;
  2032   2033       unsigned char *pixels_odd = NULL;
  2033   2034       int size_odd;
  2034   2035       int even_rows = 0;
................................................................................
  2122   2123   	|| compression == RL2_COMPRESSION_LZMA_NO)
  2123   2124         {
  2124   2125   	  /* preparing the pixels buffers */
  2125   2126   	  if (raster->sampleType == RL2_SAMPLE_1_BIT)
  2126   2127   	    {
  2127   2128   		/* packing 1-BIT data */
  2128   2129   		if (!pack_1bit_rows
  2129         -		    (raster, raster->rasterBuffer, &row_stride_odd, &pixels_odd,
  2130         -		     &size_odd))
         2130  +		    (raster, raster->rasterBuffer, &row_stride_odd,
         2131  +		     &pixels_odd, &size_odd))
  2131   2132   		    return RL2_ERROR;
  2132   2133   		odd_rows = raster->height;
  2133   2134   	    }
  2134   2135   	  else if (raster->sampleType == RL2_SAMPLE_2_BIT)
  2135   2136   	    {
  2136   2137   		/* packing 2-BIT data */
  2137   2138   		if (!pack_2bit_rows
................................................................................
  2147   2148   		    return RL2_ERROR;
  2148   2149   		odd_rows = raster->height;
  2149   2150   	    }
  2150   2151   	  else
  2151   2152   	    {
  2152   2153   		/* Odd/Even raster */
  2153   2154   		if (!odd_even_rows
  2154         -		    (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd,
  2155         -		     &even_rows, &row_stride_even, &pixels_even, &size_even,
  2156         -		     little_endian))
         2155  +		    (raster, &odd_rows, &row_stride_odd, &pixels_odd,
         2156  +		     &size_odd, &even_rows, &row_stride_even, &pixels_even,
         2157  +		     &size_even, little_endian))
  2157   2158   		    return RL2_ERROR;
  2158   2159   	    }
  2159   2160         }
  2160   2161       else if (compression == RL2_COMPRESSION_PNG)
  2161   2162         {
  2162   2163   	  if (raster->sampleType == RL2_SAMPLE_1_BIT
  2163   2164   	      || raster->sampleType == RL2_SAMPLE_2_BIT
................................................................................
  2165   2166   	    {
  2166   2167   		/* no special action is required */
  2167   2168   	    }
  2168   2169   	  else
  2169   2170   	    {
  2170   2171   		/* Odd/Even raster */
  2171   2172   		if (!odd_even_rows
  2172         -		    (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd,
  2173         -		     &even_rows, &row_stride_even, &pixels_even, &size_even,
  2174         -		     little_endian))
         2173  +		    (raster, &odd_rows, &row_stride_odd, &pixels_odd,
         2174  +		     &size_odd, &even_rows, &row_stride_even, &pixels_even,
         2175  +		     &size_even, little_endian))
  2175   2176   		    return RL2_ERROR;
  2176   2177   	    }
  2177   2178         }
  2178   2179       else if (compression == RL2_COMPRESSION_CHARLS)
  2179   2180         {
  2180   2181   	  /* Odd/Even raster */
  2181   2182   	  if (!odd_even_rows
................................................................................
  2467   2468   	  goto error;
  2468   2469   #endif /* end WebP conditional */
  2469   2470         }
  2470   2471       else if (compression == RL2_COMPRESSION_LOSSY_WEBP)
  2471   2472         {
  2472   2473   #ifndef OMIT_WEBP		/* only if WebP is enabled */
  2473   2474   	  /* compressing as lossy WEBP */
  2474         -	  if (rl2_raster_to_lossy_webp (rst, &compr_data, &compressed, quality)
  2475         -	      == RL2_OK)
         2475  +	  if (rl2_raster_to_lossy_webp
         2476  +	      (rst, &compr_data, &compressed, quality) == RL2_OK)
  2476   2477   	    {
  2477   2478   		/* ok, lossy WEBP compression was successful */
  2478   2479   		uncompressed = raster->width * raster->height * raster->nBands;
  2479   2480   		to_clean1 = compr_data;
  2480   2481   	    }
  2481   2482   	  else
  2482   2483   	      goto error;
................................................................................
  2587   2588   	  else
  2588   2589   	      goto error;
  2589   2590         }
  2590   2591       else if (compression == RL2_COMPRESSION_LOSSLESS_JP2)
  2591   2592         {
  2592   2593   #ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
  2593   2594   	  /* compressing as lossless Jpeg2000 */
  2594         -	  if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed) ==
  2595         -	      RL2_OK)
         2595  +	  if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed)
         2596  +	      == RL2_OK)
  2596   2597   	    {
  2597   2598   		/* ok, lossless Jpeg2000 compression was successful */
  2598   2599   		uncompressed = raster->width * raster->height * raster->nBands;
  2599   2600   		to_clean1 = compr_data;
  2600   2601   	    }
  2601   2602   	  else
  2602   2603   	      goto error;
................................................................................
  2719   2720   		      compressed = (int) zLen;
  2720   2721   		      compr_data = zip_buf;
  2721   2722   		      to_clean2 = zip_buf;
  2722   2723   		  }
  2723   2724   		else if (ret == Z_BUF_ERROR)
  2724   2725   		  {
  2725   2726   		      /* ZIP compression actually causes inflation: saving uncompressed data */
  2726         -		      if (rl2_delta_decode (pixels_even, size_even, delta_dist)
  2727         -			  != RL2_OK)
         2727  +		      if (rl2_delta_decode
         2728  +			  (pixels_even, size_even, delta_dist) != RL2_OK)
  2728   2729   			  goto error;
  2729   2730   		      uncompressed = size_even;
  2730   2731   		      compressed = size_even;
  2731   2732   		      compr_data = pixels_even;
  2732   2733   		      free (zip_buf);
  2733   2734   		      zip_buf = NULL;
  2734   2735   		  }
................................................................................
  3129   3130       *xnum_bands = num_bands;
  3130   3131       *xcompression = compression;
  3131   3132       *xcrc = crc;
  3132   3133       return 1;
  3133   3134   }
  3134   3135   
  3135   3136   static int
  3136         -check_blob_even (const unsigned char *blob, int blob_sz, unsigned short xwidth,
  3137         -		 unsigned short xheight, unsigned char xsample_type,
  3138         -		 unsigned char xpixel_type, unsigned char xnum_bands,
  3139         -		 unsigned char xcompression, uLong xcrc)
         3137  +check_blob_even (const unsigned char *blob, int blob_sz,
         3138  +		 unsigned short xwidth, unsigned short xheight,
         3139  +		 unsigned char xsample_type, unsigned char xpixel_type,
         3140  +		 unsigned char xnum_bands, unsigned char xcompression,
         3141  +		 uLong xcrc)
  3140   3142   {
  3141   3143   /* checking the EvenBlock for validity */
  3142   3144       const unsigned char *ptr;
  3143   3145       unsigned short width;
  3144   3146       unsigned short height;
  3145   3147       unsigned char sample_type;
  3146   3148       unsigned char pixel_type;
................................................................................
  3214   3216   check_scale (int scale, unsigned char sample_type, unsigned char compression,
  3215   3217   	     const unsigned char *blob_even)
  3216   3218   {
  3217   3219   /* checking if the encoded raster could be decoded at given scale */
  3218   3220       switch (scale)
  3219   3221         {
  3220   3222         case RL2_SCALE_1:
  3221         -	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT
         3223  +	  if (sample_type == RL2_SAMPLE_1_BIT
         3224  +	      || sample_type == RL2_SAMPLE_2_BIT
  3222   3225   	      || sample_type == RL2_SAMPLE_4_BIT)
  3223   3226   	      ;
  3224   3227   	  else if (compression == RL2_COMPRESSION_JPEG
  3225   3228   		   || compression == RL2_COMPRESSION_LOSSY_WEBP
  3226   3229   		   || compression == RL2_COMPRESSION_LOSSLESS_WEBP
  3227   3230   		   || compression == RL2_COMPRESSION_CCITTFAX4
  3228   3231   		   || compression == RL2_COMPRESSION_LOSSY_JP2
................................................................................
  3230   3233   	    {
  3231   3234   		if (blob_even != NULL)
  3232   3235   		    return 0;
  3233   3236   	    }
  3234   3237   	  else if (blob_even == NULL)
  3235   3238   	      return 0;
  3236   3239   	  break;
         3240  +      case RL2_SCALE_2:
         3241  +      case RL2_SCALE_4:
         3242  +      case RL2_SCALE_8:
         3243  +	  break;
         3244  +      default:
         3245  +	  return 0;
         3246  +      };
         3247  +    switch (sample_type)
         3248  +      {
         3249  +      case RL2_SAMPLE_1_BIT:
         3250  +      case RL2_SAMPLE_2_BIT:
         3251  +      case RL2_SAMPLE_4_BIT:
         3252  +	  if (scale != RL2_SCALE_1)
         3253  +	      return 0;
         3254  +	  break;
         3255  +      };
         3256  +    return 1;
         3257  +}
         3258  +
         3259  +static int
         3260  +check_scale2 (int scale, unsigned char sample_type)
         3261  +{
         3262  +/* checking if the encoded raster could be decoded at given scale */
         3263  +    switch (scale)
         3264  +      {
         3265  +      case RL2_SCALE_1:
  3237   3266         case RL2_SCALE_2:
  3238   3267         case RL2_SCALE_4:
  3239   3268         case RL2_SCALE_8:
  3240   3269   	  break;
  3241   3270         default:
  3242   3271   	  return 0;
  3243   3272         };
................................................................................
  4190   4219   		else
  4191   4220   		    *p_out++ = *p_even++;
  4192   4221   	    }
  4193   4222         }
  4194   4223   }
  4195   4224   
  4196   4225   static void
  4197         -do_copy_uint32 (int swap, const unsigned int *p_odd, const unsigned int *p_even,
  4198         -		unsigned int *buf, unsigned short width,
  4199         -		unsigned short odd_rows, unsigned short even_rows)
         4226  +do_copy_uint32 (int swap, const unsigned int *p_odd,
         4227  +		const unsigned int *p_even, unsigned int *buf,
         4228  +		unsigned short width, unsigned short odd_rows,
         4229  +		unsigned short even_rows)
  4200   4230   {
  4201   4231   /* reassembling an UINT32 raster - scale 1:1 */
  4202   4232       int row;
  4203   4233       int col;
  4204   4234       unsigned int *p_out;
  4205   4235   
  4206   4236       p_out = buf;
................................................................................
  4878   4908       return 1;
  4879   4909   }
  4880   4910   
  4881   4911   RL2_DECLARE int
  4882   4912   rl2_is_valid_dbms_raster_tile (unsigned short level, unsigned int tile_width,
  4883   4913   			       unsigned int tile_height,
  4884   4914   			       const unsigned char *blob_odd, int blob_odd_sz,
  4885         -			       const unsigned char *blob_even, int blob_even_sz,
  4886         -			       unsigned char sample_type,
         4915  +			       const unsigned char *blob_even,
         4916  +			       int blob_even_sz, unsigned char sample_type,
  4887   4917   			       unsigned char pixel_type,
  4888   4918   			       unsigned char num_bands,
  4889   4919   			       unsigned char compression)
  4890   4920   {
  4891   4921   /* testing a serialized Raster Tile object for validity */
  4892   4922       unsigned int width;
  4893   4923       unsigned int height;
................................................................................
  4937   4967   	    {
  4938   4968   		/* small-PALETTE: expecting an RGB/PNG Pyramid tile */
  4939   4969   		if (xsample_type == RL2_SAMPLE_UINT8
  4940   4970   		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
  4941   4971   		    && xcompression == RL2_COMPRESSION_PNG)
  4942   4972   		    return RL2_OK;
  4943   4973   	    }
  4944         -	  if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE
  4945         -	      && num_bands == 1)
         4974  +	  if (sample_type == RL2_SAMPLE_UINT8
         4975  +	      && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1)
  4946   4976   	    {
  4947   4977   		/* PALETTE 8bits: expecting an RGB/PNG Pyramid tile */
  4948   4978   		if (xsample_type == RL2_SAMPLE_UINT8
  4949   4979   		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
  4950   4980   		    && xcompression == RL2_COMPRESSION_PNG)
  4951   4981   		    return RL2_OK;
  4952   4982   	    }
................................................................................
  5010   5040       if (!check_blob_odd
  5011   5041   	(blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type,
  5012   5042   	 &num_bands, &compression, &crc))
  5013   5043   	return NULL;
  5014   5044       if (blob_even != NULL)
  5015   5045         {
  5016   5046   	  if (!check_blob_even
  5017         -	      (blob_even, blob_even_sz, width, height, sample_type, pixel_type,
  5018         -	       num_bands, compression, crc))
         5047  +	      (blob_even, blob_even_sz, width, height, sample_type,
         5048  +	       pixel_type, num_bands, compression, crc))
  5019   5049   	      return NULL;
  5020   5050         }
  5021   5051       if (!check_scale (scale, sample_type, compression, blob_even))
  5022   5052   	return NULL;
  5023   5053   
  5024   5054       switch (pixel_type)
  5025   5055         {
................................................................................
  5146   5176   		const Bytef *in = pixels_even;
  5147   5177   		even_data = malloc (uncompressed_even);
  5148   5178   		if (even_data == NULL)
  5149   5179   		    goto error;
  5150   5180   		if (uncompress (even_data, &refLen, in, compressed_even) !=
  5151   5181   		    Z_OK)
  5152   5182   		    goto error;
  5153         -		if (rl2_delta_decode (even_data, uncompressed_even, delta_dist)
  5154         -		    != RL2_OK)
         5183  +		if (rl2_delta_decode
         5184  +		    (even_data, uncompressed_even, delta_dist) != RL2_OK)
  5155   5185   		    goto error;
  5156   5186   		pixels_even = even_data;
  5157   5187   	    }
  5158   5188         }
  5159   5189       if (compression == RL2_COMPRESSION_DEFLATE_NO
  5160   5190   	&& uncompressed_odd != compressed_odd)
  5161   5191         {
................................................................................
  5304   5334   	  int ret = RL2_ERROR;
  5305   5335   	  unsigned char pix_typ;
  5306   5336   	  switch (scale)
  5307   5337   	    {
  5308   5338   	    case RL2_SCALE_1:
  5309   5339   		ret =
  5310   5340   		    rl2_decode_jpeg_scaled (1, pixels_odd, compressed_odd,
  5311         -					    &width, &height, &pix_typ, &pixels,
  5312         -					    &pixels_sz);
         5341  +					    &width, &height, &pix_typ,
         5342  +					    &pixels, &pixels_sz);
  5313   5343   		break;
  5314   5344   	    case RL2_SCALE_2:
  5315   5345   		ret =
  5316   5346   		    rl2_decode_jpeg_scaled (2, pixels_odd, compressed_odd,
  5317         -					    &width, &height, &pix_typ, &pixels,
  5318         -					    &pixels_sz);
         5347  +					    &width, &height, &pix_typ,
         5348  +					    &pixels, &pixels_sz);
  5319   5349   		break;
  5320   5350   	    case RL2_SCALE_4:
  5321   5351   		ret =
  5322   5352   		    rl2_decode_jpeg_scaled (4, pixels_odd, compressed_odd,
  5323         -					    &width, &height, &pix_typ, &pixels,
  5324         -					    &pixels_sz);
         5353  +					    &width, &height, &pix_typ,
         5354  +					    &pixels, &pixels_sz);
  5325   5355   		break;
  5326   5356   	    case RL2_SCALE_8:
  5327   5357   		ret =
  5328   5358   		    rl2_decode_jpeg_scaled (8, pixels_odd, compressed_odd,
  5329         -					    &width, &height, &pix_typ, &pixels,
  5330         -					    &pixels_sz);
         5359  +					    &width, &height, &pix_typ,
         5360  +					    &pixels, &pixels_sz);
  5331   5361   		break;
  5332   5362   	    };
  5333   5363   	  if (ret != RL2_OK)
  5334   5364   	      goto error;
  5335   5365   	  goto done;
  5336   5366         }
  5337   5367       if (compression == RL2_COMPRESSION_LOSSY_WEBP
................................................................................
  5380   5410   	  goto error;
  5381   5411   #endif /* end WebP conditional */
  5382   5412         }
  5383   5413       if (compression == RL2_COMPRESSION_PNG)
  5384   5414         {
  5385   5415   	  /* decompressing from PNG */
  5386   5416   	  int ret;
  5387         -	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT
         5417  +	  if (sample_type == RL2_SAMPLE_1_BIT
         5418  +	      || sample_type == RL2_SAMPLE_2_BIT
  5388   5419   	      || sample_type == RL2_SAMPLE_4_BIT)
  5389   5420   	    {
  5390   5421   		/* Palette or Grayscale - 1,2 or 4 bit isn't scalable */
  5391   5422   		if (scale != RL2_SCALE_1)
  5392   5423   		    goto error;
  5393   5424   		ret =
  5394   5425   		    rl2_decode_png (pixels_odd, compressed_odd,
  5395         -				    &width, &height, &sample_type, &pixel_type,
  5396         -				    &num_bands, &pixels, &pixels_sz, &mask,
  5397         -				    &mask_sz, &palette, 0);
         5426  +				    &width, &height, &sample_type,
         5427  +				    &pixel_type, &num_bands, &pixels,
         5428  +				    &pixels_sz, &mask, &mask_sz, &palette, 0);
  5398   5429   		if (ret != RL2_OK)
  5399   5430   		    goto error;
  5400   5431   		goto done;
  5401   5432   	    }
  5402   5433   	  else
  5403   5434   	    {
  5404   5435   		ret = rl2_decode_png (pixels_odd, compressed_odd,
................................................................................
  5409   5440   		if (ret != RL2_OK)
  5410   5441   		    goto error;
  5411   5442   		pixels_odd = odd_data;
  5412   5443   		if (scale == RL2_SCALE_1)
  5413   5444   		  {
  5414   5445   		      ret = rl2_decode_png (pixels_even, compressed_even,
  5415   5446   					    &width, &even_rows, &sample_type,
  5416         -					    &pixel_type, &num_bands, &even_data,
  5417         -					    &pixels_sz, &even_mask,
  5418         -					    &even_mask_sz, &palette2, 0);
         5447  +					    &pixel_type, &num_bands,
         5448  +					    &even_data, &pixels_sz,
         5449  +					    &even_mask, &even_mask_sz,
         5450  +					    &palette2, 0);
  5419   5451   		      if (ret != RL2_OK)
  5420   5452   			  goto error;
  5421   5453   		      rl2_destroy_palette (palette2);
  5422   5454   		  }
  5423   5455   		pixels_even = even_data;
  5424   5456   		if (odd_mask != NULL)
  5425   5457   		    free (odd_mask);
................................................................................
  5482   5514   	  int ret = RL2_ERROR;
  5483   5515   	  switch (scale)
  5484   5516   	    {
  5485   5517   	    case RL2_SCALE_1:
  5486   5518   		ret =
  5487   5519   		    rl2_decode_jpeg2000_scaled (1, pixels_odd, compressed_odd,
  5488   5520   						&width, &height, sample_type,
  5489         -						pixel_type, num_bands, &pixels,
  5490         -						&pixels_sz);
         5521  +						pixel_type, num_bands,
         5522  +						&pixels, &pixels_sz);
  5491   5523   		break;
  5492   5524   	    case RL2_SCALE_2:
  5493   5525   		ret =
  5494   5526   		    rl2_decode_jpeg2000_scaled (2, pixels_odd, compressed_odd,
  5495   5527   						&width, &height, sample_type,
  5496         -						pixel_type, num_bands, &pixels,
  5497         -						&pixels_sz);
         5528  +						pixel_type, num_bands,
         5529  +						&pixels, &pixels_sz);
  5498   5530   		break;
  5499   5531   	    case RL2_SCALE_4:
  5500   5532   		ret =
  5501   5533   		    rl2_decode_jpeg2000_scaled (4, pixels_odd, compressed_odd,
  5502   5534   						&width, &height, sample_type,
  5503         -						pixel_type, num_bands, &pixels,
  5504         -						&pixels_sz);
         5535  +						pixel_type, num_bands,
         5536  +						&pixels, &pixels_sz);
  5505   5537   		break;
  5506   5538   	    case RL2_SCALE_8:
  5507   5539   		ret =
  5508   5540   		    rl2_decode_jpeg2000_scaled (8, pixels_odd, compressed_odd,
  5509   5541   						&width, &height, sample_type,
  5510         -						pixel_type, num_bands, &pixels,
  5511         -						&pixels_sz);
         5542  +						pixel_type, num_bands,
         5543  +						&pixels, &pixels_sz);
  5512   5544   		break;
  5513   5545   	    };
  5514   5546   	  if (ret != RL2_OK)
  5515   5547   	      goto error;
  5516   5548   	  goto done;
  5517   5549   #else /* OpenJpeg is disabled */
  5518   5550   	  fprintf (stderr,
................................................................................
  5558   5590         {
  5559   5591   	  /* unpacking the mask */
  5560   5592   	  unsigned char *mask_pix;
  5561   5593   	  int mask_pix_sz;
  5562   5594   	  if (uncompressed_mask != (mask_width * mask_height))
  5563   5595   	      goto error;
  5564   5596   	  if (!unpack_rle
  5565         -	      (mask_width, mask_height, pixels_mask, compressed_mask, &mask_pix,
  5566         -	       &mask_pix_sz))
         5597  +	      (mask_width, mask_height, pixels_mask, compressed_mask,
         5598  +	       &mask_pix, &mask_pix_sz))
  5567   5599   	      goto error;
  5568   5600   	  if (!rescale_mask
  5569   5601   	      (scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz))
  5570   5602   	    {
  5571   5603   		free (mask_pix);
  5572   5604   		goto error;
  5573   5605   	    }
................................................................................
  5609   5641   	free (mask);
  5610   5642       if (palette != NULL)
  5611   5643   	rl2_destroy_palette (palette);
  5612   5644       if (ext_palette != NULL)
  5613   5645   	rl2_destroy_palette (ext_palette);
  5614   5646       return NULL;
  5615   5647   }
         5648  +
         5649  +RL2_PRIVATE rl2RasterPtr
         5650  +rl2_raster_decode_mask (int scale, const unsigned char *blob_odd,
         5651  +			int blob_odd_sz, int *status)
         5652  +{
         5653  +/* decoding from internal RL2 binary format to Raster - transparency mask only */
         5654  +    rl2RasterPtr raster;
         5655  +    unsigned int width;
         5656  +    unsigned int height;
         5657  +    unsigned short mask_width = 0;
         5658  +    unsigned short mask_height = 0;
         5659  +    unsigned char sample_type;
         5660  +    unsigned char pixel_type;
         5661  +    unsigned char num_bands;
         5662  +    unsigned char compression;
         5663  +    int compressed_odd;
         5664  +    int uncompressed_mask;
         5665  +    int compressed_mask;
         5666  +    uLong crc;
         5667  +    const unsigned char *pixels_mask = NULL;
         5668  +    unsigned char *pixels = NULL;
         5669  +    int pixels_sz;
         5670  +    unsigned char *mask = NULL;
         5671  +    int mask_sz = 0;
         5672  +    const unsigned char *ptr;
         5673  +    int endian;
         5674  +    int endian_arch = endianArch ();
         5675  +
         5676  +    *status = RL2_ERROR;
         5677  +    if (blob_odd == NULL)
         5678  +	return NULL;
         5679  +    if (!check_blob_odd
         5680  +	(blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type,
         5681  +	 &num_bands, &compression, &crc))
         5682  +	return NULL;
         5683  +    if (!check_scale2 (scale, sample_type))
         5684  +	return NULL;
         5685  +
         5686  +    endian = *(blob_odd + 2);
         5687  +    num_bands = *(blob_odd + 6);
         5688  +    ptr = blob_odd + 11;
         5689  +    ptr += 2;
         5690  +    ptr += 2;
         5691  +    ptr += 4;
         5692  +    compressed_odd = importU32 (ptr, endian, endian_arch);
         5693  +    ptr += 4;
         5694  +    uncompressed_mask = importU32 (ptr, endian, endian_arch);
         5695  +    ptr += 4;
         5696  +    compressed_mask = importU32 (ptr, endian, endian_arch);
         5697  +    ptr += 4;
         5698  +    if (*ptr++ != RL2_DATA_START)
         5699  +	return NULL;
         5700  +    if (uncompressed_mask > 0)
         5701  +      {
         5702  +	  /* retrieving the mask */
         5703  +	  ptr += compressed_odd;
         5704  +	  if (*ptr++ != RL2_DATA_END)
         5705  +	      return NULL;
         5706  +	  if (*ptr++ != RL2_MASK_START)
         5707  +	      return NULL;
         5708  +	  pixels_mask = ptr;
         5709  +	  mask_width = width;
         5710  +	  mask_height = height;
         5711  +	  ptr += compressed_mask;
         5712  +	  if (*ptr++ != RL2_MASK_END)
         5713  +	      return NULL;
         5714  +      }
         5715  +
         5716  +    if (pixels_mask == NULL)
         5717  +      {
         5718  +	  /* not existing Mask - not an error */
         5719  +	  *status = RL2_OK;
         5720  +	  return NULL;
         5721  +      }
         5722  +
         5723  +    /* unpacking the mask */
         5724  +    unsigned char *mask_pix;
         5725  +    int mask_pix_sz;
         5726  +    if (uncompressed_mask != (mask_width * mask_height))
         5727  +	goto error;
         5728  +    if (!unpack_rle
         5729  +	(mask_width, mask_height, pixels_mask, compressed_mask,
         5730  +	 &mask_pix, &mask_pix_sz))
         5731  +	goto error;
         5732  +    if (!rescale_mask
         5733  +	(scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz))
         5734  +      {
         5735  +	  free (mask_pix);
         5736  +	  goto error;
         5737  +      }
         5738  +    free (mask_pix);
         5739  +
         5740  +    /* will always return a full BLACK grayscale UINT8 raster */
         5741  +    pixels_sz = width * height;
         5742  +    pixels = malloc (pixels_sz);
         5743  +    memset (pixels, 0, pixels_sz);
         5744  +    raster =
         5745  +	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
         5746  +			   1, pixels, pixels_sz, NULL, mask, mask_sz, NULL);
         5747  +    if (raster == NULL)
         5748  +	goto error;
         5749  +    *status = RL2_OK;
         5750  +    return raster;
         5751  +  error:
         5752  +    if (pixels != NULL)
         5753  +	free (pixels);
         5754  +    if (mask != NULL)
         5755  +	free (mask);
         5756  +    *status = RL2_ERROR;
         5757  +    return NULL;
         5758  +}
  5616   5759   
  5617   5760   static void
  5618   5761   add_pooled_variance (rl2PrivBandStatisticsPtr band_in,
  5619   5762   		     rl2PrivBandStatisticsPtr band_out, double count)
  5620   5763   {
  5621   5764   /* adding a Pooled Variance item */
  5622   5765       rl2PoolVariancePtr pool = malloc (sizeof (rl2PoolVariance));
................................................................................
  5883   6026         {
  5884   6027   	  ignore_no_data = 0;
  5885   6028   	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
  5886   6029   	      != RL2_OK)
  5887   6030   	      ignore_no_data = 1;
  5888   6031   	  if (nbands != num_bands)
  5889   6032   	      ignore_no_data = 1;
  5890         -	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT
         6033  +	  if (sample_type == RL2_SAMPLE_1_BIT
         6034  +	      || sample_type == RL2_SAMPLE_2_BIT
  5891   6035   	      || sample_type == RL2_SAMPLE_4_BIT
  5892   6036   	      || sample_type == RL2_SAMPLE_UINT8)
  5893   6037   	      ;
  5894   6038   	  else
  5895   6039   	      ignore_no_data = 1;
  5896   6040         }
  5897   6041   
................................................................................
  6493   6637   	    }
  6494   6638         }
  6495   6639       compute_int32_histogram (width, height, pixels, mask, st, no_data);
  6496   6640   }
  6497   6641   
  6498   6642   static void
  6499   6643   compute_uint32_histogram (unsigned short width, unsigned short height,
  6500         -			  const unsigned int *pixels, const unsigned char *mask,
         6644  +			  const unsigned int *pixels,
         6645  +			  const unsigned char *mask,
  6501   6646   			  rl2PrivRasterStatisticsPtr st, rl2PixelPtr no_data)
  6502   6647   {
  6503   6648   /* computing INT16 tile histogram */
  6504   6649       int x;
  6505   6650       int y;
  6506   6651       const unsigned int *p_in = pixels;
  6507   6652       const unsigned char *p_msk = mask;

Changes to src/rl2dbms.c.

    75     75   			      unsigned char sample, unsigned char pixel,
    76     76   			      unsigned char num_bands,
    77     77   			      unsigned char compression, int quality,
    78     78   			      unsigned int tile_width,
    79     79   			      unsigned int tile_height, int srid,
    80     80   			      double x_res, double y_res,
    81     81   			      unsigned char *blob, int blob_sz,
    82         -			      unsigned char *blob_no_data, int blob_no_data_sz,
    83         -			      int strict_resolution, int mixed_resolutions,
    84         -			      int section_paths, int section_md5,
    85         -			      int section_summary)
           82  +			      unsigned char *blob_no_data,
           83  +			      int blob_no_data_sz, int strict_resolution,
           84  +			      int mixed_resolutions, int section_paths,
           85  +			      int section_md5, int section_summary)
    86     86   {
    87     87   /* inserting into "raster_coverages" */
    88     88       int ret;
    89     89       char *sql;
    90     90       sqlite3_stmt *stmt;
    91     91       const char *xsample = "UNKNOWN";
    92     92       const char *xpixel = "UNKNOWN";
................................................................................
   276    276   			   "\ty_resolution_1_4 DOUBLE,\n"
   277    277   			   "\tx_resolution_1_8 DOUBLE,\n"
   278    278   			   "\ty_resolution_1_8 DOUBLE)\n", xxcoverage);
   279    279       ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
   280    280       sqlite3_free (sql);
   281    281       if (ret != SQLITE_OK)
   282    282         {
   283         -	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage,
   284         -		   sql_err);
          283  +	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n",
          284  +		   xxcoverage, sql_err);
   285    285   	  sqlite3_free (sql_err);
   286    286   	  free (xxcoverage);
   287    287   	  return 0;
   288    288         }
   289    289       free (xxcoverage);
   290    290       return 1;
   291    291   }
................................................................................
   336    336       ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
   337    337       sqlite3_free (sql);
   338    338       free (xpk_name);
   339    339       free (xfk_name);
   340    340       free (xmother);
   341    341       if (ret != SQLITE_OK)
   342    342         {
   343         -	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage,
   344         -		   sql_err);
          343  +	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n",
          344  +		   xxcoverage, sql_err);
   345    345   	  sqlite3_free (sql_err);
   346    346   	  free (xxcoverage);
   347    347   	  return 0;
   348    348         }
   349    349       free (xxcoverage);
   350    350       return 1;
   351    351   }
................................................................................
  1244   1244       if (stmt != NULL)
  1245   1245   	sqlite3_finalize (stmt);
  1246   1246       return RL2_ERROR;
  1247   1247   }
  1248   1248   
  1249   1249   RL2_DECLARE int
  1250   1250   rl2_resolve_base_resolution_from_dbms (sqlite3 * handle, const char *coverage,
  1251         -				       int by_section, sqlite3_int64 section_id,
         1251  +				       int by_section,
         1252  +				       sqlite3_int64 section_id,
  1252   1253   				       double *x_res, double *y_res)
  1253   1254   {
  1254   1255   /* resolving the Base Resolution */
  1255   1256       int ret;
  1256   1257       char *sql;
  1257   1258       double xres;
  1258   1259       double yres;
................................................................................
  1439   1440       sqlite3_stmt *stmt = NULL;
  1440   1441   
  1441   1442       *duplicate = 0;
  1442   1443       table = sqlite3_mprintf ("%s_sections", coverage);
  1443   1444       xtable = rl2_double_quoted_sql (table);
  1444   1445       sqlite3_free (table);
  1445   1446       sql =
  1446         -	sqlite3_mprintf ("SELECT section_id FROM \"%s\" WHERE section_name = ?",
  1447         -			 xtable);
         1447  +	sqlite3_mprintf
         1448  +	("SELECT section_id FROM \"%s\" WHERE section_name = ?", xtable);
  1448   1449       free (xtable);
  1449   1450       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  1450   1451       sqlite3_free (sql);
  1451   1452       if (ret != SQLITE_OK)
  1452   1453         {
  1453   1454   	  printf ("SELECT section_id SQL error: %s\n", sqlite3_errmsg (handle));
  1454   1455   	  goto error;
................................................................................
  2386   2387   		  }
  2387   2388   		if (sqlite3_column_type (stmt, 15) == SQLITE_INTEGER)
  2388   2389   		  {
  2389   2390   		      section_summary = sqlite3_column_int (stmt, 15);
  2390   2391   		      ok_summary = 1;
  2391   2392   		  }
  2392   2393   		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
  2393         -		    && ok_quality && ok_tile_width && ok_tile_height && ok_x_res
  2394         -		    && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed
  2395         -		    && ok_paths && ok_md5 && ok_summary)
         2394  +		    && ok_quality && ok_tile_width && ok_tile_height
         2395  +		    && ok_x_res && ok_y_res && ok_srid && ok_nodata
         2396  +		    && ok_strict && ok_mixed && ok_paths && ok_md5
         2397  +		    && ok_summary)
  2396   2398   		    ok = 1;
  2397   2399   	    }
  2398   2400         }
  2399   2401       sqlite3_finalize (stmt);
  2400   2402   
  2401   2403       if (!ok)
  2402   2404         {
................................................................................
  2420   2422   	  fprintf (stderr,
  2421   2423   		   "ERROR: unable to Georeference a Coverage Object supporting \"%s\"\n",
  2422   2424   		   coverage);
  2423   2425   	  rl2_destroy_coverage (cvg);
  2424   2426   	  return NULL;
  2425   2427         }
  2426   2428       if (rl2_set_coverage_policies
  2427         -	(cvg, strict_resolution, mixed_resolutions, section_paths, section_md5,
  2428         -	 section_summary) != RL2_OK)
         2429  +	(cvg, strict_resolution, mixed_resolutions, section_paths,
         2430  +	 section_md5, section_summary) != RL2_OK)
  2429   2431         {
  2430   2432   	  fprintf (stderr,
  2431   2433   		   "ERROR: unable to set the Policies on the Coverage Object supporting \"%s\"\n",
  2432   2434   		   coverage);
  2433   2435   	  rl2_destroy_coverage (cvg);
  2434   2436   	  return NULL;
  2435   2437         }
................................................................................
  2533   2535   	      free (f_table_name);
  2534   2536   	  if (f_geometry_column != NULL)
  2535   2537   	      free (f_geometry_column);
  2536   2538   	  return NULL;
  2537   2539         }
  2538   2540   
  2539   2541       vector =
  2540         -	rl2_create_vector_layer (f_table_name, f_geometry_column, geometry_type,
  2541         -				 srid, spatial_index);
         2542  +	rl2_create_vector_layer (f_table_name, f_geometry_column,
         2543  +				 geometry_type, srid, spatial_index);
  2542   2544       free (f_table_name);
  2543   2545       free (f_geometry_column);
  2544   2546       if (vector == NULL)
  2545   2547         {
  2546   2548   	  fprintf (stderr,
  2547   2549   		   "ERROR: unable to create a Vector Layer Object supporting \"%s\"\n",
  2548   2550   		   coverage);
................................................................................
  2599   2601       if (!has_nodata)
  2600   2602         {
  2601   2603   	  for (y = 0; y < height; y++)
  2602   2604   	    {
  2603   2605   		for (x = 0; x < width; x++)
  2604   2606   		  {
  2605   2607   		      for (b = 0; b < num_bands; b++)
  2606         -			  *p++ = 0;
         2608  +			  *p++ = 255;
  2607   2609   		  }
  2608   2610   	    }
  2609   2611         }
  2610   2612       else
  2611   2613         {
  2612   2614   	  for (y = 0; y < height; y++)
  2613   2615   	    {
................................................................................
  2888   2890   }
  2889   2891   
  2890   2892   static void
  2891   2893   do_decode_tile (rl2AuxDecoderPtr decoder)
  2892   2894   {
  2893   2895   /* servicing an AuxDecoder Tile request */
  2894   2896       decoder->raster =
  2895         -	(rl2PrivRasterPtr) rl2_raster_decode (decoder->scale, decoder->blob_odd,
         2897  +	(rl2PrivRasterPtr) rl2_raster_decode (decoder->scale,
         2898  +					      decoder->blob_odd,
  2896   2899   					      decoder->blob_odd_sz,
  2897   2900   					      decoder->blob_even,
  2898   2901   					      decoder->blob_even_sz,
  2899   2902   					      (rl2PalettePtr)
  2900   2903   					      (decoder->palette));
  2901   2904       if (decoder->blob_odd != NULL)
  2902   2905   	free (decoder->blob_odd);
................................................................................
  2923   2926   	  decoder->retcode = RL2_ERROR;
  2924   2927   	  return;
  2925   2928         }
  2926   2929       rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
  2927   2930       decoder->raster = NULL;
  2928   2931       decoder->retcode = RL2_OK;
  2929   2932   }
         2933  +
         2934  +static void
         2935  +do_decode_masktile (rl2AuxMaskDecoderPtr decoder)
         2936  +{
         2937  +/* servicing an AuxMaskDecoder Tile request */
         2938  +    int status;
         2939  +    decoder->raster =
         2940  +	(rl2PrivRasterPtr) rl2_raster_decode_mask (decoder->scale,
         2941  +						   decoder->blob_odd,
         2942  +						   decoder->blob_odd_sz,
         2943  +						   &status);
         2944  +    if (decoder->blob_odd != NULL)
         2945  +	free (decoder->blob_odd);
         2946  +    decoder->blob_odd = NULL;
         2947  +    if (decoder->raster == NULL)
         2948  +      {
         2949  +	  decoder->retcode = status;
         2950  +	  return;
         2951  +      }
         2952  +    if (!rl2_copy_raw_mask
         2953  +	((rl2RasterPtr) (decoder->raster), decoder->maskbuf, decoder->width,
         2954  +	 decoder->height, decoder->x_res, decoder->y_res, decoder->minx,
         2955  +	 decoder->maxy, decoder->tile_minx, decoder->tile_maxy))
         2956  +      {
         2957  +	  decoder->retcode = RL2_ERROR;
         2958  +	  return;
         2959  +      }
         2960  +
         2961  +    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
         2962  +    decoder->raster = NULL;
         2963  +    decoder->retcode = RL2_OK;
         2964  +}
  2930   2965   
  2931   2966   #ifdef _WIN32
  2932   2967   DWORD WINAPI
  2933   2968   doRunDecoderThread (void *arg)
  2934   2969   #else
  2935   2970   void *
  2936   2971   doRunDecoderThread (void *arg)
................................................................................
  2937   2972   #endif
  2938   2973   {
  2939   2974   /* threaded function: decoding a Tile */
  2940   2975       rl2AuxDecoderPtr decoder = (rl2AuxDecoderPtr) arg;
  2941   2976       do_decode_tile (decoder);
  2942   2977   #ifdef _WIN32
  2943   2978       return 0;
         2979  +#else
         2980  +    pthread_exit (NULL);
         2981  +#endif
         2982  +}
         2983  +
         2984  +#ifdef _WIN32
         2985  +DWORD WINAPI
         2986  +doRunMaskDecoderThread (void *arg)
         2987  +#else
         2988  +void *
         2989  +doRunMaskDecoderThread (void *arg)
         2990  +#endif
         2991  +{
         2992  +/* threaded function: decoding a Tile */
         2993  +    rl2AuxMaskDecoderPtr decoder = (rl2AuxMaskDecoderPtr) arg;
         2994  +    do_decode_masktile (decoder);
         2995  +#ifdef _WIN32
         2996  +    return 0;
  2944   2997   #else
  2945   2998       pthread_exit (NULL);
  2946   2999   #endif
  2947   3000   }
  2948   3001   
  2949   3002   static void
  2950   3003   start_decoder_thread (rl2AuxDecoderPtr decoder)
................................................................................
  2986   3039   	    }
  2987   3040         }
  2988   3041       if (!ok_prior)
  2989   3042         {
  2990   3043   	  /* failure: using standard priority */
  2991   3044   	  pthread_create (&thread_id, NULL, doRunDecoderThread, decoder);
  2992   3045         }
         3046  +    p_thread = malloc (sizeof (pthread_t));
         3047  +    *p_thread = thread_id;
         3048  +    decoder->opaque_thread_id = p_thread;
         3049  +#endif
         3050  +}
         3051  +
         3052  +static void
         3053  +start_mask_decoder_thread (rl2AuxMaskDecoderPtr decoder)
         3054  +{
         3055  +/* starting a concurrent thread */
         3056  +#ifdef _WIN32
         3057  +    HANDLE thread_handle;
         3058  +    HANDLE *p_thread;
         3059  +    DWORD dwThreadId;
         3060  +    thread_handle =
         3061  +	CreateThread (NULL, 0, doRunMaskDecoderThread, decoder, 0, &dwThreadId);
         3062  +    SetThreadPriority (thread_handle, THREAD_PRIORITY_IDLE);
         3063  +    p_thread = malloc (sizeof (HANDLE));
         3064  +    *p_thread = thread_handle;
         3065  +    decoder->opaque_thread_id = p_thread;
         3066  +#else
         3067  +    pthread_t thread_id;
         3068  +    pthread_t *p_thread;
         3069  +    int ok_prior = 0;
         3070  +    int policy;
         3071  +    int min_prio;
         3072  +    pthread_attr_t attr;
         3073  +    struct sched_param sp;
         3074  +    pthread_attr_init (&attr);
         3075  +    if (pthread_attr_setschedpolicy (&attr, SCHED_RR) == 0)
         3076  +      {
         3077  +	  /* attempting to set the lowest priority */
         3078  +	  if (pthread_attr_getschedpolicy (&attr, &policy) == 0)
         3079  +	    {
         3080  +		min_prio = sched_get_priority_min (policy);
         3081  +		sp.sched_priority = min_prio;
         3082  +		if (pthread_attr_setschedparam (&attr, &sp) == 0)
         3083  +		  {
         3084  +		      /* ok, setting the lowest priority */
         3085  +		      ok_prior = 1;
         3086  +		      pthread_create (&thread_id, &attr, doRunMaskDecoderThread,
         3087  +				      decoder);
         3088  +		  }
         3089  +	    }
         3090  +      }
         3091  +    if (!ok_prior)
         3092  +      {
         3093  +	  /* failure: using standard priority */
         3094  +	  pthread_create (&thread_id, NULL, doRunMaskDecoderThread, decoder);
         3095  +      }
  2993   3096       p_thread = malloc (sizeof (pthread_t));
  2994   3097       *p_thread = thread_id;
  2995   3098       decoder->opaque_thread_id = p_thread;
  2996   3099   #endif
  2997   3100   }
  2998   3101   
  2999   3102   static int
................................................................................
  3070   3173   	    }
  3071   3174         }
  3072   3175       return 1;
  3073   3176   
  3074   3177     error:
  3075   3178       return 0;
  3076   3179   }
         3180  +
         3181  +static int
         3182  +do_run_mask_decoder_children (rl2AuxMaskDecoderPtr * thread_slots,
         3183  +			      int thread_count)
         3184  +{
         3185  +/* concurrent execution of all mask decoder children threads */
         3186  +    rl2AuxMaskDecoderPtr decoder;
         3187  +    int i;
         3188  +#ifdef _WIN32
         3189  +    HANDLE *handles;
         3190  +#endif
         3191  +
         3192  +    for (i = 0; i < thread_count; i++)
         3193  +      {
         3194  +	  /* starting all children threads */
         3195  +	  decoder = *(thread_slots + i);
         3196  +	  start_mask_decoder_thread (decoder);
         3197  +      }
         3198  +
         3199  +/* waiting until all child threads exit */
         3200  +#ifdef _WIN32
         3201  +    handles = malloc (sizeof (HANDLE) * thread_count);
         3202  +    for (i = 0; i < thread_count; i++)
         3203  +      {
         3204  +	  /* initializing the HANDLEs array */
         3205  +	  HANDLE *pOpaque;
         3206  +	  decoder = *(thread_slots + i);
         3207  +	  pOpaque = (HANDLE *) (decoder->opaque_thread_id);
         3208  +	  *(handles + i) = *pOpaque;
         3209  +      }
         3210  +    WaitForMultipleObjects (thread_count, handles, TRUE, INFINITE);
         3211  +    free (handles);
         3212  +#else
         3213  +    for (i = 0; i < thread_count; i++)
         3214  +      {
         3215  +	  pthread_t *pOpaque;
         3216  +	  decoder = *(thread_slots + i);
         3217  +	  pOpaque = (pthread_t *) (decoder->opaque_thread_id);
         3218  +	  pthread_join (*pOpaque, NULL);
         3219  +      }
         3220  +#endif
         3221  +
         3222  +/* all children threads have now finished: resuming the main thread */
         3223  +    for (i = 0; i < thread_count; i++)
         3224  +      {
         3225  +	  /* cleaning up a request slot */
         3226  +	  decoder = *(thread_slots + i);
         3227  +	  if (decoder->blob_odd != NULL)
         3228  +	      free (decoder->blob_odd);
         3229  +	  if (decoder->raster != NULL)
         3230  +	      rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
         3231  +	  if (decoder->opaque_thread_id != NULL)
         3232  +	      free (decoder->opaque_thread_id);
         3233  +	  decoder->blob_odd = NULL;
         3234  +	  decoder->blob_odd_sz = 0;
         3235  +	  decoder->raster = NULL;
         3236  +	  decoder->opaque_thread_id = NULL;
         3237  +      }
         3238  +    for (i = 0; i < thread_count; i++)
         3239  +      {
         3240  +	  /* checking for eventual errors */
         3241  +	  decoder = *(thread_slots + i);
         3242  +	  if (decoder->retcode != RL2_OK)
         3243  +	    {
         3244  +		fprintf (stderr, ERR_FRMT64, decoder->tile_id);
         3245  +		goto error;
         3246  +	    }
         3247  +      }
         3248  +    return 1;
         3249  +
         3250  +  error:
         3251  +    return 0;
         3252  +}
         3253  +
         3254  +static int
         3255  +rl2_load_dbms_masktiles (sqlite3 * handle, int max_threads, int by_section,
         3256  +			 sqlite3_int64 section_id, sqlite3_stmt * stmt_tiles,
         3257  +			 sqlite3_stmt * stmt_data, unsigned char *maskbuf,
         3258  +			 unsigned int width, unsigned int height, double x_res,
         3259  +			 double y_res, double minx, double miny, double maxx,
         3260  +			 double maxy, int level, int scale)
         3261  +{
         3262  +/* retrieving a transparenct mask from DBMS tiles */
         3263  +    rl2RasterPtr raster = NULL;
         3264  +    int ret;
         3265  +    rl2AuxMaskDecoderPtr aux = NULL;
         3266  +    rl2AuxMaskDecoderPtr decoder;
         3267  +    rl2AuxMaskDecoderPtr *thread_slots = NULL;
         3268  +    int thread_count;
         3269  +    int iaux;
         3270  +
         3271  +    if (max_threads < 1)
         3272  +	max_threads = 1;
         3273  +    if (max_threads > 64)
         3274  +	max_threads = 64;
         3275  +/* allocating the AuxDecoder array */
         3276  +    aux = malloc (sizeof (rl2AuxMaskDecoder) * max_threads);
         3277  +    if (aux == NULL)
         3278  +	return 0;
         3279  +    for (iaux = 0; iaux < max_threads; iaux++)
         3280  +      {
         3281  +	  /* initializing an empty AuxDecoder */
         3282  +	  decoder = aux + iaux;
         3283  +	  decoder->opaque_thread_id = NULL;
         3284  +	  decoder->blob_odd = NULL;
         3285  +	  decoder->blob_odd_sz = 0;
         3286  +	  decoder->maskbuf = maskbuf;
         3287  +	  decoder->width = width;
         3288  +	  decoder->height = height;
         3289  +	  decoder->x_res = x_res;
         3290  +	  decoder->y_res = y_res;
         3291  +	  decoder->scale = scale;
         3292  +	  decoder->minx = minx;
         3293  +	  decoder->maxy = maxy;
         3294  +	  decoder->raster = NULL;
         3295  +      }
         3296  +
         3297  +/* preparing the thread_slots stuct */
         3298  +    thread_slots = malloc (sizeof (rl2AuxMaskDecoderPtr) * max_threads);
         3299  +    for (thread_count = 0; thread_count < max_threads; thread_count++)
         3300  +	*(thread_slots + thread_count) = NULL;
         3301  +    thread_count = 0;
         3302  +
         3303  +/* binding the query args */
         3304  +    sqlite3_reset (stmt_tiles);
         3305  +    sqlite3_clear_bindings (stmt_tiles);
         3306  +    if (by_section)
         3307  +      {
         3308  +	  sqlite3_bind_int (stmt_tiles, 1, section_id);
         3309  +	  sqlite3_bind_int (stmt_tiles, 2, level);
         3310  +	  sqlite3_bind_double (stmt_tiles, 3, minx);
         3311  +	  sqlite3_bind_double (stmt_tiles, 4, miny);
         3312  +	  sqlite3_bind_double (stmt_tiles, 5, maxx);
         3313  +	  sqlite3_bind_double (stmt_tiles, 6, maxy);
         3314  +      }
         3315  +    else
         3316  +      {
         3317  +	  sqlite3_bind_int (stmt_tiles, 1, level);
         3318  +	  sqlite3_bind_double (stmt_tiles, 2, minx);
         3319  +	  sqlite3_bind_double (stmt_tiles, 3, miny);
         3320  +	  sqlite3_bind_double (stmt_tiles, 4, maxx);
         3321  +	  sqlite3_bind_double (stmt_tiles, 5, maxy);
         3322  +      }
         3323  +
         3324  +/* querying the tiles */
         3325  +    while (1)
         3326  +      {
         3327  +	  ret = sqlite3_step (stmt_tiles);
         3328  +	  if (ret == SQLITE_DONE)
         3329  +	      break;
         3330  +	  if (ret == SQLITE_ROW)
         3331  +	    {
         3332  +		int ok = 0;
         3333  +		const unsigned char *blob_odd = NULL;
         3334  +		int blob_odd_sz = 0;
         3335  +		sqlite3_int64 tile_id = sqlite3_column_int64 (stmt_tiles, 0);
         3336  +		double tile_minx = sqlite3_column_double (stmt_tiles, 1);
         3337  +		double tile_maxy = sqlite3_column_double (stmt_tiles, 2);
         3338  +		decoder = aux + thread_count;
         3339  +		decoder->tile_id = tile_id;
         3340  +		decoder->tile_minx = tile_minx;
         3341  +		decoder->tile_maxy = tile_maxy;
         3342  +
         3343  +		/* retrieving tile raw data from BLOBs */
         3344  +		sqlite3_reset (stmt_data);
         3345  +		sqlite3_clear_bindings (stmt_data);
         3346  +		sqlite3_bind_int64 (stmt_data, 1, tile_id);
         3347  +		ret = sqlite3_step (stmt_data);
         3348  +		if (ret == SQLITE_DONE)
         3349  +		    break;
         3350  +		if (ret == SQLITE_ROW)
         3351  +		  {
         3352  +		      /* decoding a Tile - may be by using concurrent multithreading */
         3353  +		      if (sqlite3_column_type (stmt_data, 0) == SQLITE_BLOB)
         3354  +			{
         3355  +			    blob_odd = sqlite3_column_blob (stmt_data, 0);
         3356  +			    blob_odd_sz = sqlite3_column_bytes (stmt_data, 0);
         3357  +			    decoder->blob_odd = malloc (blob_odd_sz);
         3358  +			    if (decoder->blob_odd == NULL)
         3359  +				goto error;
         3360  +			    memcpy (decoder->blob_odd, blob_odd, blob_odd_sz);
         3361  +			    decoder->blob_odd_sz = blob_odd_sz;
         3362  +			    ok = 1;
         3363  +			}
         3364  +		  }
         3365  +		else
         3366  +		  {
         3367  +		      fprintf (stderr,
         3368  +			       "SELECT tiles data; sqlite3_step() error: %s\n",
         3369  +			       sqlite3_errmsg (handle));
         3370  +		      goto error;
         3371  +		  }
         3372  +		if (!ok)
         3373  +		  {
         3374  +		      if (decoder->blob_odd != NULL)
         3375  +			  free (decoder->blob_odd);
         3376  +		      decoder->blob_odd = NULL;
         3377  +		      decoder->blob_odd_sz = 0;
         3378  +		  }
         3379  +		else
         3380  +		  {
         3381  +		      /* processing a Tile request (may be under parallel execution) */
         3382  +		      if (max_threads > 1)
         3383  +			{
         3384  +			    /* adopting a multithreaded strategy */
         3385  +			    *(thread_slots + thread_count) = decoder;
         3386  +			    thread_count++;
         3387  +			    if (thread_count == max_threads)
         3388  +			      {
         3389  +				  if (!do_run_mask_decoder_children
         3390  +				      (thread_slots, thread_count))
         3391  +				      goto error;
         3392  +				  thread_count = 0;
         3393  +			      }
         3394  +			}
         3395  +		      else
         3396  +			{
         3397  +			    /* single thread execution */
         3398  +			    do_decode_masktile (decoder);
         3399  +			    if (decoder->retcode != RL2_OK)
         3400  +			      {
         3401  +				  fprintf (stderr, ERR_FRMT64, tile_id);
         3402  +				  goto error;
         3403  +			      }
         3404  +			}
         3405  +		  }
         3406  +	    }
         3407  +	  else
         3408  +	    {
         3409  +		fprintf (stderr,
         3410  +			 "SELECT tiles; sqlite3_step() error: %s\n",
         3411  +			 sqlite3_errmsg (handle));
         3412  +		goto error;
         3413  +	    }
         3414  +      }
         3415  +    if (max_threads > 1 && thread_count > 0)
         3416  +      {
         3417  +	  /* launching the last multithreaded burst */
         3418  +	  if (!do_run_mask_decoder_children (thread_slots, thread_count))
         3419  +	      goto error;
         3420  +      }
         3421  +
         3422  +    free (aux);
         3423  +    free (thread_slots);
         3424  +    return 1;
         3425  +
         3426  +  error:
         3427  +    if (aux != NULL)
         3428  +      {
         3429  +	  /* AuxMaskDecoder cleanup */
         3430  +	  for (iaux = 0; iaux < max_threads; iaux++)
         3431  +	    {
         3432  +		decoder = aux + iaux;
         3433  +		if (decoder->blob_odd != NULL)
         3434  +		    free (decoder->blob_odd);
         3435  +		if (decoder->raster != NULL)
         3436  +		    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
         3437  +		if (decoder->opaque_thread_id != NULL)
         3438  +		    free (decoder->opaque_thread_id);
         3439  +	    }
         3440  +	  free (aux);
         3441  +      }
         3442  +    if (thread_slots != NULL)
         3443  +	free (thread_slots);
         3444  +    if (raster != NULL)
         3445  +	rl2_destroy_raster (raster);
         3446  +    return 0;
         3447  +}
  3077   3448   
  3078   3449   static int
  3079   3450   rl2_load_dbms_tiles_common (sqlite3 * handle, int max_threads,
  3080         -			    sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data,
  3081         -			    unsigned char *outbuf, unsigned int width,
  3082         -			    unsigned int height, unsigned char sample_type,
         3451  +			    sqlite3_stmt * stmt_tiles,
         3452  +			    sqlite3_stmt * stmt_data, unsigned char *outbuf,
         3453  +			    unsigned int width, unsigned int height,
         3454  +			    unsigned char sample_type,
  3083   3455   			    unsigned char num_bands, unsigned char auto_ndvi,
  3084   3456   			    unsigned char red_band_index,
  3085   3457   			    unsigned char nir_band_index, double x_res,
  3086   3458   			    double y_res, double minx, double maxy, int scale,
  3087   3459   			    rl2PalettePtr palette, rl2PixelPtr no_data,
  3088   3460   			    rl2RasterSymbolizerPtr style,
  3089   3461   			    rl2RasterStatisticsPtr stats)
................................................................................
  3704   4076   		  {
  3705   4077   		      fprintf (stderr,
  3706   4078   			       "SELECT tiles data; sqlite3_step() error: %s\n",
  3707   4079   			       sqlite3_errmsg (handle));
  3708   4080   		      goto error;
  3709   4081   		  }
  3710   4082   		raster =
  3711         -		    rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even,
  3712         -				       blob_even_sz, NULL);
         4083  +		    rl2_raster_decode (scale, blob_odd, blob_odd_sz,
         4084  +				       blob_even, blob_even_sz, NULL);
  3713   4085   		if (raster == NULL)
  3714   4086   		  {
  3715   4087   		      fprintf (stderr, ERR_FRMT64, tile_id);
  3716   4088   		      goto error;
  3717   4089   		  }
  3718   4090   		if (!copy_triple_band_raw_pixels
  3719   4091   		    (raster, outbuf, width, height, red_band, green_band,
  3720         -		     blue_band, x_res, y_res, minx, maxy, tile_minx, tile_maxy,
  3721         -		     no_data))
         4092  +		     blue_band, x_res, y_res, minx, maxy, tile_minx,
         4093  +		     tile_maxy, no_data))
  3722   4094   		    goto error;
  3723   4095   		rl2_destroy_raster (raster);
  3724   4096   		raster = NULL;
  3725   4097   	    }
  3726   4098   	  else
  3727   4099   	    {
  3728   4100   		fprintf (stderr,
................................................................................
  3866   4238   
  3867   4239       return 1;
  3868   4240   }
  3869   4241   
  3870   4242   static int
  3871   4243   copy_mono_band_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
  3872   4244   			   unsigned int width, unsigned int height,
  3873         -			   unsigned char mono_band, double x_res, double y_res,
  3874         -			   double minx, double maxy, double tile_minx,
  3875         -			   double tile_maxy, rl2PixelPtr no_data)
         4245  +			   unsigned char mono_band, double x_res,
         4246  +			   double y_res, double minx, double maxy,
         4247  +			   double tile_minx, double tile_maxy,
         4248  +			   rl2PixelPtr no_data)
  3876   4249   {
  3877   4250   /* copying raw pixels into the output buffer */
  3878   4251       unsigned int tile_width;
  3879   4252       unsigned int tile_height;
  3880   4253       unsigned int x;
  3881   4254       unsigned int y;
  3882   4255       int out_x;
................................................................................
  3999   4372       return 1;
  4000   4373   }
  4001   4374   
  4002   4375   static int
  4003   4376   load_mono_band_dbms_tiles (sqlite3 * handle, sqlite3_stmt * stmt_tiles,
  4004   4377   			   sqlite3_stmt * stmt_data, unsigned char *outbuf,
  4005   4378   			   unsigned int width, unsigned int height,
  4006         -			   unsigned char mono_band, double x_res, double y_res,
  4007         -			   double minx, double miny, double maxx, double maxy,
  4008         -			   int level, int scale, rl2PixelPtr no_data)
         4379  +			   unsigned char mono_band, double x_res,
         4380  +			   double y_res, double minx, double miny,
         4381  +			   double maxx, double maxy, int level, int scale,
         4382  +			   rl2PixelPtr no_data)
  4009   4383   {
  4010   4384   /* retrieving a full image from DBMS tiles */
  4011   4385       rl2RasterPtr raster = NULL;
  4012   4386       int ret;
  4013   4387   
  4014   4388   /* binding the query args */
  4015   4389       sqlite3_reset (stmt_tiles);
................................................................................
  4060   4434   		  {
  4061   4435   		      fprintf (stderr,
  4062   4436   			       "SELECT tiles data; sqlite3_step() error: %s\n",
  4063   4437   			       sqlite3_errmsg (handle));
  4064   4438   		      goto error;
  4065   4439   		  }
  4066   4440   		raster =
  4067         -		    rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even,
  4068         -				       blob_even_sz, NULL);
         4441  +		    rl2_raster_decode (scale, blob_odd, blob_odd_sz,
         4442  +				       blob_even, blob_even_sz, NULL);
  4069   4443   		if (raster == NULL)
  4070   4444   		  {
  4071   4445   		      fprintf (stderr, ERR_FRMT64, tile_id);
  4072   4446   		      goto error;
  4073   4447   		  }
  4074   4448   		if (!copy_mono_band_raw_pixels
  4075   4449   		    (raster, outbuf, width, height, mono_band, x_res, y_res,
................................................................................
  4097   4471   
  4098   4472   RL2_PRIVATE int
  4099   4473   rl2_load_dbms_tiles (sqlite3 * handle, int max_threads,
  4100   4474   		     sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data,
  4101   4475   		     unsigned char *outbuf, unsigned int width,
  4102   4476   		     unsigned int height, unsigned char sample_type,
  4103   4477   		     unsigned char num_bands, unsigned char auto_ndvi,
  4104         -		     unsigned char red_band_index, unsigned char nir_band_index,
  4105         -		     double x_res, double y_res, double minx, double miny,
  4106         -		     double maxx, double maxy, int level, int scale,
  4107         -		     rl2PalettePtr palette, rl2PixelPtr no_data,
  4108         -		     rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats)
         4478  +		     unsigned char red_band_index,
         4479  +		     unsigned char nir_band_index, double x_res, double y_res,
         4480  +		     double minx, double miny, double maxx, double maxy,
         4481  +		     int level, int scale, rl2PalettePtr palette,
         4482  +		     rl2PixelPtr no_data, rl2RasterSymbolizerPtr style,
         4483  +		     rl2RasterStatisticsPtr stats)
  4109   4484   {
  4110   4485   /* binding the query args */
  4111   4486       sqlite3_reset (stmt_tiles);
  4112   4487       sqlite3_clear_bindings (stmt_tiles);
  4113   4488       sqlite3_bind_int (stmt_tiles, 1, level);
  4114   4489       sqlite3_bind_double (stmt_tiles, 2, minx);
  4115   4490       sqlite3_bind_double (stmt_tiles, 3, miny);
................................................................................
  4126   4501   
  4127   4502   RL2_PRIVATE int
  4128   4503   rl2_load_dbms_tiles_section (sqlite3 * handle, int max_threads,
  4129   4504   			     sqlite3_int64 section_id,
  4130   4505   			     sqlite3_stmt * stmt_tiles,
  4131   4506   			     sqlite3_stmt * stmt_data, unsigned char *outbuf,
  4132   4507   			     unsigned int width, unsigned int height,
  4133         -			     unsigned char sample_type, unsigned char num_bands,
  4134         -			     unsigned char auto_ndvi,
         4508  +			     unsigned char sample_type,
         4509  +			     unsigned char num_bands, unsigned char auto_ndvi,
  4135   4510   			     unsigned char red_band_index,
  4136   4511   			     unsigned char nir_band_index, double x_res,
  4137         -			     double y_res, double minx, double maxy, int scale,
         4512  +			     double y_res, double minx, double miny,
         4513  +			     double maxx, double maxy, int level, int scale,
  4138   4514   			     rl2PalettePtr palette, rl2PixelPtr no_data)
  4139   4515   {
  4140   4516   /* binding the query args */
  4141   4517       sqlite3_reset (stmt_tiles);
  4142   4518       sqlite3_clear_bindings (stmt_tiles);
  4143   4519       sqlite3_bind_int (stmt_tiles, 1, section_id);
         4520  +    sqlite3_bind_int (stmt_tiles, 2, level);
         4521  +    sqlite3_bind_double (stmt_tiles, 3, minx);
         4522  +    sqlite3_bind_double (stmt_tiles, 4, miny);
         4523  +    sqlite3_bind_double (stmt_tiles, 5, maxx);
         4524  +    sqlite3_bind_double (stmt_tiles, 6, maxy);
  4144   4525   
  4145   4526       if (!rl2_load_dbms_tiles_common
  4146   4527   	(handle, max_threads, stmt_tiles, stmt_data, outbuf, width, height,
  4147   4528   	 sample_type, num_bands, auto_ndvi, red_band_index, nir_band_index,
  4148   4529   	 x_res, y_res, minx, maxy, scale, palette, no_data, NULL, NULL))
  4149   4530   	return 0;
  4150   4531       return 1;
................................................................................
  4431   4812       if (ret != SQLITE_OK)
  4432   4813   	return scale_factor;
  4433   4814       for (i = 1; i <= rows; i++)
  4434   4815   	scale_factor = 11.1120;
  4435   4816       sqlite3_free_table (results);
  4436   4817       return scale_factor;
  4437   4818   }
         4819  +
         4820  +RL2_DECLARE int
         4821  +rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads,
         4822  +			 rl2CoveragePtr cvg, unsigned int width,
         4823  +			 unsigned int height, double minx, double miny,
         4824  +			 double maxx, double maxy, double x_res,
         4825  +			 double y_res, unsigned char **mask, int *mask_size)
         4826  +{
         4827  +/* attempting to return a transparency mask from the DBMS Coverage */
         4828  +    return rl2_get_raw_raster_mask_common (handle, max_threads,
         4829  +					   cvg, 0, 0, width, height, minx, miny,
         4830  +					   maxx, maxy, x_res, y_res, mask,
         4831  +					   mask_size);
         4832  +}
         4833  +
         4834  +RL2_DECLARE int
         4835  +rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads,
         4836  +				 rl2CoveragePtr cvg,
         4837  +				 sqlite3_int64 section_id,
         4838  +				 unsigned int width,
         4839  +				 unsigned int height, double minx,
         4840  +				 double miny, double maxx, double maxy,
         4841  +				 double x_res, double y_res,
         4842  +				 unsigned char **mask, int *mask_size)
         4843  +{
         4844  +/* attempting to return a transparency mask from the DBMS Coverage */
         4845  +    return rl2_get_raw_raster_mask_common (handle, max_threads,
         4846  +					   cvg, 1, section_id, width, height,
         4847  +					   minx, miny, maxx, maxy, x_res, y_res,
         4848  +					   mask, mask_size);
         4849  +}
         4850  +
         4851  +RL2_PRIVATE int
         4852  +rl2_get_raw_raster_mask_common (sqlite3 * handle, int max_threads,
         4853  +				rl2CoveragePtr cvg, int by_section,
         4854  +				sqlite3_int64 section_id, unsigned int width,
         4855  +				unsigned int height, double minx, double miny,
         4856  +				double maxx, double maxy, double x_res,
         4857  +				double y_res, unsigned char **mask,
         4858  +				int *mask_size)
         4859  +{
         4860  +/* attempting to return a transparency mask from the DBMS Coverage */
         4861  +    const char *coverage;
         4862  +    unsigned char level;
         4863  +    unsigned char scale;
         4864  +    double xx_res = x_res;
         4865  +    double yy_res = y_res;
         4866  +    unsigned char *bufpix = NULL;
         4867  +    int bufpix_size;
         4868  +    char *xtiles;
         4869  +    char *xxtiles;
         4870  +    char *xdata;
         4871  +    char *xxdata;
         4872  +    char *sql;
         4873  +    sqlite3_stmt *stmt_tiles = NULL;
         4874  +    sqlite3_stmt *stmt_data = NULL;
         4875  +    int ret;
         4876  +
         4877  +    if (cvg == NULL || handle == NULL)
         4878  +	goto error;
         4879  +    coverage = rl2_get_coverage_name (cvg);
         4880  +    if (coverage == NULL)
         4881  +	goto error;
         4882  +    if (rl2_find_matching_resolution
         4883  +	(handle, cvg, by_section, section_id, &xx_res, &yy_res, &level,
         4884  +	 &scale) != RL2_OK)
         4885  +	goto error;
         4886  +
         4887  +    bufpix_size = width * height;
         4888  +    bufpix = malloc (bufpix_size);
         4889  +    if (bufpix == NULL)
         4890  +      {
         4891  +	  fprintf (stderr,
         4892  +		   "rl2_get_raw_raster_mask: Insufficient Memory !!!\n");
         4893  +	  goto error;
         4894  +      }
         4895  +
         4896  +/* preparing the "tiles" SQL query */
         4897  +    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
         4898  +    xxtiles = rl2_double_quoted_sql (xtiles);
         4899  +    if (by_section)
         4900  +      {
         4901  +	  /* only from a single Section */
         4902  +	  sql =
         4903  +	      sqlite3_mprintf
         4904  +	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
         4905  +	       "FROM \"%s\" "
         4906  +	       "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
         4907  +	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
         4908  +	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
         4909  +      }
         4910  +    else
         4911  +      {
         4912  +	  /* whole Coverage */
         4913  +	  sql =
         4914  +	      sqlite3_mprintf
         4915  +	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
         4916  +	       "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( "
         4917  +	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
         4918  +	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
         4919  +      }
         4920  +    sqlite3_free (xtiles);
         4921  +    free (xxtiles);
         4922  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
         4923  +    sqlite3_free (sql);
         4924  +    if (ret != SQLITE_OK)
         4925  +      {
         4926  +	  printf ("SELECT raw tiles SQL error: %s\n", sqlite3_errmsg (handle));
         4927  +	  goto error;
         4928  +      }
         4929  +
         4930  +    /* preparing the data SQL query - only ODD */
         4931  +    xdata = sqlite3_mprintf ("%s_tile_data", coverage);
         4932  +    xxdata = rl2_double_quoted_sql (xdata);
         4933  +    sqlite3_free (xdata);
         4934  +    sql = sqlite3_mprintf ("SELECT tile_data_odd "
         4935  +			   "FROM \"%s\" WHERE tile_id = ?", xxdata);
         4936  +    free (xxdata);
         4937  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL);
         4938  +    sqlite3_free (sql);
         4939  +    if (ret != SQLITE_OK)
         4940  +      {
         4941  +	  printf ("SELECT raw tiles data(1) SQL error: %s\n",
         4942  +		  sqlite3_errmsg (handle));
         4943  +	  goto error;
         4944  +      }
         4945  +
         4946  +/* preparing a fully opaque mask */
         4947  +    memset (bufpix, 0, bufpix_size);
         4948  +
         4949  +    if (!rl2_load_dbms_masktiles
         4950  +	(handle, max_threads, by_section, section_id, stmt_tiles, stmt_data,
         4951  +	 bufpix, width, height, xx_res, yy_res, minx, miny, maxx, maxy, level,
         4952  +	 scale))
         4953  +	goto error;
         4954  +    sqlite3_finalize (stmt_tiles);
         4955  +    sqlite3_finalize (stmt_data);
         4956  +    *mask = bufpix;
         4957  +    *mask_size = bufpix_size;
         4958  +
         4959  +    return RL2_OK;
         4960  +
         4961  +  error:
         4962  +    if (stmt_tiles != NULL)
         4963  +	sqlite3_finalize (stmt_tiles);
         4964  +    if (stmt_data != NULL)
         4965  +	sqlite3_finalize (stmt_data);
         4966  +    if (bufpix != NULL)
         4967  +	free (bufpix);
         4968  +    return RL2_ERROR;
         4969  +}
  4438   4970   
  4439   4971   RL2_PRIVATE int
  4440   4972   rl2_get_raw_raster_data_common (sqlite3 * handle, int max_threads,
  4441   4973   				rl2CoveragePtr cvg, int by_section,
  4442   4974   				sqlite3_int64 section_id, unsigned int width,
  4443   4975   				unsigned int height, double minx, double miny,
  4444   4976   				double maxx, double maxy, double x_res,
................................................................................
  4583   5115   			    free (blue);
  4584   5116   			}
  4585   5117   		      if (!ok)
  4586   5118   			{
  4587   5119   			    /* default: white */
  4588   5120   			    rl2_set_pixel_sample_uint8 (no_data, RL2_RED_BAND,
  4589   5121   							255);
  4590         -			    rl2_set_pixel_sample_uint8 (no_data, RL2_GREEN_BAND,
  4591         -							255);
  4592         -			    rl2_set_pixel_sample_uint8 (no_data, RL2_BLUE_BAND,
  4593         -							255);
         5122  +			    rl2_set_pixel_sample_uint8 (no_data,
         5123  +							RL2_GREEN_BAND, 255);
         5124  +			    rl2_set_pixel_sample_uint8 (no_data,
         5125  +							RL2_BLUE_BAND, 255);
  4594   5126   			}
  4595   5127   		  }
  4596   5128   	    }
  4597   5129   	  if (plt != NULL)
  4598   5130   	      rl2_destroy_palette (plt);
  4599   5131   	  plt = NULL;
  4600   5132   	  sample_type = RL2_SAMPLE_UINT8;
................................................................................
  4677   5209   		/* preparing a Shaded Relief mask */
  4678   5210   		double scale_factor =
  4679   5211   		    rl2_get_shaded_relief_scale_factor (handle, coverage);
  4680   5212   		if (rl2_get_raster_symbolizer_shaded_relief
  4681   5213   		    (style, &brightness_only, &relief_factor) != RL2_OK)
  4682   5214   		    goto error;
  4683   5215   		if (rl2_build_shaded_relief_mask
  4684         -		    (handle, max_threads, cvg, relief_factor, scale_factor,
  4685         -		     width, height, minx, miny, maxx, maxy, x_res, y_res,
  4686         -		     &shaded_relief, &shaded_relief_sz) != RL2_OK)
         5216  +		    (handle, max_threads, cvg, by_section, section_id,
         5217  +		     relief_factor, scale_factor, width, height, minx, miny,
         5218  +		     maxx, maxy, x_res, y_res, &shaded_relief,
         5219  +		     &shaded_relief_sz) != RL2_OK)
  4687   5220   		    goto error;
  4688   5221   
  4689   5222   		if (brightness_only || !rl2_has_styled_rgb_colors (style))
  4690   5223   		  {
  4691   5224   		      /* returning a Grayscale ShadedRelief (BrightnessOnly) */
  4692   5225   		      unsigned int row;
  4693   5226   		      unsigned int col;
................................................................................
  4723   5256   
  4724   5257   /* preparing the "tiles" SQL query */
  4725   5258       xtiles = sqlite3_mprintf ("%s_tiles", coverage);
  4726   5259       xxtiles = rl2_double_quoted_sql (xtiles);
  4727   5260       if (by_section)
  4728   5261         {
  4729   5262   	  /* only from a single Section */
  4730         -	  char sctn[1024];
  4731         -#if defined(_WIN32) && !defined(__MINGW32__)
  4732         -	  sprintf (sctn, "%I64d", section_id);
  4733         -#else
  4734         -	  sprintf (sctn, "%lld", section_id);
  4735         -#endif
  4736   5263   	  sql =
  4737   5264   	      sqlite3_mprintf
  4738   5265   	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
  4739   5266   	       "FROM \"%s\" "
  4740         -	       "WHERE section_id = %s AND pyramid_level = ? AND ROWID IN ( "
         5267  +	       "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
  4741   5268   	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
  4742         -	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, sctn,
  4743         -	       xtiles);
         5269  +	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
  4744   5270         }
  4745   5271       else
  4746   5272         {
  4747   5273   	  /* whole Coverage */
  4748   5274   	  sql =
  4749   5275   	      sqlite3_mprintf
  4750   5276   	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
................................................................................
  4809   5335   	  if (bgcolor != NULL)
  4810   5336   	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
  4811   5337   			       bgcolor);
  4812   5338   	  else
  4813   5339   	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
  4814   5340   			       no_data);
  4815   5341         }
  4816         -    if (!rl2_load_dbms_tiles
  4817         -	(handle, max_threads, stmt_tiles, stmt_data, bufpix, width, height,
  4818         -	 sample_type, num_bands, auto_ndvi, red_band, nir_band, xx_res, yy_res,
  4819         -	 minx, miny, maxx, maxy, level, scale, plt, no_data, style, stats))
  4820         -	goto error;
         5342  +    if (by_section)
         5343  +      {
         5344  +	  /* only from a single Section */
         5345  +	  if (!rl2_load_dbms_tiles_section
         5346  +	      (handle, max_threads, section_id, stmt_tiles, stmt_data, bufpix,
         5347  +	       width, height, sample_type, num_bands, auto_ndvi, red_band,
         5348  +	       nir_band, xx_res, yy_res, minx, miny, maxx, maxy, level, scale,
         5349  +	       plt, no_data))
         5350  +	      goto error;
         5351  +      }
         5352  +    else
         5353  +      {
         5354  +	  /* whole Coverage */
         5355  +	  if (!rl2_load_dbms_tiles
         5356  +	      (handle, max_threads, stmt_tiles, stmt_data, bufpix, width,
         5357  +	       height, sample_type, num_bands, auto_ndvi, red_band, nir_band,
         5358  +	       xx_res, yy_res, minx, miny, maxx, maxy, level, scale, plt,
         5359  +	       no_data, style, stats))
         5360  +	      goto error;
         5361  +      }
  4821   5362       if (kill_no_data != NULL)
  4822   5363   	rl2_destroy_pixel (kill_no_data);
  4823   5364       sqlite3_finalize (stmt_tiles);
  4824   5365       sqlite3_finalize (stmt_data);
  4825   5366       if (shaded_relief != NULL)
  4826   5367         {
  4827   5368   	  /* applying the Shaded Relief */
................................................................................
  4868   5409   	rl2_destroy_pixel (kill_no_data);
  4869   5410       if (shaded_relief != NULL)
  4870   5411   	free (shaded_relief);
  4871   5412       return RL2_ERROR;
  4872   5413   }
  4873   5414   
  4874   5415   RL2_DECLARE int
  4875         -rl2_get_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg,
  4876         -			 unsigned int width, unsigned int height,
  4877         -			 double minx, double miny, double maxx, double maxy,
  4878         -			 double x_res, double y_res, unsigned char **buffer,
  4879         -			 int *buf_size, rl2PalettePtr * palette,
  4880         -			 unsigned char out_pixel)
         5416  +rl2_get_raw_raster_data (sqlite3 * handle, int max_threads,
         5417  +			 rl2CoveragePtr cvg, unsigned int width,
         5418  +			 unsigned int height, double minx, double miny,
         5419  +			 double maxx, double maxy, double x_res, double y_res,
         5420  +			 unsigned char **buffer, int *buf_size,
         5421  +			 rl2PalettePtr * palette, unsigned char out_pixel)
  4881   5422   {
  4882   5423   /* attempting to return a buffer containing raw pixels from the DBMS Coverage */
  4883   5424       return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 0, 0,
  4884   5425   					   width, height, minx, miny, maxx,
  4885         -					   maxy, x_res, y_res, buffer, buf_size,
  4886         -					   palette, out_pixel, NULL, NULL,
  4887         -					   NULL);
         5426  +					   maxy, x_res, y_res, buffer,
         5427  +					   buf_size, palette, out_pixel, NULL,
         5428  +					   NULL, NULL);
  4888   5429   }
  4889   5430   
  4890   5431   RL2_DECLARE int
  4891   5432   rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
  4892   5433   				 rl2CoveragePtr cvg, sqlite3_int64 section_id,
  4893   5434   				 unsigned int width, unsigned int height,
  4894   5435   				 double minx, double miny, double maxx,
................................................................................
  4897   5438   				 rl2PalettePtr * palette,
  4898   5439   				 unsigned char out_pixel)
  4899   5440   {
  4900   5441   /* attempting to return a buffer containing raw pixels from the DBMS Coverage/Section */
  4901   5442       return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 1,
  4902   5443   					   section_id, width, height, minx,
  4903   5444   					   miny, maxx, maxy, x_res, y_res,
  4904         -					   buffer, buf_size, palette, out_pixel,
  4905         -					   NULL, NULL, NULL);
         5445  +					   buffer, buf_size, palette,
         5446  +					   out_pixel, NULL, NULL, NULL);
  4906   5447   }
  4907   5448   
  4908   5449   static int
  4909   5450   get_triple_band_raw_raster_data_common (int by_section, sqlite3 * handle,
  4910   5451   					rl2CoveragePtr cvg,
  4911   5452   					sqlite3_int64 section_id,
  4912         -					unsigned int width, unsigned int height,
  4913         -					double minx, double miny, double maxx,
  4914         -					double maxy, double x_res, double y_res,
         5453  +					unsigned int width,
         5454  +					unsigned int height, double minx,
         5455  +					double miny, double maxx, double maxy,
         5456  +					double x_res, double y_res,
  4915   5457   					unsigned char red_band,
  4916   5458   					unsigned char green_band,
  4917   5459   					unsigned char blue_band,
  4918   5460   					unsigned char **buffer, int *buf_size,
  4919   5461   					rl2PixelPtr bgcolor)
  4920   5462   {
  4921   5463   /* attempting to return a buffer containing raw pixels from the DBMS Coverage */
................................................................................
  5072   5614   				     unsigned char blue_band,
  5073   5615   				     unsigned char **buffer, int *buf_size,
  5074   5616   				     rl2PixelPtr bgcolor)
  5075   5617   {
  5076   5618   /* attempting to return a buffer containing raw pixels from the DBMS Coverage */
  5077   5619       return get_triple_band_raw_raster_data_common (0, handle, cvg, 0, width,
  5078   5620   						   height, minx, miny, maxx,
  5079         -						   maxy, x_res, y_res, red_band,
  5080         -						   green_band, blue_band,
  5081         -						   buffer, buf_size, bgcolor);
         5621  +						   maxy, x_res, y_res,
         5622  +						   red_band, green_band,
         5623  +						   blue_band, buffer,
         5624  +						   buf_size, bgcolor);
  5082   5625   }
  5083   5626   
  5084   5627   RL2_DECLARE int
  5085   5628   rl2_get_section_triple_band_raw_raster_data (sqlite3 * handle,
  5086   5629   					     rl2CoveragePtr cvg,
  5087   5630   					     sqlite3_int64 section_id,
  5088   5631   					     unsigned int width,
................................................................................
  5097   5640   					     int *buf_size, rl2PixelPtr bgcolor)
  5098   5641   {
  5099   5642   /* attempting to return a buffer containing raw pixels - Section */
  5100   5643       return get_triple_band_raw_raster_data_common (1, handle, cvg, section_id,
  5101   5644   						   width, height, minx, miny,
  5102   5645   						   maxx, maxy, x_res, y_res,
  5103   5646   						   red_band, green_band,
  5104         -						   blue_band, buffer, buf_size,
  5105         -						   bgcolor);
         5647  +						   blue_band, buffer,
         5648  +						   buf_size, bgcolor);
  5106   5649   }
  5107   5650   
  5108   5651   static int
  5109   5652   get_mono_band_raw_raster_data_common (int by_section, sqlite3 * handle,
  5110   5653   				      rl2CoveragePtr cvg,
  5111   5654   				      sqlite3_int64 section_id,
  5112   5655   				      unsigned int width, unsigned int height,
................................................................................
  5263   5806   				   double x_res, double y_res,
  5264   5807   				   unsigned char mono_band,
  5265   5808   				   unsigned char **buffer, int *buf_size,
  5266   5809   				   rl2PixelPtr no_data)
  5267   5810   {
  5268   5811   /* attempting to return a buffer containing raw pixels from the DBMS Coverage */
  5269   5812       return get_mono_band_raw_raster_data_common (0, handle, cvg, 0, width,
  5270         -						 height, minx, miny, maxx, maxy,
  5271         -						 x_res, y_res, buffer, buf_size,
  5272         -						 mono_band, no_data);
         5813  +						 height, minx, miny, maxx,
         5814  +						 maxy, x_res, y_res, buffer,
         5815  +						 buf_size, mono_band, no_data);
  5273   5816   }
  5274   5817   
  5275   5818   RL2_DECLARE int
  5276         -rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle, rl2CoveragePtr cvg,
         5819  +rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle,
         5820  +					   rl2CoveragePtr cvg,
  5277   5821   					   sqlite3_int64 section_id,
  5278   5822   					   unsigned int width,
  5279   5823   					   unsigned int height, double minx,
  5280   5824   					   double miny, double maxx,
  5281   5825   					   double maxy, double x_res,
  5282   5826   					   double y_res,
  5283   5827   					   unsigned char mono_band,
................................................................................
  5291   5835   						 buffer, buf_size, mono_band,
  5292   5836   						 no_data);
  5293   5837   }
  5294   5838   
  5295   5839   RL2_DECLARE int
  5296   5840   rl2_get_raw_raster_data_bgcolor (sqlite3 * handle, int max_threads,
  5297   5841   				 rl2CoveragePtr cvg, unsigned int width,
  5298         -				 unsigned int height, double minx, double miny,
  5299         -				 double maxx, double maxy, double x_res,
  5300         -				 double y_res, unsigned char **buffer,
  5301         -				 int *buf_size, rl2PalettePtr * palette,
  5302         -				 unsigned char *out_pixel, unsigned char bg_red,
  5303         -				 unsigned char bg_green, unsigned char bg_blue,
         5842  +				 unsigned int height, double minx,
         5843  +				 double miny, double maxx, double maxy,
         5844  +				 double x_res, double y_res,
         5845  +				 unsigned char **buffer, int *buf_size,
         5846  +				 rl2PalettePtr * palette,
         5847  +				 unsigned char *out_pixel,
         5848  +				 unsigned char bg_red, unsigned char bg_green,
         5849  +				 unsigned char bg_blue,
  5304   5850   				 rl2RasterSymbolizerPtr style,
  5305   5851   				 rl2RasterStatisticsPtr stats)
  5306   5852   {
  5307   5853   /* attempting to return a buffer containing raw pixels from the DBMS Coverage + bgcolor */
  5308   5854       int ret;
  5309   5855       rl2PixelPtr no_data = NULL;
  5310   5856       const char *coverage;
................................................................................
  5380   5926   	  if (index < 0)
  5381   5927   	    {
  5382   5928   		/* palette color found */
  5383   5929   		switch (sample_type)
  5384   5930   		  {
  5385   5931   		  case RL2_SAMPLE_1_BIT:
  5386   5932   		      no_data =
  5387         -			  rl2_create_pixel (RL2_SAMPLE_1_BIT, RL2_PIXEL_PALETTE,
  5388         -					    1);
         5933  +			  rl2_create_pixel (RL2_SAMPLE_1_BIT,
         5934  +					    RL2_PIXEL_PALETTE, 1);
  5389   5935   		      rl2_set_pixel_sample_1bit (no_data,
  5390   5936   						 (unsigned char) index);
  5391   5937   		      break;
  5392   5938   		  case RL2_SAMPLE_2_BIT:
  5393   5939   		      no_data =
  5394         -			  rl2_create_pixel (RL2_SAMPLE_2_BIT, RL2_PIXEL_PALETTE,
  5395         -					    1);
         5940  +			  rl2_create_pixel (RL2_SAMPLE_2_BIT,
         5941  +					    RL2_PIXEL_PALETTE, 1);
  5396   5942   		      rl2_set_pixel_sample_2bit (no_data,
  5397   5943   						 (unsigned char) index);
  5398   5944   		      break;
  5399   5945   		  case RL2_SAMPLE_4_BIT:
  5400   5946   		      no_data =
  5401         -			  rl2_create_pixel (RL2_SAMPLE_4_BIT, RL2_PIXEL_PALETTE,
  5402         -					    1);
         5947  +			  rl2_create_pixel (RL2_SAMPLE_4_BIT,
         5948  +					    RL2_PIXEL_PALETTE, 1);
  5403   5949   		      rl2_set_pixel_sample_4bit (no_data,
  5404   5950   						 (unsigned char) index);
  5405   5951   		      break;
  5406   5952   		  case RL2_SAMPLE_UINT8:
  5407   5953   		      no_data =
  5408         -			  rl2_create_pixel (RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE,
  5409         -					    1);
         5954  +			  rl2_create_pixel (RL2_SAMPLE_UINT8,
         5955  +					    RL2_PIXEL_PALETTE, 1);
  5410   5956   		      rl2_set_pixel_sample_uint8 (no_data, RL2_PALETTE_BAND,
  5411   5957   						  (unsigned char) index);
  5412   5958   		      break;
  5413   5959   
  5414   5960   		  };
  5415   5961   	    }
  5416   5962         }
................................................................................
  5703   6249       sqlite3_stmt *stmt = NULL;
  5704   6250       char *sql;
  5705   6251       int ret;
  5706   6252       if (handle == NULL || coverage == NULL || palette == NULL)
  5707   6253   	return RL2_ERROR;
  5708   6254   
  5709   6255       sql =
  5710         -	sqlite3_mprintf ("SELECT sample_type, pixel_type FROM raster_coverages "
  5711         -			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
         6256  +	sqlite3_mprintf
         6257  +	("SELECT sample_type, pixel_type FROM raster_coverages "
         6258  +	 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
  5712   6259       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  5713   6260       sqlite3_free (sql);
  5714   6261       if (ret != SQLITE_OK)
  5715   6262         {
  5716   6263   	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
  5717   6264   	  goto error;
  5718   6265         }
................................................................................
  6231   6778   	sqlite3_finalize (stmt);
  6232   6779       if (stl != NULL)
  6233   6780   	rl2_destroy_coverage_style (stl);
  6234   6781       return NULL;
  6235   6782   }
  6236   6783   
  6237   6784   RL2_DECLARE rl2FeatureTypeStylePtr
  6238         -rl2_create_feature_type_style_from_dbms (sqlite3 * handle, const char *coverage,
         6785  +rl2_create_feature_type_style_from_dbms (sqlite3 * handle,
         6786  +					 const char *coverage,
  6239   6787   					 const char *style)
  6240   6788   {
  6241   6789   /* attempting to load and parse a Feature Type Style */
  6242   6790       const char *sql;
  6243   6791       int ret;
  6244   6792       sqlite3_stmt *stmt = NULL;
  6245   6793       rl2FeatureTypeStylePtr stl = NULL;
................................................................................
  6375   6923       char **results;
  6376   6924       int rows;
  6377   6925       int columns;
  6378   6926       int i;
  6379   6927       int ok = 0;
  6380   6928   /* testing if the Layer Style exists */
  6381   6929       char *sql =
  6382         -	sqlite3_mprintf ("SELECT style_name FROM SE_raster_styled_layers AS r "
  6383         -			 "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) "
  6384         -			 "WHERE Lower(r.coverage_name) = Lower(%Q) AND "
  6385         -			 "Lower(s.style_name) = Lower(%Q)", namedLayer,
  6386         -			 namedStyle);
         6930  +	sqlite3_mprintf
         6931  +	("SELECT style_name FROM SE_raster_styled_layers AS r "
         6932  +	 "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) "
         6933  +	 "WHERE Lower(r.coverage_name) = Lower(%Q) AND "
         6934  +	 "Lower(s.style_name) = Lower(%Q)", namedLayer,
         6935  +	 namedStyle);
  6387   6936       ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL);
  6388   6937       sqlite3_free (sql);
  6389   6938       if (ret != SQLITE_OK)
  6390   6939   	return 0;
  6391   6940       for (i = 1; i <= rows; i++)
  6392   6941   	ok = 1;
  6393   6942       sqlite3_free_table (results);
................................................................................
  7001   7550       int section_summary = 0;
  7002   7551       rl2PixelPtr no_data = NULL;
  7003   7552       rl2PalettePtr palette = NULL;
  7004   7553       char *title = NULL;
  7005   7554       char *abstract = NULL;
  7006   7555       unsigned char *statistics = NULL;
  7007   7556       int statistics_sz;
         7557  +    int ok_geo = 0;
  7008   7558       int ok_bbox = 0;
  7009   7559       double geo_minx;
  7010   7560       double geo_miny;
  7011   7561       double geo_maxx;
  7012   7562       double geo_maxy;
  7013   7563       double ext_minx;
  7014   7564       double ext_miny;
................................................................................
  7399   7949   		      strcpy (abstract, value);
  7400   7950   		  }
  7401   7951   		if (sqlite3_column_type (stmt, 18) == SQLITE_BLOB)
  7402   7952   		  {
  7403   7953   		      statistics_sz = sqlite3_column_bytes (stmt, 18);
  7404   7954   		      statistics = malloc (statistics_sz);
  7405   7955   		      memcpy (statistics,
  7406         -			      (const unsigned char *) sqlite3_column_blob (stmt,
  7407         -									   18),
  7408         -			      statistics_sz);
         7956  +			      (const unsigned char *)
         7957  +			      sqlite3_column_blob (stmt, 18), statistics_sz);
  7409   7958   		  }
  7410   7959   		if (sqlite3_column_type (stmt, 19) == SQLITE_FLOAT)
  7411   7960   		  {
  7412   7961   		      geo_minx = sqlite3_column_double (stmt, 19);
  7413         -		      ok_bbox++;
         7962  +		      ok_geo++;
  7414   7963   		  }
  7415   7964   		if (sqlite3_column_type (stmt, 20) == SQLITE_FLOAT)
  7416   7965   		  {
  7417   7966   		      geo_miny = sqlite3_column_double (stmt, 20);
  7418         -		      ok_bbox++;
         7967  +		      ok_geo++;
  7419   7968   		  }
  7420   7969   		if (sqlite3_column_type (stmt, 21) == SQLITE_FLOAT)
  7421   7970   		  {
  7422   7971   		      geo_maxx = sqlite3_column_double (stmt, 21);
  7423         -		      ok_bbox++;
         7972  +		      ok_geo++;
  7424   7973   		  }
  7425   7974   		if (sqlite3_column_type (stmt, 22) == SQLITE_FLOAT)
  7426   7975   		  {
  7427   7976   		      geo_maxy = sqlite3_column_double (stmt, 22);
  7428         -		      ok_bbox++;
         7977  +		      ok_geo++;
  7429   7978   		  }
  7430   7979   		if (sqlite3_column_type (stmt, 23) == SQLITE_FLOAT)
  7431   7980   		  {
  7432   7981   		      ext_minx = sqlite3_column_double (stmt, 23);
  7433   7982   		      ok_bbox++;
  7434   7983   		  }
  7435   7984   		if (sqlite3_column_type (stmt, 24) == SQLITE_FLOAT)
................................................................................
  7481   8030   		  {
  7482   8031   		      const unsigned char *blob =
  7483   8032   			  sqlite3_column_blob (stmt, 33);
  7484   8033   		      int blob_sz = sqlite3_column_bytes (stmt, 33);
  7485   8034   		      palette = rl2_deserialize_dbms_palette (blob, blob_sz);
  7486   8035   		  }
  7487   8036   		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
  7488         -		    && ok_quality && ok_tile_width && ok_tile_height && ok_x_res
  7489         -		    && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed
  7490         -		    && ok_paths && ok_md5 && ok_summary)
         8037  +		    && ok_quality && ok_tile_width && ok_tile_height
         8038  +		    && ok_x_res && ok_y_res && ok_srid && ok_nodata
         8039  +		    && ok_strict && ok_mixed && ok_paths && ok_md5
         8040  +		    && ok_summary)
  7491   8041   		    ok = 1;
  7492         -		if (ok_bbox != 8)
         8042  +		if (ok_geo != 4)
         8043  +		    ok_geo = 0;
         8044  +		if (ok_bbox != 4)
  7493   8045   		    ok_bbox = 0;
  7494   8046   	    }
  7495   8047         }
  7496   8048       sqlite3_finalize (stmt);
  7497   8049       stmt = NULL;
  7498   8050       if (!ok)
  7499   8051   	goto error;
................................................................................
  7504   8056   				    compr, quality,
  7505   8057   				    (unsigned short) tile_width,
  7506   8058   				    (unsigned short) tile_height, srid,
  7507   8059   				    horz_res, vert_res, no_data, palette,
  7508   8060   				    strict_resolution, mixed_resolutions,
  7509   8061   				    section_paths, section_md5,
  7510   8062   				    section_summary);
  7511         -	if (no_data != NULL)
  7512         -	rl2_destroy_pixel(no_data);
  7513         -	if (palette != NULL)
  7514         -	rl2_destroy_palette(palette);
         8063  +    if (no_data != NULL)
         8064  +	rl2_destroy_pixel (no_data);
         8065  +    if (palette != NULL)
         8066  +	rl2_destroy_palette (palette);
  7515   8067       if (ret != RL2_OK)
  7516   8068   	goto error;
  7517   8069   
  7518   8070   /* completing the destination coverage */
  7519   8071       sql = "UPDATE main.raster_coverages SET title = ?, "
  7520   8072   	"abstract = ?, statistics = ?, geo_minx = ?, geo_miny = ?, geo_maxx = ?, "
  7521   8073   	"geo_maxy = ?, extent_minx = ?, extent_miny = ?, extent_maxx = ?, "
................................................................................
  7538   8090   	sqlite3_bind_null (stmt, 2);
  7539   8091       else
  7540   8092   	sqlite3_bind_text (stmt, 2, abstract, strlen (abstract), free);
  7541   8093       if (statistics == NULL)
  7542   8094   	sqlite3_bind_null (stmt, 3);
  7543   8095       else
  7544   8096   	sqlite3_bind_blob (stmt, 3, statistics, statistics_sz, free);
  7545         -    if (ok_bbox)
         8097  +    if (ok_geo)
  7546   8098         {
  7547   8099   	  sqlite3_bind_double (stmt, 4, geo_minx);
  7548   8100   	  sqlite3_bind_double (stmt, 5, geo_miny);
  7549   8101   	  sqlite3_bind_double (stmt, 6, geo_maxx);
  7550   8102   	  sqlite3_bind_double (stmt, 7, geo_maxy);
  7551         -	  sqlite3_bind_double (stmt, 8, ext_minx);
  7552         -	  sqlite3_bind_double (stmt, 9, ext_miny);
  7553         -	  sqlite3_bind_double (stmt, 10, ext_maxx);
  7554         -	  sqlite3_bind_double (stmt, 11, ext_maxy);
  7555   8103         }
  7556   8104       else
  7557   8105         {
  7558   8106   	  sqlite3_bind_null (stmt, 4);
  7559   8107   	  sqlite3_bind_null (stmt, 5);
  7560   8108   	  sqlite3_bind_null (stmt, 6);
  7561   8109   	  sqlite3_bind_null (stmt, 7);
         8110  +      }
         8111  +    if (ok_bbox)
         8112  +      {
         8113  +	  sqlite3_bind_double (stmt, 8, ext_minx);
         8114  +	  sqlite3_bind_double (stmt, 9, ext_miny);
         8115  +	  sqlite3_bind_double (stmt, 10, ext_maxx);
         8116  +	  sqlite3_bind_double (stmt, 11, ext_maxy);
         8117  +      }
         8118  +    else
         8119  +      {
  7562   8120   	  sqlite3_bind_null (stmt, 8);
  7563   8121   	  sqlite3_bind_null (stmt, 9);
  7564   8122   	  sqlite3_bind_null (stmt, 10);
  7565   8123   	  sqlite3_bind_null (stmt, 11);
  7566   8124         }
  7567   8125       if (!ok_is_queryable)
  7568   8126   	sqlite3_bind_null (stmt, 12);
................................................................................
  7587   8145       if (!ok_enable_auto_ndvi)
  7588   8146   	sqlite3_bind_null (stmt, 17);
  7589   8147       else
  7590   8148   	sqlite3_bind_int (stmt, 17, enable_auto_ndvi);
  7591   8149       sqlite3_bind_text (stmt, 18, coverage_name, strlen (coverage_name),
  7592   8150   		       SQLITE_STATIC);
  7593   8151       ret = sqlite3_step (stmt);
  7594         -    sqlite3_finalize(stmt);
         8152  +    sqlite3_finalize (stmt);
         8153  +    stmt = NULL;
  7595   8154       if (ret == SQLITE_DONE || ret == SQLITE_ROW)
  7596   8155   	goto ok_continue;
  7597   8156       fprintf (stderr,
  7598   8157   	     "sqlite3_step() error: UPDATE raster_coverages \"%s\"\n",
  7599   8158   	     sqlite3_errmsg (sqlite));
  7600   8159       goto error;
  7601   8160   
................................................................................
  7609   8168   			   "x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
  7610   8169   			   "SELECT pyramid_level, x_resolution_1_1, y_resolution_1_1, x_resolution_1_2, "
  7611   8170   			   "y_resolution_1_2, x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, "
  7612   8171   			   "y_resolution_1_8 FROM \"%s\".\"%s\"", xxcoverage,
  7613   8172   			   xdb, xxcoverage);
  7614   8173       free (xxcoverage);
  7615   8174       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7616         -    sqlite3_free(sql);
         8175  +    sqlite3_free (sql);
  7617   8176       if (ret != SQLITE_OK)
  7618   8177   	goto error;
  7619   8178   
  7620   8179   /* copying  coverage-SECTIONS */
  7621   8180       xcoverage = sqlite3_mprintf ("%s_sections", coverage_name);
  7622   8181       xxcoverage = rl2_double_quoted_sql (xcoverage);
  7623   8182       sqlite3_free (xcoverage);
  7624         -    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, "
  7625         -			   "width, height, file_path, md5_checksum, summary, statistics, geometry) "
  7626         -			   "SELECT section_id, section_name, width, height, file_path, md5_checksum, "
  7627         -			   "summary, statistics, geometry FROM \"%s\".\"%s\"",
  7628         -			   xxcoverage, xdb, xxcoverage);
         8183  +    sql =
         8184  +	sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, "
         8185  +			 "width, height, file_path, md5_checksum, summary, statistics, geometry) "
         8186  +			 "SELECT section_id, section_name, width, height, file_path, md5_checksum, "
         8187  +			 "summary, statistics, geometry FROM \"%s\".\"%s\"",
         8188  +			 xxcoverage, xdb, xxcoverage);
  7629   8189       free (xxcoverage);
  7630   8190       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7631         -    sqlite3_free(sql);
         8191  +    sqlite3_free (sql);
  7632   8192       if (ret != SQLITE_OK)
  7633   8193   	goto error;
  7634   8194   
  7635   8195   /* copying  coverage-TILES */
  7636   8196       xcoverage = sqlite3_mprintf ("%s_tiles", coverage_name);
  7637   8197       xxcoverage = rl2_double_quoted_sql (xcoverage);
  7638   8198       sqlite3_free (xcoverage);
  7639   8199       sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, pyramid_level, "
  7640   8200   			   "section_id, geometry) SELECT tile_id, pyramid_level, section_id, geometry "
  7641   8201   			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
  7642   8202       free (xxcoverage);
  7643   8203       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7644         -    sqlite3_free(sql);
         8204  +    sqlite3_free (sql);
  7645   8205       if (ret != SQLITE_OK)
  7646   8206   	goto error;
  7647   8207   
  7648   8208   /* copying  coverage-TILE_DATA */
  7649   8209       xcoverage = sqlite3_mprintf ("%s_tile_data", coverage_name);
  7650   8210       xxcoverage = rl2_double_quoted_sql (xcoverage);
  7651   8211       sqlite3_free (xcoverage);
  7652   8212       sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, tile_data_odd, "
  7653   8213   			   "tile_data_even) SELECT tile_id, tile_data_odd, tile_data_even "
  7654   8214   			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
  7655   8215       free (xxcoverage);
  7656   8216       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7657         -    sqlite3_free(sql);
         8217  +    sqlite3_free (sql);
  7658   8218       if (ret != SQLITE_OK)
  7659   8219   	goto error;
  7660   8220   
  7661   8221   /* copying KEYWORDS */
  7662   8222       sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_keyword "
  7663   8223   			   "(coverage_name, keyword) SELECT coverage_name, keyword "
  7664   8224   			   "FROM \"%s\".raster_coverages_keyword", xdb);
  7665   8225       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7666         -    sqlite3_free(sql);
         8226  +    sqlite3_free (sql);
  7667   8227       if (ret != SQLITE_OK)
  7668   8228   	goto error;
  7669   8229   
  7670   8230   /* copying SRID */
  7671   8231       sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_srid "
  7672   8232   			   "(coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx) "
  7673   8233   			   "SELECT coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx "
  7674   8234   			   "FROM \"%s\".raster_coverages_srid", xdb);
  7675   8235       ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
  7676         -    sqlite3_free(sql);
         8236  +    sqlite3_free (sql);
  7677   8237       if (ret != SQLITE_OK)
  7678   8238   	goto error;
  7679   8239   
  7680   8240       free (xdb);
  7681   8241       return RL2_OK;
  7682   8242   
  7683   8243     error:
  7684   8244       if (xdb != NULL)
  7685   8245   	free (xdb);
  7686   8246       if (stmt != NULL)
  7687   8247   	sqlite3_finalize (stmt);
  7688   8248       return RL2_ERROR;
  7689   8249   }
         8250  +
         8251  +RL2_PRIVATE int
         8252  +do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg)
         8253  +{
         8254  +/* testing for an empty Palette Coverage */
         8255  +    rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg;
         8256  +    int ret;
         8257  +    char **results;
         8258  +    int rows;
         8259  +    int columns;
         8260  +    int i;
         8261  +    int initial = 0;
         8262  +    char *xcoverage;
         8263  +    char *xxcoverage;
         8264  +
         8265  +    if (coverage == NULL)
         8266  +	return RL2_ERROR;
         8267  +    if (coverage->coverageName == NULL)
         8268  +	return RL2_ERROR;
         8269  +
         8270  +    xcoverage = sqlite3_mprintf ("%s_tiles", coverage->coverageName);
         8271  +    xxcoverage = rl2_double_quoted_sql (xcoverage);
         8272  +    sqlite3_free (xcoverage);
         8273  +    char *sql = sqlite3_mprintf ("SELECT Count(*) FROM \"%s\"",
         8274  +				 xxcoverage);
         8275  +    free (xxcoverage);
         8276  +    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL);
         8277  +    sqlite3_free (sql);
         8278  +    if (ret != SQLITE_OK)
         8279  +	return RL2_ERROR;
         8280  +    for (i = 1; i <= rows; i++)
         8281  +      {
         8282  +	  if (atoi (results[(i * columns) + 0]) == 0)
         8283  +	      initial = 1;
         8284  +      }
         8285  +    sqlite3_free_table (results);
         8286  +    if (initial)
         8287  +	return RL2_TRUE;
         8288  +    return RL2_FALSE;
         8289  +}
         8290  +
         8291  +RL2_DECLARE int
         8292  +rl2_install_dbms_palette_from_tiff (sqlite3 * handle, rl2CoveragePtr coverage,
         8293  +				    rl2TiffOriginPtr tiff)
         8294  +{
         8295  +/*attempting to merge/update a Coverage's Palette */
         8296  +    int i;
         8297  +    int j;
         8298  +    int changed = 0;
         8299  +    int maxPalette = 0;
         8300  +    unsigned char red[256];
         8301  +    unsigned char green[256];
         8302  +    unsigned char blue[256];
         8303  +    int ok;
         8304  +    rl2PalettePtr palette = NULL;
         8305  +    rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage;
         8306  +    rl2PrivTiffOriginPtr origin = (rl2PrivTiffOriginPtr) tiff;
         8307  +    if (cvg == NULL || origin == NULL)
         8308  +	return RL2_ERROR;
         8309  +
         8310  +    for (i = 0; i < origin->maxPalette; i++)
         8311  +      {
         8312  +	  /* checking TIFF palette entries */
         8313  +	  unsigned char tiff_red = origin->red[i];
         8314  +	  unsigned char tiff_green = origin->green[i];
         8315  +	  unsigned char tiff_blue = origin->blue[i];
         8316  +	  ok = 0;
         8317  +	  for (j = 0; j < maxPalette; j++)
         8318  +	    {
         8319  +		if (tiff_red == red[j] && tiff_green == green[j]
         8320  +		    && tiff_blue == blue[j])
         8321  +		  {
         8322  +		      /* found a matching color */
         8323  +		      ok = 1;
         8324  +		      break;
         8325  +		  }
         8326  +	    }
         8327  +	  if (!ok)
         8328  +	    {
         8329  +		/* attempting to insert a new color into the pseudo-Palette */
         8330  +		if (maxPalette == 256)
         8331  +		    goto error;
         8332  +		red[maxPalette] = tiff_red;
         8333  +		green[maxPalette] = tiff_green;
         8334  +		blue[maxPalette] = tiff_blue;
         8335  +		maxPalette++;
         8336  +		changed = 1;
         8337  +	    }
         8338  +      }
         8339  +    if (changed)
         8340  +      {
         8341  +	  /* updating the DBMS Palette */
         8342  +	  palette = rl2_create_palette (maxPalette);
         8343  +	  if (palette == NULL)
         8344  +	      goto error;
         8345  +	  for (j = 0; j < maxPalette; j++)
         8346  +	      rl2_set_palette_color (palette, j, red[j], green[j], blue[j]);
         8347  +	  if (rl2_update_dbms_palette (handle, cvg->coverageName, palette) !=
         8348  +	      RL2_OK)
         8349  +	      goto error;
         8350  +      }
         8351  +    set_remapped_palette (origin, palette);
         8352  +    rl2_destroy_palette (palette);
         8353  +    return RL2_OK;
         8354  +
         8355  +  error:
         8356  +    if (palette != NULL)
         8357  +	rl2_destroy_palette (palette);
         8358  +    return RL2_ERROR;
         8359  +}

Changes to src/rl2gif.c.

   602    602   	rl2_destroy_palette (palette);
   603    603       return NULL;
   604    604   }
   605    605   
   606    606   RL2_PRIVATE int
   607    607   rl2_decode_gif (const unsigned char *gif, int gif_size, unsigned int *xwidth,
   608    608   		unsigned int *xheight, unsigned char *xsample_type,
   609         -		unsigned char *xpixel_type, unsigned char **blob, int *blob_sz,
   610         -		rl2PalettePtr * palette)
          609  +		unsigned char *xpixel_type, unsigned char **blob,
          610  +		int *blob_sz, rl2PalettePtr * palette)
   611    611   {
   612    612   /* attempting to create a raster from a GIF image - raw block */
   613    613       struct gif_memory_buffer membuf;
   614    614   #ifdef GIFLIB_MAJOR
   615    615       int ErrorCode;
   616    616   #endif
   617    617       GifFileType *GifFile = NULL;

Changes to src/rl2import.c.

   100    100       tile->blob_odd = NULL;
   101    101       tile->blob_even = NULL;
   102    102       rl2_destroy_raster (tile->raster);
   103    103       tile->raster = NULL;
   104    104   }
   105    105   
   106    106   static void
   107         -addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row, unsigned int col,
   108         -		     double minx, double maxy)
          107  +addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row,
          108  +		     unsigned int col, double minx, double maxy)
   109    109   {
   110    110   /* adding a Tile to some AuxImporter container */
   111    111       rl2AuxImporterTilePtr tile;
   112    112       if (aux == NULL)
   113    113   	return;
   114    114   
   115    115       tile = malloc (sizeof (rl2AuxImporterTile));
................................................................................
   346    346       switch (aux->origin_type)
   347    347         {
   348    348         case RL2_ORIGIN_ASCII_GRID:
   349    349   	  ascii_grid_origin = (rl2AsciiGridOriginPtr) (aux->origin);
   350    350   	  tile->raster =
   351    351   	      rl2_get_tile_from_ascii_grid_origin ((rl2CoveragePtr)
   352    352   						   (aux->coverage),
   353         -						   ascii_grid_origin, tile->row,
   354         -						   tile->col, aux->verbose);
          353  +						   ascii_grid_origin,
          354  +						   tile->row, tile->col,
          355  +						   aux->verbose);
   355    356   	  break;
   356    357         case RL2_ORIGIN_JPEG:
   357    358   	  raster_origin = (rl2RasterPtr) (aux->origin);
   358    359   	  tile->raster =
   359    360   	      rl2_get_tile_from_jpeg_origin ((rl2CoveragePtr) (aux->coverage),
   360    361   					     raster_origin, tile->row,
   361         -					     tile->col, aux->forced_conversion,
          362  +					     tile->col,
          363  +					     aux->forced_conversion,
   362    364   					     aux->verbose);
   363    365   	  break;
   364    366         case RL2_ORIGIN_JPEG2000:
   365    367   	  raster_origin = (rl2RasterPtr) (aux->origin);
   366    368   	  tile->raster =
   367    369   	      rl2_get_tile_from_jpeg2000_origin ((rl2CoveragePtr)
   368         -						 (aux->coverage), raster_origin,
   369         -						 tile->row, tile->col,
          370  +						 (aux->coverage),
          371  +						 raster_origin, tile->row,
          372  +						 tile->col,
   370    373   						 aux->forced_conversion,
   371    374   						 aux->verbose);
   372    375   	  break;
   373    376         case RL2_ORIGIN_TIFF:
   374    377   	  tiff_origin = (rl2TiffOriginPtr) (aux->origin);
   375    378   	  tile->raster =
   376    379   	      rl2_get_tile_from_tiff_origin ((rl2CoveragePtr) (aux->coverage),
   377         -					     tiff_origin, tile->row, tile->col,
   378         -					     aux->srid, aux->verbose);
          380  +					     tiff_origin, tile->row,
          381  +					     tile->col, aux->srid,
          382  +					     aux->verbose);
   379    383   	  break;
   380    384         case RL2_ORIGIN_RAW:
   381    385   	  raster_origin = (rl2RasterPtr) (aux->origin);
   382    386   	  tile->raster =
   383    387   	      rl2_get_tile_from_raw_pixels ((rl2CoveragePtr) (aux->coverage),
   384    388   					    raster_origin, tile->row,
   385    389   					    tile->col);
................................................................................
   588    592         }
   589    593       if (coverage->mixedResolutions)
   590    594         {
   591    595   	  /* accepting any resolution */
   592    596         }
   593    597       else if (coverage->strictResolution)
   594    598         {
   595         -	  /* enforcing Strict Resolution check */
   596         -	  if (res_x != coverage->hResolution)
          599  +	  /* enforcing Strict Resolution check */ double x_diff =
          600  +	      fabs (coverage->hResolution - res_x);
          601  +	  double y_diff = fabs (coverage->vResolution - res_y);
          602  +	  double x_lim = coverage->hResolution / 1000000.0;
          603  +	  double y_lim = coverage->vResolution / 1000000.0;
          604  +	  if (x_diff > x_lim)
   597    605   	    {
   598    606   		if (verbose)
   599    607   		    fprintf (stderr,
   600    608   			     "Mismatching Horizontal Resolution (Strict) !!!\n");
   601    609   		goto error;
   602    610   	    }
   603         -	  if (res_y != coverage->vResolution)
          611  +	  if (y_diff > y_lim)
   604    612   	    {
   605    613   		if (verbose)
   606    614   		    fprintf (stderr,
   607    615   			     "Mismatching Vertical Resolution (Strict) !!!\n");
   608    616   		goto error;
   609    617   	    }
   610    618         }
................................................................................
   637    645   	  fprintf (stderr, "Coverage/ASCII mismatch\n");
   638    646   	  goto error;
   639    647         }
   640    648       no_data = rl2_get_coverage_no_data (cvg);
   641    649   
   642    650   /* INSERTing the section */
   643    651       if (!rl2_do_insert_section
   644         -	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
   645         -	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
          652  +	(handle, src_path, section, srid, width, height, minx, miny, maxx,
          653  +	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
   646    654   	 coverage->sectionSummary, stmt_sect, &section_id))
   647    655   	goto error;
   648    656       section_stats = rl2_create_raster_statistics (sample_type, 1);
   649    657       if (section_stats == NULL)
   650    658   	goto error;
   651    659   /* INSERTing the base-levels */
   652    660       if (coverage->mixedResolutions)
................................................................................
   663    671   	      (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl))
   664    672   	      goto error;
   665    673         }
   666    674   
   667    675   /* preparing all Tile Requests */
   668    676       aux =
   669    677   	createAuxImporter (coverage, srid, maxx, miny, tile_w, tile_h, res_x,
   670         -			   res_y, RL2_ORIGIN_ASCII_GRID, origin, RL2_CONVERT_NO,
   671         -			   verbose, compression, 100);
          678  +			   res_y, RL2_ORIGIN_ASCII_GRID, origin,
          679  +			   RL2_CONVERT_NO, verbose, compression, 100);
   672    680       tile_maxy = maxy;
   673    681       for (row = 0; row < height; row += tile_h)
   674    682         {
   675    683   	  tile_minx = minx;
   676    684   	  for (col = 0; col < width; col += tile_w)
   677    685   	    {
   678    686   		/* adding a Tile request */
................................................................................
   908    916   }
   909    917   
   910    918   #ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
   911    919   
   912    920   static int
   913    921   check_jpeg2000_origin_compatibility (rl2RasterPtr raster,
   914    922   				     rl2CoveragePtr coverage,
   915         -				     unsigned int *width, unsigned int *height,
          923  +				     unsigned int *width,
          924  +				     unsigned int *height,
   916    925   				     unsigned char *forced_conversion)
   917    926   {
   918    927   /* checking if the Jpeg2000 and the Coverage are mutually compatible */
   919    928       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
   920    929       rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage;
   921    930       if (rst == NULL || cvg == NULL)
   922    931   	return 0;
................................................................................
   994   1003   	    {
   995   1004   		*width = rst->width;
   996   1005   		*height = rst->height;
   997   1006   		*forced_conversion = RL2_CONVERT_NO;
   998   1007   		return 1;
   999   1008   	    }
  1000   1009         }
  1001         -    if (rst->sampleType == RL2_SAMPLE_UINT16 && rst->pixelType == RL2_PIXEL_RGB
  1002         -	&& rst->nBands == 3)
         1010  +    if (rst->sampleType == RL2_SAMPLE_UINT16
         1011  +	&& rst->pixelType == RL2_PIXEL_RGB && rst->nBands == 3)
  1003   1012         {
  1004   1013   	  if (cvg->sampleType == RL2_SAMPLE_UINT16
  1005   1014   	      && cvg->pixelType == RL2_PIXEL_RGB && cvg->nBands == 3)
  1006   1015   	    {
  1007   1016   		*width = rst->width;
  1008   1017   		*height = rst->height;
  1009   1018   		*forced_conversion = RL2_CONVERT_NO;
................................................................................
  1229   1238   	  maxy = height - 1.0;
  1230   1239   	  res_x = 1.0;
  1231   1240   	  res_y = 1.0;
  1232   1241         }
  1233   1242       raster_in = (rl2PrivRasterPtr) rst_in;
  1234   1243       xml_summary =
  1235   1244   	rl2_build_jpeg_xml_summary (width, height, raster_in->pixelType,
  1236         -				    is_georeferenced, res_x, res_y, minx, miny,
  1237         -				    maxx, maxy);
         1245  +				    is_georeferenced, res_x, res_y, minx,
         1246  +				    miny, maxx, maxy);
  1238   1247   
  1239   1248       printf ("------------------\n");
  1240   1249       if (total > 1)
  1241   1250   	printf ("%d/%d) Importing: %s\n", current, total, src_path);
  1242   1251       else
  1243   1252   	printf ("Importing: %s\n", src_path);
  1244   1253       printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
  1266   1275         }
  1267   1276       if (coverage->mixedResolutions)
  1268   1277         {
  1269   1278   	  /* accepting any resolution */
  1270   1279         }
  1271   1280       else if (coverage->strictResolution)
  1272   1281         {
  1273         -	  /* enforcing Strict Resolution check */
  1274         -	  if (res_x != coverage->hResolution)
         1282  +	  /* enforcing Strict Resolution check */ double x_diff =
         1283  +	      fabs (coverage->hResolution - res_x);
         1284  +	  double y_diff = fabs (coverage->vResolution - res_y);
         1285  +	  double x_lim = coverage->hResolution / 1000000.0;
         1286  +	  double y_lim = coverage->vResolution / 1000000.0;
         1287  +	  if (x_diff > x_lim)
  1275   1288   	    {
  1276   1289   		if (verbose)
  1277   1290   		    fprintf (stderr,
  1278   1291   			     "Mismatching Horizontal Resolution (Strict) !!!\n");
  1279   1292   		goto error;
  1280   1293   	    }
  1281         -	  if (res_y != coverage->vResolution)
         1294  +	  if (y_diff > y_lim)
  1282   1295   	    {
  1283   1296   		if (verbose)
  1284   1297   		    fprintf (stderr,
  1285   1298   			     "Mismatching Vertical Resolution (Strict) !!!\n");
  1286   1299   		goto error;
  1287   1300   	    }
  1288   1301         }
................................................................................
  1309   1322   	    }
  1310   1323         }
  1311   1324   
  1312   1325       no_data = rl2_get_coverage_no_data (cvg);
  1313   1326   
  1314   1327   /* INSERTing the section */
  1315   1328       if (!rl2_do_insert_section
  1316         -	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
  1317         -	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
         1329  +	(handle, src_path, section, srid, width, height, minx, miny, maxx,
         1330  +	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
  1318   1331   	 coverage->sectionSummary, stmt_sect, &section_id))
  1319   1332   	goto error;
  1320   1333       section_stats = rl2_create_raster_statistics (sample_type, num_bands);
  1321   1334       if (section_stats == NULL)
  1322   1335   	goto error;
  1323   1336   /* INSERTing the base-levels */
  1324   1337       if (coverage->mixedResolutions)
................................................................................
  1677   1690   	  maxy = height - 1.0;
  1678   1691   	  res_x = 1.0;
  1679   1692   	  res_y = 1.0;
  1680   1693         }
  1681   1694       raster_in = (rl2PrivRasterPtr) rst_in;
  1682   1695       xml_summary =
  1683   1696   	rl2_build_jpeg2000_xml_summary (width, height, raster_in->sampleType,
  1684         -					raster_in->pixelType, raster_in->nBands,
  1685         -					is_georeferenced, res_x, res_y, minx,
  1686         -					miny, maxx, maxy, tile_width,
  1687         -					tile_height);
         1697  +					raster_in->pixelType,
         1698  +					raster_in->nBands, is_georeferenced,
         1699  +					res_x, res_y, minx, miny, maxx, maxy,
         1700  +					tile_width, tile_height);
  1688   1701   
  1689   1702       printf ("------------------\n");
  1690   1703       if (total > 1)
  1691   1704   	printf ("%d/%d) Importing: %s\n", current, total, src_path);
  1692   1705       else
  1693   1706   	printf ("Importing: %s\n", src_path);
  1694   1707       printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
  1717   1730       if (coverage->mixedResolutions)
  1718   1731         {
  1719   1732   	  /* accepting any resolution */
  1720   1733         }
  1721   1734       else if (coverage->strictResolution)
  1722   1735         {
  1723   1736   	  /* enforcing Strict Resolution check */
  1724         -	  if (res_x != coverage->hResolution)
         1737  +	  double x_diff = fabs (coverage->hResolution - res_x);
         1738  +	  double y_diff = fabs (coverage->vResolution - res_y);
         1739  +	  double x_lim = coverage->hResolution / 1000000.0;
         1740  +	  double y_lim = coverage->vResolution / 1000000.0;
         1741  +	  if (x_diff > x_lim)
  1725   1742   	    {
  1726   1743   		if (verbose)
  1727   1744   		    fprintf (stderr,
  1728   1745   			     "Mismatching Horizontal Resolution (Strict) !!!\n");
  1729   1746   		goto error;
  1730   1747   	    }
  1731         -	  if (res_y != coverage->vResolution)
         1748  +	  if (y_diff > y_lim)
  1732   1749   	    {
  1733   1750   		if (verbose)
  1734   1751   		    fprintf (stderr,
  1735   1752   			     "Mismatching Vertical Resolution (Strict) !!!\n");
  1736   1753   		goto error;
  1737   1754   	    }
  1738   1755         }
................................................................................
  1759   1776   	    }
  1760   1777         }
  1761   1778   
  1762   1779       no_data = rl2_get_coverage_no_data (cvg);
  1763   1780   
  1764   1781   /* INSERTing the section */
  1765   1782       if (!rl2_do_insert_section
  1766         -	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
  1767         -	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
         1783  +	(handle, src_path, section, srid, width, height, minx, miny, maxx,
         1784  +	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
  1768   1785   	 coverage->sectionSummary, stmt_sect, &section_id))
  1769   1786   	goto error;
  1770   1787       section_stats = rl2_create_raster_statistics (sample_type, num_bands);
  1771   1788       if (section_stats == NULL)
  1772   1789   	goto error;
  1773   1790   /* INSERTing the base-levels */
  1774   1791       if (coverage->mixedResolutions)
................................................................................
  2070   2087       rl2AuxImporterTilePtr *thread_slots = NULL;
  2071   2088       int thread_count;
  2072   2089   
  2073   2090       if (is_ascii_grid (src_path))
  2074   2091   	return do_import_ascii_grid (handle, max_threads, src_path, cvg,
  2075   2092   				     section, force_srid, tile_w, tile_h,
  2076   2093   				     pyramidize, sample_type, compression,
  2077         -				     stmt_data, stmt_tils, stmt_sect, stmt_levl,
  2078         -				     stmt_upd_sect, verbose, current, total);
         2094  +				     stmt_data, stmt_tils, stmt_sect,
         2095  +				     stmt_levl, stmt_upd_sect, verbose,
         2096  +				     current, total);
  2079   2097   
  2080   2098       if (is_jpeg_image (src_path))
  2081   2099   	return do_import_jpeg_image (handle, max_threads, src_path, cvg,
  2082   2100   				     section, force_srid, tile_w, tile_h,
  2083   2101   				     pyramidize, sample_type, num_bands,
  2084         -				     compression, quality, stmt_data, stmt_tils,
  2085         -				     stmt_sect, stmt_levl, stmt_upd_sect,
  2086         -				     verbose, current, total);
         2102  +				     compression, quality, stmt_data,
         2103  +				     stmt_tils, stmt_sect, stmt_levl,
         2104  +				     stmt_upd_sect, verbose, current, total);
  2087   2105   
  2088   2106   #ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
  2089   2107       if (is_jpeg2000_image (src_path))
  2090   2108   	return do_import_jpeg2000_image (handle, max_threads, src_path, cvg,
  2091   2109   					 section, force_srid, tile_w, tile_h,
  2092   2110   					 pyramidize, sample_type, num_bands,
  2093   2111   					 compression, quality, stmt_data,
................................................................................
  2171   2189       if (coverage->mixedResolutions)
  2172   2190         {
  2173   2191   	  /* accepting any resolution */
  2174   2192         }
  2175   2193       else if (coverage->strictResolution)
  2176   2194         {
  2177   2195   	  /* enforcing Strict Resolution check */
  2178         -	  if (res_x != coverage->hResolution)
         2196  +	  double x_diff = fabs (coverage->hResolution - res_x);
         2197  +	  double y_diff = fabs (coverage->vResolution - res_y);
         2198  +	  double x_lim = coverage->hResolution / 1000000.0;
         2199  +	  double y_lim = coverage->vResolution / 1000000.0;
         2200  +	  if (x_diff > x_lim)
  2179   2201   	    {
  2180   2202   		if (verbose)
  2181   2203   		    fprintf (stderr,
  2182   2204   			     "Mismatching Horizontal Resolution (Strict) !!!\n");
  2183   2205   		goto error;
  2184   2206   	    }
  2185         -	  if (res_y != coverage->vResolution)
         2207  +	  if (y_diff > y_lim)
  2186   2208   	    {
  2187   2209   		if (verbose)
  2188   2210   		    fprintf (stderr,
  2189   2211   			     "Mismatching Vertical Resolution (Strict) !!!\n");
  2190   2212   		goto error;
  2191   2213   	    }
  2192   2214         }
................................................................................
  2212   2234   		goto error;
  2213   2235   	    }
  2214   2236         }
  2215   2237   
  2216   2238       if (pixel_type == RL2_PIXEL_PALETTE)
  2217   2239         {
  2218   2240   	  /* remapping the Palette */
         2241  +	  if (do_check_initial_palette (handle, cvg) == RL2_TRUE)
         2242  +	    {
         2243  +		if (rl2_install_dbms_palette_from_tiff (handle, cvg, origin) !=
         2244  +		    RL2_OK)
         2245  +		  {
         2246  +		      fprintf (stderr,
         2247  +			       "Unable to install the initial Palette !!!\n");
         2248  +		      goto error;
         2249  +		  }
         2250  +	    }
  2219   2251   	  if (rl2_check_dbms_palette (handle, cvg, origin) != RL2_OK)
  2220   2252   	    {
  2221   2253   		fprintf (stderr, "Mismatching Palette !!!\n");
  2222   2254   		goto error;
  2223   2255   	    }
  2224   2256         }
  2225   2257   
  2226         -    if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose) !=
  2227         -	RL2_TRUE)
         2258  +    if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose)
         2259  +	!= RL2_TRUE)
  2228   2260         {
  2229   2261   	  fprintf (stderr, "Coverage/TIFF mismatch\n");
  2230   2262   	  goto error;
  2231   2263         }
  2232   2264       no_data = rl2_get_coverage_no_data (cvg);
  2233   2265   
  2234   2266   /* INSERTing the section */
  2235   2267       if (!rl2_do_insert_section
  2236         -	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
  2237         -	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
         2268  +	(handle, src_path, section, srid, width, height, minx, miny, maxx,
         2269  +	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
  2238   2270   	 coverage->sectionSummary, stmt_sect, &section_id))
  2239   2271   	goto error;
  2240   2272       section_stats = rl2_create_raster_statistics (sample_type, num_bands);
  2241   2273       if (section_stats == NULL)
  2242   2274   	goto error;
  2243   2275   /* INSERTing the base-levels */
  2244   2276       if (coverage->mixedResolutions)
................................................................................
  2534   2566   		      if ((c_file.attrib & _A_RDONLY) == _A_RDONLY
  2535   2567   			  || (c_file.attrib & _A_NORMAL) == _A_NORMAL)
  2536   2568   			{
  2537   2569   			    path =
  2538   2570   				sqlite3_mprintf ("%s/%s", dir_path,
  2539   2571   						 c_file.name);
  2540   2572   			    ret =
  2541         -				do_import_file (handle, max_threads, path, cvg,
  2542         -						section, worldfile, force_srid,
  2543         -						pyramidize, sample_type,
  2544         -						pixel_type, num_bands, tile_w,
  2545         -						tile_h, compression, quality,
  2546         -						stmt_data, stmt_tils, stmt_sect,
  2547         -						stmt_levl, stmt_upd_sect,
  2548         -						verbose, cnt + 1, total);
         2573  +				do_import_file (handle, max_threads, path,
         2574  +						cvg, section, worldfile,
         2575  +						force_srid, pyramidize,
         2576  +						sample_type, pixel_type,
         2577  +						num_bands, tile_w, tile_h,
         2578  +						compression, quality,
         2579  +						stmt_data, stmt_tils,
         2580  +						stmt_sect, stmt_levl,
         2581  +						stmt_upd_sect, verbose,
         2582  +						cnt + 1, total);
  2549   2583   			    sqlite3_free (path);
  2550   2584   			    if (!ret)
  2551   2585   				goto error;
  2552   2586   			    cnt++;
  2553   2587   			}
  2554   2588   		      if (_findnext (hFile, &c_file) != 0)
  2555   2589   			  break;
................................................................................
  2772   2806   	       stmt_sect, stmt_levl, stmt_upd_sect, verbose, -1, -1))
  2773   2807   	      goto error;
  2774   2808         }
  2775   2809       else
  2776   2810         {
  2777   2811   	  /* importing all Image files from a whole directory */
  2778   2812   	  if (!do_import_dir
  2779         -	      (handle, max_threads, dir_path, file_ext, cvg, section, worldfile,
  2780         -	       force_srid, pyramidize, sample_type, pixel_type, num_bands,
  2781         -	       tile_w, tile_h, compression, quality, stmt_data, stmt_tils,
  2782         -	       stmt_sect, stmt_levl, stmt_upd_sect, verbose))
         2813  +	      (handle, max_threads, dir_path, file_ext, cvg, section,
         2814  +	       worldfile, force_srid, pyramidize, sample_type, pixel_type,
         2815  +	       num_bands, tile_w, tile_h, compression, quality, stmt_data,
         2816  +	       stmt_tils, stmt_sect, stmt_levl, stmt_upd_sect, verbose))
  2783   2817   	      goto error;
  2784   2818         }
  2785   2819   
  2786   2820       sqlite3_finalize (stmt_upd_sect);
  2787   2821       sqlite3_finalize (stmt_sect);
  2788   2822       sqlite3_finalize (stmt_levl);
  2789   2823       sqlite3_finalize (stmt_tils);
................................................................................
  2894   2928   		*p_out++ = *p_in++;
  2895   2929   	    }
  2896   2930         }
  2897   2931   }
  2898   2932   
  2899   2933   static void
  2900   2934   copy_uint8_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
  2901         -			   unsigned char num_bands, unsigned int width,
  2902         -			   unsigned int height,
  2903         -			   unsigned int tile_width,
  2904         -			   unsigned int tile_height, unsigned int base_y,
  2905         -			   unsigned int base_x)
         2935  +			   unsigned char pixel_type, unsigned char num_bands,
         2936  +			   unsigned int width, unsigned int height,
         2937  +			   unsigned int tile_width, unsigned int tile_height,
         2938  +			   unsigned int base_y, unsigned int base_x)
  2906   2939   {
  2907   2940   /* copying UINT8 pixels from the output buffer into the tile */
  2908   2941       unsigned int x;
  2909   2942       unsigned int y;
  2910   2943       int b;
  2911   2944       const unsigned char *p_in;
  2912   2945       unsigned char *p_out = tile;
................................................................................
  2922   2955   	    {
  2923   2956   		if ((base_x + x) >= width)
  2924   2957   		  {
  2925   2958   		      p_out += num_bands;
  2926   2959   		      p_in += num_bands;
  2927   2960   		      continue;
  2928   2961   		  }
  2929         -		for (b = 0; b < num_bands; b++)
  2930         -		    *p_out++ = *p_in++;
         2962  +		if (pixel_type == RL2_PIXEL_MONOCHROME)
         2963  +		  {
         2964  +		      unsigned char pxl = *p_in++;
         2965  +		      if (pxl == 0)
         2966  +			  *p_out++ = 1;
         2967  +		      else
         2968  +			  *p_out++ = 0;
         2969  +		  }
         2970  +		else if (pixel_type == RL2_PIXEL_PALETTE)
         2971  +		  {
         2972  +		      unsigned char pxl = *p_in++;
         2973  +		      if (pxl == 0)
         2974  +			  *p_out++ = 1;
         2975  +		      else
         2976  +			  *p_out++ = 0;
         2977  +		  }
         2978  +		else
         2979  +		  {
         2980  +		      for (b = 0; b < num_bands; b++)
         2981  +			  *p_out++ = *p_in++;
         2982  +		  }
  2931   2983   	    }
  2932   2984         }
  2933   2985   }
  2934   2986   
  2935   2987   static void
  2936   2988   copy_int16_outbuf_to_tile (const short *outbuf, short *tile,
  2937   2989   			   unsigned int width,
................................................................................
  2961   3013   		  }
  2962   3014   		*p_out++ = *p_in++;
  2963   3015   	    }
  2964   3016         }
  2965   3017   }
  2966   3018   
  2967   3019   static void
  2968         -copy_uint16_outbuf_to_tile (const unsigned short *outbuf, unsigned short *tile,
  2969         -			    unsigned char num_bands, unsigned int width,
  2970         -			    unsigned int height,
  2971         -			    unsigned int tile_width,
  2972         -			    unsigned int tile_height, unsigned int base_y,
  2973         -			    unsigned int base_x)
         3020  +copy_uint16_outbuf_to_tile (const unsigned short *outbuf,
         3021  +			    unsigned short *tile, unsigned char num_bands,
         3022  +			    unsigned int width, unsigned int height,
         3023  +			    unsigned int tile_width, unsigned int tile_height,
         3024  +			    unsigned int base_y, unsigned int base_x)
  2974   3025   {
  2975   3026   /* copying UINT16 pixels from the output buffer into the tile */
  2976   3027       unsigned int x;
  2977   3028       unsigned int y;
  2978   3029       int b;
  2979   3030       const unsigned short *p_in;
  2980   3031       unsigned short *p_out = tile;
................................................................................
  3125   3176   		*p_out++ = *p_in++;
  3126   3177   	    }
  3127   3178         }
  3128   3179   }
  3129   3180   
  3130   3181   static void
  3131   3182   copy_from_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
  3132         -			  unsigned char sample_type, unsigned char num_bands,
  3133         -			  unsigned int width, unsigned int height,
  3134         -			  unsigned int tile_width, unsigned int tile_height,
  3135         -			  unsigned int base_y, unsigned int base_x)
         3183  +			  unsigned char sample_type, unsigned char pixel_type,
         3184  +			  unsigned char num_bands, unsigned int width,
         3185  +			  unsigned int height, unsigned int tile_width,
         3186  +			  unsigned int tile_height, unsigned int base_y,
         3187  +			  unsigned int base_x)
  3136   3188   {
  3137   3189   /* copying pixels from the output buffer into the tile */
  3138   3190       switch (sample_type)
  3139   3191         {
  3140   3192         case RL2_SAMPLE_INT8:
  3141   3193   	  copy_int8_outbuf_to_tile ((char *) outbuf,
  3142   3194   				    (char *) tile, width, height, tile_width,
  3143   3195   				    tile_height, base_y, base_x);
  3144   3196   	  break;
  3145   3197         case RL2_SAMPLE_INT16:
  3146   3198   	  copy_int16_outbuf_to_tile ((short *) outbuf,
  3147         -				     (short *) tile, width, height, tile_width,
  3148         -				     tile_height, base_y, base_x);
         3199  +				     (short *) tile, width, height,
         3200  +				     tile_width, tile_height, base_y, base_x);
  3149   3201   	  break;
  3150   3202         case RL2_SAMPLE_UINT16:
  3151   3203   	  copy_uint16_outbuf_to_tile ((unsigned short *) outbuf,
  3152   3204   				      (unsigned short *) tile, num_bands,
  3153   3205   				      width, height, tile_width, tile_height,
  3154   3206   				      base_y, base_x);
  3155   3207   	  break;
................................................................................
  3161   3213         case RL2_SAMPLE_UINT32:
  3162   3214   	  copy_uint32_outbuf_to_tile ((unsigned int *) outbuf,
  3163   3215   				      (unsigned int *) tile, width, height,
  3164   3216   				      tile_width, tile_height, base_y, base_x);
  3165   3217   	  break;
  3166   3218         case RL2_SAMPLE_FLOAT:
  3167   3219   	  copy_float_outbuf_to_tile ((float *) outbuf,
  3168         -				     (float *) tile, width, height, tile_width,
  3169         -				     tile_height, base_y, base_x);
         3220  +				     (float *) tile, width, height,
         3221  +				     tile_width, tile_height, base_y, base_x);
  3170   3222   	  break;
  3171   3223         case RL2_SAMPLE_DOUBLE:
  3172   3224   	  copy_double_outbuf_to_tile ((double *) outbuf,
  3173   3225   				      (double *) tile, width, height,
  3174   3226   				      tile_width, tile_height, base_y, base_x);
  3175   3227   	  break;
  3176   3228         default:
  3177   3229   	  copy_uint8_outbuf_to_tile ((unsigned char *) outbuf,
  3178         -				     (unsigned char *) tile, num_bands, width,
  3179         -				     height, tile_width, tile_height, base_y,
  3180         -				     base_x);
         3230  +				     (unsigned char *) tile, pixel_type,
         3231  +				     num_bands, width, height, tile_width,
         3232  +				     tile_height, base_y, base_x);
  3181   3233   	  break;
  3182   3234         };
  3183   3235   }
  3184   3236   
  3185   3237   static int
  3186         -export_geotiff_common (sqlite3 * handle, int max_threads, const char *dst_path,
  3187         -		       rl2CoveragePtr cvg, int by_section,
  3188         -		       sqlite3_int64 section_id, double x_res, double y_res,
  3189         -		       double minx, double miny, double maxx, double maxy,
  3190         -		       unsigned int width, unsigned int height,
         3238  +export_geotiff_common (sqlite3 * handle, int max_threads,
         3239  +		       const char *dst_path, rl2CoveragePtr cvg,
         3240  +		       int by_section, sqlite3_int64 section_id, double x_res,
         3241  +		       double y_res, double minx, double miny, double maxx,
         3242  +		       double maxy, unsigned int width, unsigned int height,
  3191   3243   		       unsigned char compression, unsigned int tile_sz,
  3192   3244   		       int with_worldfile)
  3193   3245   {
  3194   3246   /* exporting a GeoTIFF common implementation */
  3195   3247       rl2RasterPtr raster = NULL;
  3196   3248       rl2PalettePtr palette = NULL;
  3197   3249       rl2PalettePtr plt2 = NULL;
................................................................................
  3254   3306   	    }
  3255   3307         }
  3256   3308   
  3257   3309       if (by_section)
  3258   3310         {
  3259   3311   	  /* just a single Section */
  3260   3312   	  if (rl2_get_section_raw_raster_data
  3261         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  3262         -	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3263         -	       pixel_type) != RL2_OK)
         3313  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         3314  +	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
         3315  +	       &palette, pixel_type) != RL2_OK)
  3264   3316   	      goto error;
  3265   3317         }
  3266   3318       else
  3267   3319         {
  3268   3320   	  /* whole Coverage */
  3269   3321   	  if (rl2_get_raw_raster_data
  3270         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  3271         -	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
         3322  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         3323  +	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3272   3324   	       pixel_type) != RL2_OK)
  3273   3325   	      goto error;
  3274   3326         }
  3275   3327   
  3276   3328   /* computing the sample size */
  3277   3329       switch (sample_type)
  3278   3330         {
................................................................................
  3311   3363   			       "rl2tool Export: Insufficient Memory !!!\n");
  3312   3364   		      goto error;
  3313   3365   		  }
  3314   3366   		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
  3315   3367   		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
  3316   3368   						 no_data);
  3317   3369   		else
  3318         -		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  3319         -					 num_bands, no_data);
         3370  +		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
         3371  +					 sample_type, num_bands, no_data);
  3320   3372   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  3321         -					  num_bands, width, height, tile_sz,
  3322         -					  tile_sz, base_y, base_x);
         3373  +					  pixel_type, num_bands, width, height,
         3374  +					  tile_sz, tile_sz, base_y, base_x);
  3323   3375   		plt2 = rl2_clone_palette (palette);
  3324   3376   		raster =
  3325   3377   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  3326   3378   				       pixel_type, num_bands, bufpix,
  3327   3379   				       bufpix_size, plt2, NULL, 0, NULL);
  3328   3380   		bufpix = NULL;
  3329   3381   		if (raster == NULL)
................................................................................
  3376   3428       return export_geotiff_common (handle, max_threads, dst_path, cvg, 0, 0,
  3377   3429   				  x_res, y_res, minx, miny, maxx, maxy, width,
  3378   3430   				  height, compression, tile_sz, with_worldfile);
  3379   3431   }
  3380   3432   
  3381   3433   RL2_DECLARE int
  3382   3434   rl2_export_section_geotiff_from_dbms (sqlite3 * handle, int max_threads,
  3383         -				      const char *dst_path, rl2CoveragePtr cvg,
         3435  +				      const char *dst_path,
         3436  +				      rl2CoveragePtr cvg,
  3384   3437   				      sqlite3_int64 section_id, double x_res,
  3385   3438   				      double y_res, double minx, double miny,
  3386   3439   				      double maxx, double maxy,
  3387   3440   				      unsigned int width, unsigned int height,
  3388   3441   				      unsigned char compression,
  3389   3442   				      unsigned int tile_sz, int with_worldfile)
  3390   3443   {
................................................................................
  3467   3520   	    }
  3468   3521         }
  3469   3522   
  3470   3523       if (by_section)
  3471   3524         {
  3472   3525   	  /* just a single select Section */
  3473   3526   	  if (rl2_get_section_raw_raster_data
  3474         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  3475         -	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3476         -	       pixel_type) != RL2_OK)
         3527  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         3528  +	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
         3529  +	       &palette, pixel_type) != RL2_OK)
  3477   3530   	      goto error;
  3478   3531         }
  3479   3532       else
  3480   3533         {
  3481   3534   	  /* whole Coverage */
  3482   3535   	  if (rl2_get_raw_raster_data
  3483         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  3484         -	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
         3536  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         3537  +	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3485   3538   	       pixel_type) != RL2_OK)
  3486   3539   	      goto error;
  3487   3540         }
  3488   3541   
  3489   3542   /* computing the sample size */
  3490   3543       switch (sample_type)
  3491   3544         {
................................................................................
  3502   3555   	  pix_sz = 8;
  3503   3556   	  break;
  3504   3557         };
  3505   3558   
  3506   3559       tiff =
  3507   3560   	rl2_create_tiff_worldfile_destination (dst_path, width, height,
  3508   3561   					       sample_type, pixel_type,
  3509         -					       num_bands, palette, compression,
  3510         -					       1, tile_sz, srid, minx, miny,
  3511         -					       maxx, maxy, xx_res, yy_res);
         3562  +					       num_bands, palette,
         3563  +					       compression, 1, tile_sz, srid,
         3564  +					       minx, miny, maxx, maxy, xx_res,
         3565  +					       yy_res);
  3512   3566       if (tiff == NULL)
  3513   3567   	goto error;
  3514   3568       for (base_y = 0; base_y < height; base_y += tile_sz)
  3515   3569         {
  3516   3570   	  for (base_x = 0; base_x < width; base_x += tile_sz)
  3517   3571   	    {
  3518   3572   		/* exporting all tiles from the output buffer */
................................................................................
  3524   3578   			       "rl2tool Export: Insufficient Memory !!!\n");
  3525   3579   		      goto error;
  3526   3580   		  }
  3527   3581   		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
  3528   3582   		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
  3529   3583   						 no_data);
  3530   3584   		else
  3531         -		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  3532         -					 num_bands, no_data);
         3585  +		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
         3586  +					 sample_type, num_bands, no_data);
  3533   3587   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  3534         -					  num_bands, width, height, tile_sz,
  3535         -					  tile_sz, base_y, base_x);
         3588  +					  pixel_type, num_bands, width, height,
         3589  +					  tile_sz, tile_sz, base_y, base_x);
  3536   3590   		plt2 = rl2_clone_palette (palette);
  3537   3591   		raster =
  3538   3592   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  3539   3593   				       pixel_type, num_bands, bufpix,
  3540   3594   				       bufpix_size, plt2, NULL, 0, NULL);
  3541   3595   		bufpix = NULL;
  3542   3596   		if (raster == NULL)
................................................................................
  3580   3634   				     double miny, double maxx, double maxy,
  3581   3635   				     unsigned int width, unsigned int height,
  3582   3636   				     unsigned char compression,
  3583   3637   				     unsigned int tile_sz)
  3584   3638   {
  3585   3639   /* exporting a TIFF+TFW from the DBMS into the file-system */
  3586   3640       return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 0,
  3587         -					0, x_res, y_res, minx, miny, maxx, maxy,
  3588         -					width, height, compression, tile_sz);
         3641  +					0, x_res, y_res, minx, miny, maxx,
         3642  +					maxy, width, height, compression,
         3643  +					tile_sz);
  3589   3644   }
  3590   3645   
  3591   3646   RL2_DECLARE int
  3592         -rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle, int max_threads,
         3647  +rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle,
         3648  +					     int max_threads,
  3593   3649   					     const char *dst_path,
  3594   3650   					     rl2CoveragePtr cvg,
  3595   3651   					     sqlite3_int64 section_id,
  3596   3652   					     double x_res, double y_res,
  3597   3653   					     double minx, double miny,
  3598   3654   					     double maxx, double maxy,
  3599   3655   					     unsigned int width,
................................................................................
  3600   3656   					     unsigned int height,
  3601   3657   					     unsigned char compression,
  3602   3658   					     unsigned int tile_sz)
  3603   3659   {
  3604   3660   /* exporting a TIFF+TFW - single Section */
  3605   3661       return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 1,
  3606   3662   					section_id, x_res, y_res, minx, miny,
  3607         -					maxx, maxy, width, height, compression,
  3608         -					tile_sz);
         3663  +					maxx, maxy, width, height,
         3664  +					compression, tile_sz);
  3609   3665   }
  3610   3666   
  3611   3667   static int
  3612   3668   export_tiff_common (sqlite3 * handle, int max_threads, const char *dst_path,
  3613   3669   		    rl2CoveragePtr cvg, int by_section,
  3614   3670   		    sqlite3_int64 section_id, double x_res, double y_res,
  3615   3671   		    double minx, double miny, double maxx, double maxy,
................................................................................
  3681   3737   	    }
  3682   3738         }
  3683   3739   
  3684   3740       if (by_section)
  3685   3741         {
  3686   3742   	  /* just a single Section */
  3687   3743   	  if (rl2_get_section_raw_raster_data
  3688         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  3689         -	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3690         -	       pixel_type) != RL2_OK)
         3744  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         3745  +	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
         3746  +	       &palette, pixel_type) != RL2_OK)
  3691   3747   	      goto error;
  3692   3748         }
  3693   3749       else
  3694   3750         {
  3695   3751   	  /* whole Coverage */
  3696   3752   	  if (rl2_get_raw_raster_data
  3697         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  3698         -	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
         3753  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         3754  +	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
  3699   3755   	       pixel_type) != RL2_OK)
  3700   3756   	      goto error;
  3701   3757         }
  3702   3758   
  3703   3759   /* computing the sample size */
  3704   3760       switch (sample_type)
  3705   3761         {
................................................................................
  3736   3792   			       "rl2tool Export: Insufficient Memory !!!\n");
  3737   3793   		      goto error;
  3738   3794   		  }
  3739   3795   		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
  3740   3796   		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
  3741   3797   						 no_data);
  3742   3798   		else
  3743         -		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  3744         -					 num_bands, no_data);
         3799  +		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
         3800  +					 sample_type, num_bands, no_data);
  3745   3801   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  3746         -					  num_bands, width, height, tile_sz,
  3747         -					  tile_sz, base_y, base_x);
         3802  +					  pixel_type, num_bands, width, height,
         3803  +					  tile_sz, tile_sz, base_y, base_x);
  3748   3804   		plt2 = rl2_clone_palette (palette);
  3749   3805   		raster =
  3750   3806   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  3751   3807   				       pixel_type, num_bands, bufpix,
  3752   3808   				       bufpix_size, plt2, NULL, 0, NULL);
  3753   3809   		bufpix = NULL;
  3754   3810   		if (raster == NULL)
................................................................................
  3780   3836   	rl2_destroy_palette (palette);
  3781   3837       return RL2_ERROR;
  3782   3838   }
  3783   3839   
  3784   3840   RL2_DECLARE int
  3785   3841   rl2_export_tiff_from_dbms (sqlite3 * handle, int max_threads,
  3786   3842   			   const char *dst_path, rl2CoveragePtr cvg,
  3787         -			   double x_res, double y_res, double minx, double miny,
  3788         -			   double maxx, double maxy, unsigned int width,
  3789         -			   unsigned int height, unsigned char compression,
  3790         -			   unsigned int tile_sz)
         3843  +			   double x_res, double y_res, double minx,
         3844  +			   double miny, double maxx, double maxy,
         3845  +			   unsigned int width, unsigned int height,
         3846  +			   unsigned char compression, unsigned int tile_sz)
  3791   3847   {
  3792   3848   /* exporting a plain TIFF from the DBMS into the file-system */
  3793         -    return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0, x_res,
  3794         -			       y_res, minx, miny, maxx, maxy, width, height,
  3795         -			       compression, tile_sz);
         3849  +    return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0,
         3850  +			       x_res, y_res, minx, miny, maxx, maxy, width,
         3851  +			       height, compression, tile_sz);
  3796   3852   }
  3797   3853   
  3798   3854   RL2_DECLARE int
  3799   3855   rl2_export_section_tiff_from_dbms (sqlite3 * handle, int max_threads,
  3800   3856   				   const char *dst_path, rl2CoveragePtr cvg,
  3801   3857   				   sqlite3_int64 section_id, double x_res,
  3802   3858   				   double y_res, double minx, double miny,
  3803         -				   double maxx, double maxy, unsigned int width,
  3804         -				   unsigned int height,
         3859  +				   double maxx, double maxy,
         3860  +				   unsigned int width, unsigned int height,
  3805   3861   				   unsigned char compression,
  3806   3862   				   unsigned int tile_sz)
  3807   3863   {
  3808   3864   /* exporting a plain TIFF - single Section*/
  3809   3865       return export_tiff_common (handle, max_threads, dst_path, cvg, 1,
  3810         -			       section_id, x_res, y_res, minx, miny, maxx, maxy,
  3811         -			       width, height, compression, tile_sz);
         3866  +			       section_id, x_res, y_res, minx, miny, maxx,
         3867  +			       maxy, width, height, compression, tile_sz);
  3812   3868   }
  3813   3869   
  3814   3870   static int
  3815   3871   export_triple_band_geotiff_common (int by_section, sqlite3 * handle,
  3816   3872   				   const char *dst_path,
  3817         -				   rl2CoveragePtr cvg, sqlite3_int64 section_id,
  3818         -				   double x_res, double y_res, double minx,
  3819         -				   double miny, double maxx, double maxy,
         3873  +				   rl2CoveragePtr cvg,
         3874  +				   sqlite3_int64 section_id, double x_res,
         3875  +				   double y_res, double minx, double miny,
         3876  +				   double maxx, double maxy,
  3820   3877   				   unsigned int width, unsigned int height,
  3821   3878   				   unsigned char red_band,
  3822   3879   				   unsigned char green_band,
  3823   3880   				   unsigned char blue_band,
  3824   3881   				   unsigned char compression,
  3825   3882   				   unsigned int tile_sz, int with_worldfile)
  3826   3883   {
................................................................................
  3892   3949   	      goto error;
  3893   3950         }
  3894   3951   
  3895   3952       tiff =
  3896   3953   	rl2_create_geotiff_destination (dst_path, handle, width, height,
  3897   3954   					sample_type, RL2_PIXEL_RGB, 3,
  3898   3955   					NULL, compression, 1, tile_sz, srid,
  3899         -					minx, miny, maxx, maxy, xx_res, yy_res,
  3900         -					with_worldfile);
         3956  +					minx, miny, maxx, maxy, xx_res,
         3957  +					yy_res, with_worldfile);
  3901   3958       if (tiff == NULL)
  3902   3959   	goto error;
  3903   3960       for (base_y = 0; base_y < height; base_y += tile_sz)
  3904   3961         {
  3905   3962   	  for (base_x = 0; base_x < width; base_x += tile_sz)
  3906   3963   	    {
  3907   3964   		/* exporting all tiles from the output buffer */
................................................................................
  3914   3971   		      fprintf (stderr,
  3915   3972   			       "rl2tool Export: Insufficient Memory !!!\n");
  3916   3973   		      goto error;
  3917   3974   		  }
  3918   3975   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  3919   3976   				     3, no_data);
  3920   3977   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  3921         -					  3, width, height, tile_sz,
         3978  +					  pixel_type, 3, width, height, tile_sz,
  3922   3979   					  tile_sz, base_y, base_x);
  3923   3980   		raster =
  3924   3981   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  3925         -				       RL2_PIXEL_RGB, 3, bufpix,
  3926         -				       bufpix_size, NULL, NULL, 0, NULL);
         3982  +				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
         3983  +				       NULL, NULL, 0, NULL);
  3927   3984   		bufpix = NULL;
  3928   3985   		if (raster == NULL)
  3929   3986   		    goto error;
  3930   3987   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  3931   3988   		    RL2_OK)
  3932   3989   		    goto error;
  3933   3990   		rl2_destroy_raster (raster);
................................................................................
  4090   4147       else
  4091   4148   	out_pixel = RL2_PIXEL_GRAYSCALE;
  4092   4149   
  4093   4150       tiff =
  4094   4151   	rl2_create_geotiff_destination (dst_path, handle, width, height,
  4095   4152   					sample_type, out_pixel, 1,
  4096   4153   					NULL, compression, 1, tile_sz, srid,
  4097         -					minx, miny, maxx, maxy, xx_res, yy_res,
  4098         -					with_worldfile);
         4154  +					minx, miny, maxx, maxy, xx_res,
         4155  +					yy_res, with_worldfile);
  4099   4156       if (tiff == NULL)
  4100   4157   	goto error;
  4101   4158       for (base_y = 0; base_y < height; base_y += tile_sz)
  4102   4159         {
  4103   4160   	  for (base_x = 0; base_x < width; base_x += tile_sz)
  4104   4161   	    {
  4105   4162   		/* exporting all tiles from the output buffer */
................................................................................
  4112   4169   		      fprintf (stderr,
  4113   4170   			       "rl2tool Export: Insufficient Memory !!!\n");
  4114   4171   		      goto error;
  4115   4172   		  }
  4116   4173   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  4117   4174   				     1, no_data);
  4118   4175   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  4119         -					  1, width, height, tile_sz,
         4176  +					  pixel_type, 1, width, height, tile_sz,
  4120   4177   					  tile_sz, base_y, base_x);
  4121   4178   		raster =
  4122         -		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  4123         -				       out_pixel, 1, bufpix,
  4124         -				       bufpix_size, NULL, NULL, 0, NULL);
         4179  +		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,
         4180  +				       1, bufpix, bufpix_size, NULL, NULL, 0,
         4181  +				       NULL);
  4125   4182   		bufpix = NULL;
  4126   4183   		if (raster == NULL)
  4127   4184   		    goto error;
  4128   4185   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  4129   4186   		    RL2_OK)
  4130   4187   		    goto error;
  4131   4188   		rl2_destroy_raster (raster);
................................................................................
  4170   4227   					unsigned int height,
  4171   4228   					unsigned char mono_band,
  4172   4229   					unsigned char compression,
  4173   4230   					unsigned int tile_sz,
  4174   4231   					int with_worldfile)
  4175   4232   {
  4176   4233   /* exporting a Mono-Band GeoTIFF from the DBMS into the file-system */
  4177         -    return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0, x_res,
  4178         -					    y_res, minx, miny, maxx, maxy,
  4179         -					    width, height, mono_band,
         4234  +    return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0,
         4235  +					    x_res, y_res, minx, miny, maxx,
         4236  +					    maxy, width, height, mono_band,
  4180   4237   					    compression, tile_sz,
  4181   4238   					    with_worldfile);
  4182   4239   }
  4183   4240   
  4184   4241   RL2_DECLARE int
  4185   4242   rl2_export_section_mono_band_geotiff_from_dbms (sqlite3 * handle,
  4186   4243   						const char *dst_path,
................................................................................
  4206   4263   
  4207   4264   static int
  4208   4265   export_triple_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
  4209   4266   					  const char *dst_path,
  4210   4267   					  rl2CoveragePtr cvg,
  4211   4268   					  sqlite3_int64 section_id,
  4212   4269   					  double x_res, double y_res,
  4213         -					  double minx, double miny, double maxx,
  4214         -					  double maxy, unsigned int width,
         4270  +					  double minx, double miny,
         4271  +					  double maxx, double maxy,
         4272  +					  unsigned int width,
  4215   4273   					  unsigned int height,
  4216   4274   					  unsigned char red_band,
  4217   4275   					  unsigned char green_band,
  4218   4276   					  unsigned char blue_band,
  4219   4277   					  unsigned char compression,
  4220   4278   					  unsigned int tile_sz)
  4221   4279   {
................................................................................
  4286   4344   	       no_data) != RL2_OK)
  4287   4345   	      goto error;
  4288   4346         }
  4289   4347   
  4290   4348       tiff =
  4291   4349   	rl2_create_tiff_worldfile_destination (dst_path, width, height,
  4292   4350   					       sample_type, RL2_PIXEL_RGB,
  4293         -					       3, NULL, compression, 1, tile_sz,
  4294         -					       srid, minx, miny, maxx, maxy,
  4295         -					       xx_res, yy_res);
         4351  +					       3, NULL, compression, 1,
         4352  +					       tile_sz, srid, minx, miny,
         4353  +					       maxx, maxy, xx_res, yy_res);
  4296   4354       if (tiff == NULL)
  4297   4355   	goto error;
  4298   4356       for (base_y = 0; base_y < height; base_y += tile_sz)
  4299   4357         {
  4300   4358   	  for (base_x = 0; base_x < width; base_x += tile_sz)
  4301   4359   	    {
  4302   4360   		/* exporting all tiles from the output buffer */
................................................................................
  4309   4367   		      fprintf (stderr,
  4310   4368   			       "rl2tool Export: Insufficient Memory !!!\n");
  4311   4369   		      goto error;
  4312   4370   		  }
  4313   4371   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  4314   4372   				     3, no_data);
  4315   4373   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  4316         -					  3, width, height, tile_sz,
         4374  +					  pixel_type, 3, width, height, tile_sz,
  4317   4375   					  tile_sz, base_y, base_x);
  4318   4376   		raster =
  4319   4377   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  4320         -				       RL2_PIXEL_RGB, 3, bufpix,
  4321         -				       bufpix_size, NULL, NULL, 0, NULL);
         4378  +				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
         4379  +				       NULL, NULL, 0, NULL);
  4322   4380   		bufpix = NULL;
  4323   4381   		if (raster == NULL)
  4324   4382   		    goto error;
  4325   4383   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  4326   4384   		    RL2_OK)
  4327   4385   		    goto error;
  4328   4386   		rl2_destroy_raster (raster);
................................................................................
  4388   4446   							 double y_res,
  4389   4447   							 double minx,
  4390   4448   							 double miny,
  4391   4449   							 double maxx,
  4392   4450   							 double maxy,
  4393   4451   							 unsigned int width,
  4394   4452   							 unsigned int height,
  4395         -							 unsigned char red_band,
         4453  +							 unsigned char
         4454  +							 red_band,
  4396   4455   							 unsigned char
  4397   4456   							 green_band,
  4398   4457   							 unsigned char
  4399   4458   							 blue_band,
  4400   4459   							 unsigned char
  4401   4460   							 compression,
  4402   4461   							 unsigned int tile_sz)
................................................................................
  4410   4469   						     compression, tile_sz);
  4411   4470   }
  4412   4471   
  4413   4472   static int
  4414   4473   export_mono_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
  4415   4474   					const char *dst_path,
  4416   4475   					rl2CoveragePtr cvg,
  4417         -					sqlite3_int64 section_id, double x_res,
  4418         -					double y_res, double minx, double miny,
  4419         -					double maxx, double maxy,
  4420         -					unsigned int width, unsigned int height,
         4476  +					sqlite3_int64 section_id,
         4477  +					double x_res, double y_res,
         4478  +					double minx, double miny, double maxx,
         4479  +					double maxy, unsigned int width,
         4480  +					unsigned int height,
  4421   4481   					unsigned char mono_band,
  4422   4482   					unsigned char compression,
  4423   4483   					unsigned int tile_sz)
  4424   4484   {
  4425   4485   /* exporting a Mono-Band TIFF+TFW - common implementation */
  4426   4486       rl2RasterPtr raster = NULL;
  4427   4487       rl2PixelPtr no_data_multi = NULL;
................................................................................
  4488   4548   	out_pixel = RL2_PIXEL_DATAGRID;
  4489   4549       else
  4490   4550   	out_pixel = RL2_PIXEL_GRAYSCALE;
  4491   4551   
  4492   4552       tiff =
  4493   4553   	rl2_create_tiff_worldfile_destination (dst_path, width, height,
  4494   4554   					       sample_type, out_pixel,
  4495         -					       1, NULL, compression, 1, tile_sz,
  4496         -					       srid, minx, miny, maxx, maxy,
  4497         -					       xx_res, yy_res);
         4555  +					       1, NULL, compression, 1,
         4556  +					       tile_sz, srid, minx, miny,
         4557  +					       maxx, maxy, xx_res, yy_res);
  4498   4558       if (tiff == NULL)
  4499   4559   	goto error;
  4500   4560       for (base_y = 0; base_y < height; base_y += tile_sz)
  4501   4561         {
  4502   4562   	  for (base_x = 0; base_x < width; base_x += tile_sz)
  4503   4563   	    {
  4504   4564   		/* exporting all tiles from the output buffer */
................................................................................
  4511   4571   		      fprintf (stderr,
  4512   4572   			       "rl2tool Export: Insufficient Memory !!!\n");
  4513   4573   		      goto error;
  4514   4574   		  }
  4515   4575   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  4516   4576   				     1, no_data);
  4517   4577   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  4518         -					  1, width, height, tile_sz,
         4578  +					  pixel_type, 1, width, height, tile_sz,
  4519   4579   					  tile_sz, base_y, base_x);
  4520   4580   		raster =
  4521         -		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  4522         -				       out_pixel, 1, bufpix,
  4523         -				       bufpix_size, NULL, NULL, 0, NULL);
         4581  +		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,
         4582  +				       1, bufpix, bufpix_size, NULL, NULL, 0,
         4583  +				       NULL);
  4524   4584   		bufpix = NULL;
  4525   4585   		if (raster == NULL)
  4526   4586   		    goto error;
  4527   4587   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  4528   4588   		    RL2_OK)
  4529   4589   		    goto error;
  4530   4590   		rl2_destroy_raster (raster);
................................................................................
  4566   4626   					       unsigned int width,
  4567   4627   					       unsigned int height,
  4568   4628   					       unsigned char mono_band,
  4569   4629   					       unsigned char compression,
  4570   4630   					       unsigned int tile_sz)
  4571   4631   {
  4572   4632   /* exporting a Mono-Band TIFF+TFW from the DBMS into the file-system */
  4573         -    return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg, 0,
  4574         -						   x_res, y_res, minx, miny,
  4575         -						   maxx, maxy, width, height,
  4576         -						   mono_band, compression,
  4577         -						   tile_sz);
         4633  +    return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg,
         4634  +						   0, x_res, y_res, minx,
         4635  +						   miny, maxx, maxy, width,
         4636  +						   height, mono_band,
         4637  +						   compression, tile_sz);
  4578   4638   }
  4579   4639   
  4580   4640   RL2_DECLARE int
  4581   4641   rl2_export_section_mono_band_tiff_worldfile_from_dbms (sqlite3 * handle,
  4582   4642   						       const char *dst_path,
  4583   4643   						       rl2CoveragePtr cvg,
  4584         -						       sqlite3_int64 section_id,
         4644  +						       sqlite3_int64
         4645  +						       section_id,
  4585   4646   						       double x_res,
  4586   4647   						       double y_res,
  4587         -						       double minx, double miny,
  4588         -						       double maxx, double maxy,
         4648  +						       double minx,
         4649  +						       double miny,
         4650  +						       double maxx,
         4651  +						       double maxy,
  4589   4652   						       unsigned int width,
  4590   4653   						       unsigned int height,
  4591         -						       unsigned char mono_band,
         4654  +						       unsigned char
         4655  +						       mono_band,
  4592   4656   						       unsigned char
  4593   4657   						       compression,
  4594   4658   						       unsigned int tile_sz)
  4595   4659   {
  4596   4660   /* exporting a Mono-Band TIFF+TFW - Section */
  4597   4661       return export_mono_band_tiff_worldfile_common (1, handle, dst_path, cvg,
  4598   4662   						   section_id, x_res, y_res,
................................................................................
  4700   4764   		      fprintf (stderr,
  4701   4765   			       "rl2tool Export: Insufficient Memory !!!\n");
  4702   4766   		      goto error;
  4703   4767   		  }
  4704   4768   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  4705   4769   				     3, no_data);
  4706   4770   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  4707         -					  3, width, height, tile_sz,
         4771  +					  pixel_type, 3, width, height, tile_sz,
  4708   4772   					  tile_sz, base_y, base_x);
  4709   4773   		raster =
  4710   4774   		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  4711         -				       RL2_PIXEL_RGB, 3, bufpix,
  4712         -				       bufpix_size, NULL, NULL, 0, NULL);
         4775  +				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
         4776  +				       NULL, NULL, 0, NULL);
  4713   4777   		bufpix = NULL;
  4714   4778   		if (raster == NULL)
  4715   4779   		    goto error;
  4716   4780   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  4717   4781   		    RL2_OK)
  4718   4782   		    goto error;
  4719   4783   		rl2_destroy_raster (raster);
................................................................................
  4752   4816   				       unsigned char green_band,
  4753   4817   				       unsigned char blue_band,
  4754   4818   				       unsigned char compression,
  4755   4819   				       unsigned int tile_sz)
  4756   4820   {
  4757   4821   /* exporting a plain Band-Composed TIFF from the DBMS into the file-system */
  4758   4822       return export_triple_band_tiff_common (0, handle, dst_path, cvg, 0, x_res,
  4759         -					   y_res, minx, miny, maxx, maxy, width,
  4760         -					   height, red_band, green_band,
  4761         -					   blue_band, compression, tile_sz);
         4823  +					   y_res, minx, miny, maxx, maxy,
         4824  +					   width, height, red_band,
         4825  +					   green_band, blue_band, compression,
         4826  +					   tile_sz);
  4762   4827   }
  4763   4828   
  4764   4829   RL2_DECLARE int
  4765   4830   rl2_export_section_triple_band_tiff_from_dbms (sqlite3 * handle,
  4766   4831   					       const char *dst_path,
  4767   4832   					       rl2CoveragePtr cvg,
  4768   4833   					       sqlite3_int64 section_id,
................................................................................
  4774   4839   					       unsigned char red_band,
  4775   4840   					       unsigned char green_band,
  4776   4841   					       unsigned char blue_band,
  4777   4842   					       unsigned char compression,
  4778   4843   					       unsigned int tile_sz)
  4779   4844   {
  4780   4845   /* exporting a plain Band-Composed TIFF - Section */
  4781         -    return export_triple_band_tiff_common (1, handle, dst_path, cvg, section_id,
  4782         -					   x_res, y_res, minx, miny, maxx, maxy,
  4783         -					   width, height, red_band, green_band,
  4784         -					   blue_band, compression, tile_sz);
         4846  +    return export_triple_band_tiff_common (1, handle, dst_path, cvg,
         4847  +					   section_id, x_res, y_res, minx,
         4848  +					   miny, maxx, maxy, width, height,
         4849  +					   red_band, green_band, blue_band,
         4850  +					   compression, tile_sz);
  4785   4851   }
  4786   4852   
  4787   4853   static int
  4788   4854   export_mono_band_tiff_common (int by_section, sqlite3 * handle,
  4789   4855   			      const char *dst_path, rl2CoveragePtr cvg,
  4790   4856   			      sqlite3_int64 section_id, double x_res,
  4791   4857   			      double y_res, double minx, double miny,
................................................................................
  4880   4946   		      fprintf (stderr,
  4881   4947   			       "rl2tool Export: Insufficient Memory !!!\n");
  4882   4948   		      goto error;
  4883   4949   		  }
  4884   4950   		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
  4885   4951   				     1, no_data);
  4886   4952   		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
  4887         -					  1, width, height, tile_sz,
         4953  +					  pixel_type, 1, width, height, tile_sz,
  4888   4954   					  tile_sz, base_y, base_x);
  4889   4955   		raster =
  4890         -		    rl2_create_raster (tile_sz, tile_sz, sample_type,
  4891         -				       out_pixel, 1, bufpix,
  4892         -				       bufpix_size, NULL, NULL, 0, NULL);
         4956  +		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,
         4957  +				       1, bufpix, bufpix_size, NULL, NULL, 0,
         4958  +				       NULL);
  4893   4959   		bufpix = NULL;
  4894   4960   		if (raster == NULL)
  4895   4961   		    goto error;
  4896   4962   		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
  4897   4963   		    RL2_OK)
  4898   4964   		    goto error;
  4899   4965   		rl2_destroy_raster (raster);
................................................................................
  4952   5018   					     unsigned char mono_band,
  4953   5019   					     unsigned char compression,
  4954   5020   					     unsigned int tile_sz)
  4955   5021   {
  4956   5022   /* exporting a plain Mono-Band TIFF from the DBMS - Section */
  4957   5023       return export_mono_band_tiff_common (1, handle, dst_path, cvg, section_id,
  4958   5024   					 x_res, y_res, minx, miny, maxx, maxy,
  4959         -					 width, height, mono_band, compression,
  4960         -					 tile_sz);
         5025  +					 width, height, mono_band,
         5026  +					 compression, tile_sz);
  4961   5027   }
  4962   5028   
  4963   5029   static int
  4964   5030   export_ascii_grid_common (int by_section, sqlite3 * handle, int max_threads,
  4965   5031   			  const char *dst_path, rl2CoveragePtr cvg,
  4966   5032   			  sqlite3_int64 section_id, double res, double minx,
  4967   5033   			  double miny, double maxx, double maxy,
................................................................................
  5061   5127   	    }
  5062   5128         }
  5063   5129   
  5064   5130       if (by_section)
  5065   5131         {
  5066   5132   	  /* single Section */
  5067   5133   	  if (rl2_get_section_raw_raster_data
  5068         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  5069         -	       maxx, maxy, res, res, &pixels, &pixels_size, &palette,
         5134  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         5135  +	       miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette,
  5070   5136   	       RL2_PIXEL_DATAGRID) != RL2_OK)
  5071   5137   	      goto error;
  5072   5138         }
  5073   5139       else
  5074   5140         {
  5075   5141   	  /* whole Coverage */
  5076   5142   	  if (rl2_get_raw_raster_data
  5077         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  5078         -	       res, res, &pixels, &pixels_size, &palette,
         5143  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         5144  +	       maxy, res, res, &pixels, &pixels_size, &palette,
  5079   5145   	       RL2_PIXEL_DATAGRID) != RL2_OK)
  5080   5146   	      goto error;
  5081   5147         }
  5082   5148   
  5083   5149       ascii =
  5084   5150   	rl2_create_ascii_grid_destination (dst_path, width, height,
  5085   5151   					   xx_res, minx, miny, is_centered,
................................................................................
  5120   5186   				 double res, double minx, double miny,
  5121   5187   				 double maxx, double maxy, unsigned int width,
  5122   5188   				 unsigned int height, int is_centered,
  5123   5189   				 int decimal_digits)
  5124   5190   {
  5125   5191   /* exporting an ASCII Grid from the DBMS into the file-system */
  5126   5192       return export_ascii_grid_common (0, handle, max_threads, dst_path, cvg, 0,
  5127         -				     res, minx, miny, maxx, maxy, width, height,
  5128         -				     is_centered, decimal_digits);
         5193  +				     res, minx, miny, maxx, maxy, width,
         5194  +				     height, is_centered, decimal_digits);
  5129   5195   }
  5130   5196   
  5131   5197   RL2_DECLARE int
  5132   5198   rl2_export_section_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
  5133   5199   					 const char *dst_path,
  5134   5200   					 rl2CoveragePtr cvg,
  5135   5201   					 sqlite3_int64 section_id, double res,
  5136         -					 double minx, double miny, double maxx,
  5137         -					 double maxy, unsigned int width,
         5202  +					 double minx, double miny,
         5203  +					 double maxx, double maxy,
         5204  +					 unsigned int width,
  5138   5205   					 unsigned int height, int is_centered,
  5139   5206   					 int decimal_digits)
  5140   5207   {
  5141   5208   /* exporting an ASCII Grid - Section */
  5142   5209       return export_ascii_grid_common (1, handle, max_threads, dst_path, cvg,
  5143   5210   				     section_id, res, minx, miny, maxx, maxy,
  5144   5211   				     width, height, is_centered,
................................................................................
  5184   5251   	  if (match == no_data->nBands)
  5185   5252   	      return 1;
  5186   5253         }
  5187   5254       return 0;
  5188   5255   }
  5189   5256   
  5190   5257   static float
  5191         -compute_ndvi (void *pixels, unsigned char sample_type, unsigned char num_bands,
  5192         -	      unsigned short width, unsigned char red_band,
  5193         -	      unsigned char nir_band, unsigned short row, unsigned short col,
         5258  +compute_ndvi (void *pixels, unsigned char sample_type,
         5259  +	      unsigned char num_bands, unsigned short width,
         5260  +	      unsigned char red_band, unsigned char nir_band,
         5261  +	      unsigned short row, unsigned short col,
  5194   5262   	      rl2PrivPixelPtr in_no_data, float out_no_data)
  5195   5263   {
  5196   5264   /* computing a Normalized Difference Vegetaion Index -NDVI */
  5197   5265       float red;
  5198   5266       float nir;
  5199   5267       unsigned char *p8;
  5200   5268       unsigned short *p16;
................................................................................
  5223   5291   
  5224   5292   static int
  5225   5293   export_ndvi_ascii_grid_common (int by_section, sqlite3 * handle,
  5226   5294   			       int max_threads, const char *dst_path,
  5227   5295   			       rl2CoveragePtr cvg, sqlite3_int64 section_id,
  5228   5296   			       double res, double minx, double miny,
  5229   5297   			       double maxx, double maxy, unsigned int width,
  5230         -			       unsigned int height, int red_band, int nir_band,
  5231         -			       int is_centered, int decimal_digits)
         5298  +			       unsigned int height, int red_band,
         5299  +			       int nir_band, int is_centered,
         5300  +			       int decimal_digits)
  5232   5301   {
  5233   5302   /* exporting an NDVI ASCII Grid common implementation */
  5234   5303       rl2PalettePtr palette = NULL;
  5235   5304       rl2PixelPtr in_no_data;
  5236   5305       rl2AsciiGridDestinationPtr ascii = NULL;
  5237   5306       unsigned char level;
  5238   5307       unsigned char scale;
................................................................................
  5277   5346       if (red_band == nir_band)
  5278   5347   	goto error;
  5279   5348   
  5280   5349       if (by_section)
  5281   5350         {
  5282   5351   	  /* single Section */
  5283   5352   	  if (rl2_get_section_raw_raster_data
  5284         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  5285         -	       maxx, maxy, res, res, &pixels, &pixels_size, &palette,
         5353  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         5354  +	       miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette,
  5286   5355   	       RL2_PIXEL_MULTIBAND) != RL2_OK)
  5287   5356   	      goto error;
  5288   5357         }
  5289   5358       else
  5290   5359         {
  5291   5360   	  /* whole Coverage */
  5292   5361   	  if (rl2_get_raw_raster_data
  5293         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  5294         -	       res, res, &pixels, &pixels_size, &palette,
         5362  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         5363  +	       maxy, res, res, &pixels, &pixels_size, &palette,
  5295   5364   	       RL2_PIXEL_MULTIBAND) != RL2_OK)
  5296   5365   	      goto error;
  5297   5366         }
  5298   5367   
  5299   5368   /* creating the output NDVI raster */
  5300   5369       out_pixels_size = width * height * sizeof (float);
  5301   5370       out_pixels = malloc (out_pixels_size);
................................................................................
  5303   5372   	goto error;
  5304   5373       po = (float *) out_pixels;
  5305   5374       for (row = 0; row < height; row++)
  5306   5375         {
  5307   5376   	  /* computing NDVI */
  5308   5377   	  for (col = 0; col < width; col++)
  5309   5378   	      *po++ =
  5310         -		  compute_ndvi (pixels, sample_type, num_bands, width, red_band,
  5311         -				nir_band, row, col,
         5379  +		  compute_ndvi (pixels, sample_type, num_bands, width,
         5380  +				red_band, nir_band, row, col,
  5312   5381   				(rl2PrivPixelPtr) in_no_data, out_no_data);
  5313   5382         }
  5314   5383       free (pixels);
  5315   5384       pixels = NULL;
  5316   5385   
  5317   5386       ascii =
  5318   5387   	rl2_create_ascii_grid_destination (dst_path, width, height,
................................................................................
  5347   5416       if (palette != NULL)
  5348   5417   	rl2_destroy_palette (palette);
  5349   5418       return RL2_ERROR;
  5350   5419   }
  5351   5420   
  5352   5421   RL2_DECLARE int
  5353   5422   rl2_export_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
  5354         -				      const char *dst_path, rl2CoveragePtr cvg,
  5355         -				      double res, double minx, double miny,
  5356         -				      double maxx, double maxy,
  5357         -				      unsigned int width, unsigned int height,
  5358         -				      int red_band, int nir_band,
  5359         -				      int is_centered, int decimal_digits)
         5423  +				      const char *dst_path,
         5424  +				      rl2CoveragePtr cvg, double res,
         5425  +				      double minx, double miny, double maxx,
         5426  +				      double maxy, unsigned int width,
         5427  +				      unsigned int height, int red_band,
         5428  +				      int nir_band, int is_centered,
         5429  +				      int decimal_digits)
  5360   5430   {
  5361   5431   /* exporting an ASCII Grid from the DBMS into the file-system */
  5362         -    return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path, cvg,
  5363         -					  0, res, minx, miny, maxx, maxy, width,
  5364         -					  height, red_band, nir_band,
         5432  +    return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path,
         5433  +					  cvg, 0, res, minx, miny, maxx, maxy,
         5434  +					  width, height, red_band, nir_band,
  5365   5435   					  is_centered, decimal_digits);
  5366   5436   }
  5367   5437   
  5368   5438   RL2_DECLARE int
  5369         -rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
         5439  +rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle,
         5440  +					      int max_threads,
  5370   5441   					      const char *dst_path,
  5371   5442   					      rl2CoveragePtr cvg,
  5372   5443   					      sqlite3_int64 section_id,
  5373   5444   					      double res, double minx,
  5374   5445   					      double miny, double maxx,
  5375   5446   					      double maxy, unsigned int width,
  5376         -					      unsigned int height, int red_band,
  5377         -					      int nir_band, int is_centered,
         5447  +					      unsigned int height,
         5448  +					      int red_band, int nir_band,
         5449  +					      int is_centered,
  5378   5450   					      int decimal_digits)
  5379   5451   {
  5380   5452   /* exporting an ASCII Grid - Section */
  5381         -    return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path, cvg,
  5382         -					  section_id, res, minx, miny, maxx,
  5383         -					  maxy, width, height, red_band,
         5453  +    return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path,
         5454  +					  cvg, section_id, res, minx, miny,
         5455  +					  maxx, maxy, width, height, red_band,
  5384   5456   					  nir_band, is_centered,
  5385   5457   					  decimal_digits);
  5386   5458   }
  5387   5459   
  5388   5460   static int
  5389   5461   export_jpeg_common (int by_section, sqlite3 * handle, int max_threads,
  5390   5462   		    const char *dst_path, rl2CoveragePtr cvg,
................................................................................
  5427   5499       else
  5428   5500   	goto error;
  5429   5501   
  5430   5502       if (by_section)
  5431   5503         {
  5432   5504   	  /* single Section */
  5433   5505   	  if (rl2_get_section_raw_raster_data
  5434         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  5435         -	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
         5506  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         5507  +	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
  5436   5508   	       pixel_type) != RL2_OK)
  5437   5509   	      goto error;
  5438   5510         }
  5439   5511       else
  5440   5512         {
  5441   5513   	  /* whole Coverage */
  5442   5514   	  if (rl2_get_raw_raster_data
  5443         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  5444         -	       xx_res, yy_res, &outbuf, &outbuf_size, NULL,
         5515  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         5516  +	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
  5445   5517   	       pixel_type) != RL2_OK)
  5446   5518   	      goto error;
  5447   5519         }
  5448   5520   
  5449   5521       raster =
  5450   5522   	rl2_create_raster (width, height, sample_type, pixel_type, num_bands,
  5451   5523   			   outbuf, outbuf_size, NULL, NULL, 0, NULL);
................................................................................
  5478   5550   	free (outbuf);
  5479   5551       return RL2_ERROR;
  5480   5552   }
  5481   5553   
  5482   5554   RL2_DECLARE int
  5483   5555   rl2_export_jpeg_from_dbms (sqlite3 * handle, int max_threads,
  5484   5556   			   const char *dst_path, rl2CoveragePtr cvg,
  5485         -			   double x_res, double y_res, double minx, double miny,
  5486         -			   double maxx, double maxy, unsigned int width,
  5487         -			   unsigned int height, int quality, int with_worldfile)
         5557  +			   double x_res, double y_res, double minx,
         5558  +			   double miny, double maxx, double maxy,
         5559  +			   unsigned int width, unsigned int height,
         5560  +			   int quality, int with_worldfile)
  5488   5561   {
  5489   5562   /* exporting a JPEG (with possible JGW) from the DBMS into the file-system */
  5490         -    return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0, x_res,
  5491         -			       y_res, minx, miny, maxx, maxy, width, height,
  5492         -			       quality, with_worldfile);
         5563  +    return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0,
         5564  +			       x_res, y_res, minx, miny, maxx, maxy, width,
         5565  +			       height, quality, with_worldfile);
  5493   5566   }
  5494   5567   
  5495   5568   RL2_DECLARE int
  5496   5569   rl2_export_section_jpeg_from_dbms (sqlite3 * handle, int max_threads,
  5497   5570   				   const char *dst_path, rl2CoveragePtr cvg,
  5498   5571   				   sqlite3_int64 section_id, double x_res,
  5499   5572   				   double y_res, double minx, double miny,
  5500         -				   double maxx, double maxy, unsigned int width,
  5501         -				   unsigned int height, int quality,
  5502         -				   int with_worldfile)
         5573  +				   double maxx, double maxy,
         5574  +				   unsigned int width, unsigned int height,
         5575  +				   int quality, int with_worldfile)
  5503   5576   {
  5504   5577   /* exporting a JPEG (with possible JGW) - Section */
  5505   5578       return export_jpeg_common (1, handle, max_threads, dst_path, cvg,
  5506         -			       section_id, x_res, y_res, minx, miny, maxx, maxy,
  5507         -			       width, height, quality, with_worldfile);
         5579  +			       section_id, x_res, y_res, minx, miny, maxx,
         5580  +			       maxy, width, height, quality, with_worldfile);
  5508   5581   }
  5509   5582   
  5510   5583   static int
  5511   5584   export_raw_pixels_common (int by_section, sqlite3 * handle, int max_threads,
  5512   5585   			  rl2CoveragePtr cvg, sqlite3_int64 section_id,
  5513         -			  double x_res, double y_res, double minx, double miny,
  5514         -			  double maxx, double maxy, unsigned int width,
  5515         -			  unsigned int height, int big_endian,
  5516         -			  unsigned char **blob, int *blob_size)
         5586  +			  double x_res, double y_res, double minx,
         5587  +			  double miny, double maxx, double maxy,
         5588  +			  unsigned int width, unsigned int height,
         5589  +			  int big_endian, unsigned char **blob, int *blob_size)
  5517   5590   {
  5518   5591   /* common implementation for Export RAW pixels */
  5519   5592       unsigned char level;
  5520   5593       unsigned char scale;
  5521   5594       double xx_res = x_res;
  5522   5595       double yy_res = y_res;
  5523   5596       unsigned char sample_type;
................................................................................
  5540   5613   	RL2_OK)
  5541   5614   	goto error;
  5542   5615   
  5543   5616       if (by_section)
  5544   5617         {
  5545   5618   	  /* single Section */
  5546   5619   	  if (rl2_get_section_raw_raster_data
  5547         -	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
  5548         -	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
         5620  +	      (handle, max_threads, cvg, section_id, width, height, minx,
         5621  +	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
  5549   5622   	       pixel_type) != RL2_OK)
  5550   5623   	      goto error;
  5551   5624         }
  5552   5625       else
  5553   5626         {
  5554   5627   	  /* whole Coverage */
  5555   5628   	  if (rl2_get_raw_raster_data
  5556         -	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
  5557         -	       xx_res, yy_res, &outbuf, &outbuf_size, NULL,
         5629  +	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
         5630  +	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
  5558   5631   	       pixel_type) != RL2_OK)
  5559   5632   	      goto error;
  5560   5633         }
  5561   5634       bufpix =
  5562   5635   	rl2_copy_endian_raw_pixels (outbuf, outbuf_size, width, height,
  5563   5636   				    sample_type, num_bands, big_endian);
  5564   5637       if (bufpix == NULL)
................................................................................
  5580   5653   				 double y_res, double minx, double miny,
  5581   5654   				 double maxx, double maxy,
  5582   5655   				 unsigned int width,
  5583   5656   				 unsigned int height, int big_endian,
  5584   5657   				 unsigned char **blob, int *blob_size)
  5585   5658   {
  5586   5659   /* exporting RAW pixel buffer and Transparency Mask from the DBMS */
  5587         -    return export_raw_pixels_common (0, handle, max_threads, coverage, 0, x_res,
  5588         -				     y_res, minx, miny, maxx, maxy, width,
  5589         -				     height, big_endian, blob, blob_size);
         5660  +    return export_raw_pixels_common (0, handle, max_threads, coverage, 0,
         5661  +				     x_res, y_res, minx, miny, maxx, maxy,
         5662  +				     width, height, big_endian, blob,
         5663  +				     blob_size);
  5590   5664   }
  5591   5665   
  5592   5666   RL2_DECLARE int
  5593   5667   rl2_export_section_raw_pixels_from_dbms (sqlite3 * handle, int max_threads,
  5594   5668   					 rl2CoveragePtr coverage,
  5595   5669   					 sqlite3_int64 section_id,
  5596   5670   					 double x_res, double y_res,
................................................................................
  5599   5673   					 unsigned int width,
  5600   5674   					 unsigned int height,
  5601   5675   					 int big_endian,
  5602   5676   					 unsigned char **blob, int *blob_size)
  5603   5677   {
  5604   5678   /* exporting RAW pixel buffer and Transparency Mask - Section */
  5605   5679       return export_raw_pixels_common (1, handle, max_threads, coverage,
  5606         -				     section_id, x_res, y_res, minx, miny, maxx,
  5607         -				     maxy, width, height, big_endian, blob,
  5608         -				     blob_size);
         5680  +				     section_id, x_res, y_res, minx, miny,
         5681  +				     maxx, maxy, width, height, big_endian,
         5682  +				     blob, blob_size);
  5609   5683   }
  5610   5684   
  5611   5685   RL2_DECLARE int
  5612   5686   rl2_load_raw_raster_into_dbms (sqlite3 * handle, int max_threads,
  5613   5687   			       rl2CoveragePtr cvg, const char *section,
  5614   5688   			       rl2RasterPtr rst, int pyramidize)
  5615   5689   {
................................................................................
  6005   6079       return RL2_OK;
  6006   6080   
  6007   6081     error:
  6008   6082       if (aux != NULL)
  6009   6083   	destroyAuxImporter (aux);
  6010   6084       if (thread_slots != NULL)
  6011   6085   	free (thread_slots);
         6086  +    if (stmt_upd_sect != NULL)
         6087  +	sqlite3_finalize (stmt_upd_sect);
         6088  +    if (stmt_sect != NULL)
         6089  +	sqlite3_finalize (stmt_sect);
         6090  +    if (stmt_levl != NULL)
         6091  +	sqlite3_finalize (stmt_levl);
         6092  +    if (stmt_tils != NULL)
         6093  +	sqlite3_finalize (stmt_tils);
         6094  +    if (stmt_data != NULL)
         6095  +	sqlite3_finalize (stmt_data);
         6096  +    return RL2_ERROR;
         6097  +}
         6098  +
         6099  +RL2_DECLARE int
         6100  +rl2_load_raw_tiles_into_dbms (sqlite3 * handle,
         6101  +			      rl2CoveragePtr cvg, const char *section,
         6102  +			      unsigned int sctn_width,
         6103  +			      unsigned int sctn_height,
         6104  +			      int sctn_srid,
         6105  +			      double sctn_minx,
         6106  +			      double sctn_miny,
         6107  +			      double sctn_maxx,
         6108  +			      double sctn_maxy,
         6109  +			      int (*getTile) (void *data, double tile_minx,
         6110  +					      double tile_miny,
         6111  +					      double tile_maxx,
         6112  +					      double tile_maxy,
         6113  +					      unsigned char *bufpix,
         6114  +					      rl2PalettePtr * palette),
         6115  +			      void *data, int pyramidize)
         6116  +{
         6117  +/* callback-based IMPORT Raster function */
         6118  +    rl2PrivCoveragePtr privcvg = (rl2PrivCoveragePtr) cvg;
         6119  +    int ret;
         6120  +    char *sql;
         6121  +    const char *coverage;
         6122  +    unsigned char sample_type;
         6123  +    unsigned char pixel_type;
         6124  +    unsigned char num_bands;
         6125  +    unsigned int tile_w;
         6126  +    unsigned int tile_h;
         6127  +    unsigned char compression;
         6128  +    int quality;
         6129  +    char *table;
         6130  +    char *xtable;
         6131  +    unsigned int tileWidth;
         6132  +    unsigned int tileHeight;
         6133  +    unsigned int width = sctn_width;
         6134  +    unsigned int height = sctn_height;
         6135  +    int srid;
         6136  +    double minx = sctn_minx;
         6137  +    double miny = sctn_miny;
         6138  +    double maxx = sctn_maxx;
         6139  +    double maxy = sctn_maxy;
         6140  +    double tile_minx;
         6141  +    double tile_miny;
         6142  +    double tile_maxx;
         6143  +    double tile_maxy;
         6144  +    rl2RasterStatisticsPtr section_stats = NULL;
         6145  +    rl2PixelPtr no_data = NULL;
         6146  +    rl2PalettePtr palette = NULL;
         6147  +    rl2PalettePtr aux_palette = NULL;
         6148  +    unsigned int row;
         6149  +    unsigned int col;
         6150  +    double res_x;
         6151  +    double res_y;
         6152  +    double hResolution;
         6153  +    double vResolution;
         6154  +    double base_res_x;
         6155  +    double base_res_y;
         6156  +    char *xml_summary = NULL;
         6157  +    sqlite3_stmt *stmt_data = NULL;
         6158  +    sqlite3_stmt *stmt_tils = NULL;
         6159  +    sqlite3_stmt *stmt_sect = NULL;
         6160  +    sqlite3_stmt *stmt_levl = NULL;
         6161  +    sqlite3_stmt *stmt_upd_sect = NULL;
         6162  +    sqlite3_int64 section_id;
         6163  +    int pixel_size;
         6164  +    int bufpix_sz;
         6165  +
         6166  +    if (cvg == NULL)
         6167  +	goto error;
         6168  +    if (section == NULL)
         6169  +	goto error;
         6170  +    if (width == 0 || height == 0)
         6171  +	goto error;
         6172  +    if (minx >= maxx || miny >= maxy)
         6173  +	goto error;
         6174  +    hResolution = (sctn_maxx - sctn_minx) / (double) sctn_width;
         6175  +    vResolution = (sctn_maxy - sctn_miny) / (double) sctn_height;
         6176  +
         6177  +    if (rl2_get_coverage_tile_size (cvg, &tileWidth, &tileHeight) != RL2_OK)
         6178  +	goto error;
         6179  +    if (rl2_get_coverage_srid (cvg, &srid) != RL2_OK)
         6180  +	goto error;
         6181  +    if (srid != sctn_srid)
         6182  +	goto error;
         6183  +    srid = sctn_srid;
         6184  +
         6185  +    tile_w = tileWidth;
         6186  +    tile_h = tileHeight;
         6187  +    rl2_get_coverage_compression (cvg, &compression, &quality);
         6188  +    rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands);
         6189  +    coverage = rl2_get_coverage_name (cvg);
         6190  +    switch (sample_type)
         6191  +      {
         6192  +      case RL2_SAMPLE_INT16:
         6193  +      case RL2_SAMPLE_UINT16:
         6194  +	  pixel_size = 2;
         6195  +	  break;
         6196  +      case RL2_SAMPLE_INT32:
         6197  +      case RL2_SAMPLE_UINT32:
         6198  +      case RL2_SAMPLE_FLOAT:
         6199  +	  pixel_size = 4;
         6200  +	  break;
         6201  +      case RL2_SAMPLE_DOUBLE:
         6202  +	  pixel_size = 8;
         6203  +	  break;
         6204  +      default:
         6205  +	  pixel_size = 1;
         6206  +	  break;
         6207  +      };
         6208  +    pixel_size *= num_bands;
         6209  +    bufpix_sz = tile_w * tile_h * pixel_size;
         6210  +
         6211  +    table = sqlite3_mprintf ("%s_sections", coverage);
         6212  +    xtable = rl2_double_quoted_sql (table);
         6213  +    sqlite3_free (table);
         6214  +    sql =
         6215  +	sqlite3_mprintf
         6216  +	("INSERT INTO \"%s\" (section_id, section_name, file_path, "
         6217  +	 "md5_checksum, summary, width, height, geometry) "
         6218  +	 "VALUES (NULL, ?, ?, ?, XB_Create(?), ?, ?, ?)", xtable);
         6219  +    free (xtable);
         6220  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_sect, NULL);
         6221  +    sqlite3_free (sql);
         6222  +    if (ret != SQLITE_OK)
         6223  +      {
         6224  +	  printf ("INSERT INTO sections SQL error: %s\n",
         6225  +		  sqlite3_errmsg (handle));
         6226  +	  goto error;
         6227  +      }
         6228  +
         6229  +    table = sqlite3_mprintf ("%s_sections", coverage);
         6230  +    xtable = rl2_double_quoted_sql (table);
         6231  +    sqlite3_free (table);
         6232  +    sql =
         6233  +	sqlite3_mprintf
         6234  +	("UPDATE \"%s\" SET statistics = ? WHERE section_id = ?", xtable);
         6235  +    free (xtable);
         6236  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_upd_sect, NULL);
         6237  +    sqlite3_free (sql);
         6238  +    if (ret != SQLITE_OK)
         6239  +      {
         6240  +	  printf ("UPDATE sections SQL error: %s\n", sqlite3_errmsg (handle));
         6241  +	  goto error;
         6242  +      }
         6243  +
         6244  +    if (privcvg->mixedResolutions)
         6245  +      {
         6246  +	  /* mixed resolutions Coverage */
         6247  +	  table = sqlite3_mprintf ("%s_section_levels", coverage);
         6248  +	  xtable = rl2_double_quoted_sql (table);
         6249  +	  sqlite3_free (table);
         6250  +	  sql =
         6251  +	      sqlite3_mprintf
         6252  +	      ("INSERT OR IGNORE INTO \"%s\" (section_id, pyramid_level, "
         6253  +	       "x_resolution_1_1, y_resolution_1_1, "
         6254  +	       "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, "
         6255  +	       "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
         6256  +	       "VALUES (?, 0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable);
         6257  +	  free (xtable);
         6258  +	  ret =
         6259  +	      sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL);
         6260  +	  sqlite3_free (sql);
         6261  +	  if (ret != SQLITE_OK)
         6262  +	    {
         6263  +		printf ("INSERT INTO section_levels SQL error: %s\n",
         6264  +			sqlite3_errmsg (handle));
         6265  +		goto error;
         6266  +	    }
         6267  +      }
         6268  +    else
         6269  +      {
         6270  +	  /* single resolution Coverage */
         6271  +	  table = sqlite3_mprintf ("%s_levels", coverage);
         6272  +	  xtable = rl2_double_quoted_sql (table);
         6273  +	  sqlite3_free (table);
         6274  +	  sql =
         6275  +	      sqlite3_mprintf
         6276  +	      ("INSERT OR IGNORE INTO \"%s\" (pyramid_level, "
         6277  +	       "x_resolution_1_1, y_resolution_1_1, "
         6278  +	       "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, "
         6279  +	       "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
         6280  +	       "VALUES (0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable);
         6281  +	  free (xtable);
         6282  +	  ret =
         6283  +	      sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL);
         6284  +	  sqlite3_free (sql);
         6285  +	  if (ret != SQLITE_OK)
         6286  +	    {
         6287  +		printf ("INSERT INTO levels SQL error: %s\n",
         6288  +			sqlite3_errmsg (handle));
         6289  +		goto error;
         6290  +	    }
         6291  +      }
         6292  +
         6293  +    table = sqlite3_mprintf ("%s_tiles", coverage);
         6294  +    xtable = rl2_double_quoted_sql (table);
         6295  +    sqlite3_free (table);
         6296  +    sql =
         6297  +	sqlite3_mprintf
         6298  +	("INSERT INTO \"%s\" (tile_id, pyramid_level, section_id, geometry) "
         6299  +	 "VALUES (NULL, 0, ?, BuildMBR(?, ?, ?, ?, ?))", xtable);
         6300  +    free (xtable);
         6301  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tils, NULL);
         6302  +    sqlite3_free (sql);
         6303  +    if (ret != SQLITE_OK)
         6304  +      {
         6305  +	  printf ("INSERT INTO tiles SQL error: %s\n", sqlite3_errmsg (handle));
         6306  +	  goto error;
         6307  +      }
         6308  +
         6309  +    table = sqlite3_mprintf ("%s_tile_data", coverage);
         6310  +    xtable = rl2_double_quoted_sql (table);
         6311  +    sqlite3_free (table);
         6312  +    sql =
         6313  +	sqlite3_mprintf
         6314  +	("INSERT INTO \"%s\" (tile_id, tile_data_odd, tile_data_even) "
         6315  +	 "VALUES (?, ?, ?)", xtable);
         6316  +    free (xtable);
         6317  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL);
         6318  +    sqlite3_free (sql);
         6319  +    if (ret != SQLITE_OK)
         6320  +      {
         6321  +	  printf ("INSERT INTO tile_data SQL error: %s\n",
         6322  +		  sqlite3_errmsg (handle));
         6323  +	  goto error;
         6324  +      }
         6325  +    res_x = hResolution;
         6326  +    res_y = vResolution;
         6327  +    base_res_x = privcvg->hResolution;
         6328  +    base_res_y = privcvg->vResolution;
         6329  +
         6330  +/* INSERTing the section */
         6331  +    if (!rl2_do_insert_section
         6332  +	(handle, "loaded from RAW pixels", section, srid, width, height, minx,
         6333  +	 miny, maxx, maxy, xml_summary, privcvg->sectionPaths,
         6334  +	 privcvg->sectionMD5, privcvg->sectionSummary, stmt_sect, &section_id))
         6335  +	goto error;
         6336  +    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
         6337  +    if (section_stats == NULL)
         6338  +	goto error;
         6339  +/* INSERTing the base-levels */
         6340  +    if (privcvg->mixedResolutions)
         6341  +      {
         6342  +	  /* multiple resolutions Coverage */
         6343  +	  if (!rl2_do_insert_section_levels
         6344  +	      (handle, section_id, res_x, res_y, 1.0, sample_type, stmt_levl))
         6345  +	      goto error;
         6346  +      }
         6347  +    else
         6348  +      {
         6349  +	  /* single resolution Coverage */
         6350  +	  if (!rl2_do_insert_levels
         6351  +	      (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl))
         6352  +	      goto error;
         6353  +      }
         6354  +
         6355  +/* looping on tiles */
         6356  +    tile_maxy = maxy;
         6357  +    for (row = 0; row < height; row += tile_h)
         6358  +      {
         6359  +	  tile_miny = tile_maxy - ((double) tile_h * res_y);
         6360  +	  tile_minx = minx;
         6361  +	  for (col = 0; col < width; col += tile_w)
         6362  +	    {
         6363  +		/* requesting a Tile */
         6364  +		rl2RasterPtr tile;
         6365  +		unsigned char *blob_odd;
         6366  +		unsigned char *blob_even;
         6367  +		int blob_odd_sz;
         6368  +		int blob_even_sz;
         6369  +		unsigned char *bufpix = malloc (bufpix_sz);
         6370  +
         6371  +		if (pixel_type == RL2_PIXEL_PALETTE)
         6372  +		    rl2_prime_void_tile_palette (bufpix, tile_w, tile_h,
         6373  +						 no_data);
         6374  +		else
         6375  +		    rl2_prime_void_tile (bufpix, tile_w, tile_h,
         6376  +					 sample_type, num_bands, no_data);
         6377  +
         6378  +		tile_maxx = tile_minx + ((double) tile_w * res_x);
         6379  +		if (!getTile
         6380  +		    (data, tile_minx, tile_miny, tile_maxx, tile_maxy, bufpix,
         6381  +		     &palette))
         6382  +		  {
         6383  +		      if (bufpix != NULL)
         6384  +			  free (bufpix);
         6385  +		      goto error;
         6386  +		  }
         6387  +
         6388  +		/* building a raster Tile */
         6389  +		tile =
         6390  +		    rl2_create_raster (tile_w, tile_h, sample_type, pixel_type,
         6391  +				       num_bands, bufpix, bufpix_sz, palette,
         6392  +				       NULL, 0, no_data);
         6393  +		if (tile == NULL)
         6394  +		  {
         6395  +		      if (bufpix != NULL)
         6396  +			  free (bufpix);
         6397  +		      goto error;
         6398  +		  }
         6399  +
         6400  +		/* encoding the Tile */
         6401  +		if (rl2_raster_encode
         6402  +		    (tile, compression, &blob_odd, &blob_odd_sz, &blob_even,
         6403  +		     &blob_even_sz, quality, 1) != RL2_OK)
         6404  +		  {
         6405  +		      fprintf (stderr,
         6406  +			       "ERROR: unable to encode a tile [Row=%d Col=%d]\n",
         6407  +			       row, col);
         6408  +		      rl2_destroy_raster (tile);
         6409  +		      goto error;
         6410  +		  }
         6411  +		aux_palette = rl2_clone_palette (rl2_get_raster_palette (tile));
         6412  +		rl2_destroy_raster (tile);
         6413  +
         6414  +		/* INSERTing the tile */
         6415  +		if (!do_insert_tile
         6416  +		    (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
         6417  +		     section_id, srid, tile_minx, tile_miny, tile_maxx,
         6418  +		     tile_maxy, aux_palette, no_data, stmt_tils, stmt_data,
         6419  +		     section_stats))
         6420  +		    goto error;
         6421  +
         6422  +		/* next tile */
         6423  +		tile_minx += (double) tile_w *res_x;
         6424  +	    }
         6425  +	  tile_maxy -= (double) tile_h *res_y;
         6426  +      }
         6427  +
         6428  +/* updating the Section's Statistics */
         6429  +    compute_aggregate_sq_diff (section_stats);
         6430  +    if (!rl2_do_insert_stats (handle, section_stats, section_id, stmt_upd_sect))
         6431  +	goto error;
         6432  +
         6433  +    rl2_destroy_raster_statistics (section_stats);
         6434  +    section_stats = NULL;
         6435  +
         6436  +    if (pyramidize)
         6437  +      {
         6438  +	  /* immediately building the Section's Pyramid */
         6439  +	  const char *coverage_name = rl2_get_coverage_name (cvg);
         6440  +	  if (coverage_name == NULL)
         6441  +	      goto error;
         6442  +	  if (rl2_build_section_pyramid
         6443  +	      (handle, 1, coverage_name, section_id, 1, 0) != RL2_OK)
         6444  +	    {
         6445  +		fprintf (stderr, "unable to build the Section's Pyramid\n");
         6446  +		goto error;
         6447  +	    }
         6448  +      }
         6449  +
         6450  +    sqlite3_finalize (stmt_upd_sect);
         6451  +    sqlite3_finalize (stmt_sect);
         6452  +    sqlite3_finalize (stmt_levl);
         6453  +    sqlite3_finalize (stmt_tils);
         6454  +    sqlite3_finalize (stmt_data);
         6455  +    stmt_upd_sect = NULL;
         6456  +    stmt_sect = NULL;
         6457  +    stmt_levl = NULL;
         6458  +    stmt_tils = NULL;
         6459  +    stmt_data = NULL;
         6460  +
         6461  +    if (rl2_update_dbms_coverage (handle, coverage) != RL2_OK)
         6462  +      {
         6463  +	  fprintf (stderr, "unable to update the Coverage\n");
         6464  +	  goto error;
         6465  +      }
         6466  +
         6467  +    return RL2_OK;
         6468  +
         6469  +  error:
  6012   6470       if (stmt_upd_sect != NULL)
  6013   6471   	sqlite3_finalize (stmt_upd_sect);
  6014   6472       if (stmt_sect != NULL)
  6015   6473   	sqlite3_finalize (stmt_sect);
  6016   6474       if (stmt_levl != NULL)
  6017   6475   	sqlite3_finalize (stmt_levl);
  6018   6476       if (stmt_tils != NULL)
  6019   6477   	sqlite3_finalize (stmt_tils);
  6020   6478       if (stmt_data != NULL)
  6021   6479   	sqlite3_finalize (stmt_data);
  6022   6480       return RL2_ERROR;
  6023   6481   }

Changes to src/rl2jpeg.c.

   226    226       /* The source object is made permanent so that a series of JPEG images
   227    227        * can be read from the same buffer by calling jpeg_mem_src only before
   228    228        * the first one.
   229    229        */
   230    230       if (cinfo->src == NULL)
   231    231         {				/* first time for this JPEG object? */
   232    232   	  cinfo->src = (struct jpeg_source_mgr *)
   233         -	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
          233  +	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
          234  +					  JPOOL_PERMANENT,
   234    235   					  sizeof (struct jpeg_source_mgr));
   235    236         }
   236    237   
   237    238       src = cinfo->src;
   238    239       src->init_source = init_mem_source;
   239    240       src->fill_input_buffer = fill_mem_input_buffer;
   240    241       src->skip_input_data = skip_input_data;
................................................................................
   261    262   
   262    263       /* The destination object is made permanent so that multiple JPEG images
   263    264        * can be written to the same buffer without re-executing jpeg_mem_dest.
   264    265        */
   265    266       if (cinfo->dest == NULL)
   266    267         {				/* first time for this JPEG object? */
   267    268   	  cinfo->dest = (struct jpeg_destination_mgr *)
   268         -	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
          269  +	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
          270  +					  JPOOL_PERMANENT,
   269    271   					  sizeof (jpeg_mem_destination_mgr));
   270    272   	  dest = (jpeg_mem_dest_ptr) cinfo->dest;
   271    273   	  dest->newbuffer = NULL;
   272    274         }
   273    275   
   274    276       dest = (jpeg_mem_dest_ptr) cinfo->dest;
   275    277       dest->pub.init_destination = init_mem_destination;
................................................................................
   753    755   /* creating a JPEG image from a raster */
   754    756       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
   755    757       unsigned char *blob;
   756    758       int blob_size;
   757    759   
   758    760       if (rst == NULL)
   759    761   	return RL2_ERROR;
   760         -    if (check_jpeg_compatibility (rst->sampleType, rst->pixelType, rst->nBands)
   761         -	!= RL2_OK)
          762  +    if (check_jpeg_compatibility
          763  +	(rst->sampleType, rst->pixelType, rst->nBands) != RL2_OK)
   762    764   	return RL2_ERROR;
   763    765       if (rl2_data_to_jpeg
   764    766   	(rst->rasterBuffer, rst->maskBuffer, (rl2PalettePtr) (rst->Palette),
   765    767   	 rst->width, rst->height, rst->sampleType, rst->pixelType, &blob,
   766    768   	 &blob_size, quality) != RL2_OK)
   767    769   	return RL2_ERROR;
   768    770       *jpeg = blob;
................................................................................
   778    780   /* creating a PNG image from an RGB buffer */
   779    781       unsigned char *blob;
   780    782       int blob_size;
   781    783       if (rgb == NULL)
   782    784   	return RL2_ERROR;
   783    785   
   784    786       if (rl2_data_to_jpeg
   785         -	(rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, &blob,
   786         -	 &blob_size, quality) != RL2_OK)
          787  +	(rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB,
          788  +	 &blob, &blob_size, quality) != RL2_OK)
   787    789   	return RL2_ERROR;
   788    790       *jpeg = blob;
   789    791       *jpeg_size = blob_size;
   790    792       return RL2_OK;
   791    793   }
   792    794   
   793    795   RL2_DECLARE int
   794    796   rl2_gray_to_jpeg (unsigned int width, unsigned int height,
   795         -		  const unsigned char *gray, int quality, unsigned char **jpeg,
   796         -		  int *jpeg_size)
          797  +		  const unsigned char *gray, int quality,
          798  +		  unsigned char **jpeg, int *jpeg_size)
   797    799   {
   798    800   /* creating a PNG image from a Grayscale buffer */
   799    801       unsigned char *blob;
   800    802       int blob_size;
   801    803       if (gray == NULL)
   802    804   	return RL2_ERROR;
   803    805   
   804    806       if (rl2_data_to_jpeg
   805         -	(gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
   806         -	 &blob, &blob_size, quality) != RL2_OK)
          807  +	(gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8,
          808  +	 RL2_PIXEL_GRAYSCALE, &blob, &blob_size, quality) != RL2_OK)
   807    809   	return RL2_ERROR;
   808    810       *jpeg = blob;
   809    811       *jpeg_size = blob_size;
   810    812       return RL2_OK;
   811    813   }
   812    814   
   813    815   RL2_PRIVATE int
................................................................................
   847    849       rst = rl2_raster_from_jpeg (blob, blob_size);
   848    850       free (blob);
   849    851       if (rst == NULL)
   850    852   	return NULL;
   851    853   
   852    854   /* creating the raster section */
   853    855       scn =
   854         -	rl2_create_section (path, RL2_COMPRESSION_JPEG, RL2_TILESIZE_UNDEFINED,
   855         -			    RL2_TILESIZE_UNDEFINED, rst);
          856  +	rl2_create_section (path, RL2_COMPRESSION_JPEG,
          857  +			    RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED,
          858  +			    rst);
   856    859       return scn;
   857    860   }
   858    861   
   859    862   RL2_DECLARE rl2RasterPtr
   860    863   rl2_raster_from_jpeg (const unsigned char *jpeg, int jpeg_size)
   861    864   {
   862    865   /* attempting to create a raster from a JPEG image */
................................................................................
   874    877   	goto error;
   875    878       nBands = 1;
   876    879       if (pixel_type == RL2_PIXEL_RGB)
   877    880   	nBands = 3;
   878    881   
   879    882   /* creating the raster */
   880    883       rst =
   881         -	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type, nBands,
   882         -			   data, data_size, NULL, NULL, 0, NULL);
          884  +	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type,
          885  +			   nBands, data, data_size, NULL, NULL, 0, NULL);
   883    886       if (rst == NULL)
   884    887   	goto error;
   885    888       return rst;
   886    889   
   887    890     error:
   888    891       if (rst != NULL)
   889    892   	rl2_destroy_raster (rst);
   890    893       if (data != NULL)
   891    894   	free (data);
   892    895       return NULL;
   893    896   }
   894    897   
   895    898   RL2_DECLARE int
   896         -rl2_get_jpeg_infos (const char *path, unsigned int *width, unsigned int *height,
   897         -		    unsigned char *pixel_type)
          899  +rl2_get_jpeg_infos (const char *path, unsigned int *width,
          900  +		    unsigned int *height, unsigned char *pixel_type)
   898    901   {
   899    902   /* attempting to retrieve basic infos from a JPEG image */
   900    903       int jpeg_size;
   901    904       unsigned char *jpeg = NULL;
   902    905       struct jpeg_decompress_struct cinfo;
   903    906       struct jpeg_error_mgr jerr;
   904    907       int row_stride;
................................................................................
  1060   1063   	  /* reading all decompressed scanlines */
  1061   1064   	  jpeg_read_scanlines (&cinfo, buffer, 1);
  1062   1065   	  if (cinfo.out_color_space == JCS_CMYK)
  1063   1066   	    {
  1064   1067   		JSAMPROW row = buffer[0];
  1065   1068   		for (i = 0; i < (int) (cinfo.output_width); i++)
  1066   1069   		  {
  1067         -		      CMYK2RGB (*(row + 0), *(row + 1), *(row + 2), *(row + 3),
  1068         -				inverted, p_data);
         1070  +		      CMYK2RGB (*(row + 0), *(row + 1), *(row + 2),
         1071  +				*(row + 3), inverted, p_data);
  1069   1072   		      row += 4;
  1070   1073   		      p_data += 3;
  1071   1074   		  }
  1072   1075   	    }
  1073   1076   	  else if (cinfo.out_color_space == JCS_GRAYSCALE)
  1074   1077   	    {
  1075   1078   		JSAMPROW row = buffer[0];
................................................................................
  1294   1297   				unsigned char forced_conversion, int verbose)
  1295   1298   {
  1296   1299   /* checking for strict compatibility */
  1297   1300       if (coverage->sampleType == RL2_SAMPLE_UINT8
  1298   1301   	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
  1299   1302         {
  1300   1303   	  if (raster->sampleType == RL2_SAMPLE_UINT8
  1301         -	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
  1302         -	      && forced_conversion == RL2_CONVERT_NO)
         1304  +	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
         1305  +	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
  1303   1306   	      return 1;
  1304   1307   	  if (raster->sampleType == RL2_SAMPLE_UINT8
  1305   1308   	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
  1306   1309   	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
  1307   1310   	      return 1;
  1308   1311         }
  1309   1312       if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
  1310   1313   	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
  1311   1314         {
  1312   1315   	  if (raster->sampleType == RL2_SAMPLE_UINT8
  1313   1316   	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
  1314   1317   	      && forced_conversion == RL2_CONVERT_NO)
  1315   1318   	      return 1;
  1316   1319   	  if (raster->sampleType == RL2_SAMPLE_UINT8
  1317         -	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
         1320  +	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
         1321  +	      && raster->nBands == 1
  1318   1322   	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
  1319   1323   	      return 1;
  1320   1324         }
  1321   1325       if (verbose)
  1322   1326   	fprintf (stderr, "Mismatching JPEG colorspace !!!\n");
  1323   1327       return 0;
  1324   1328   }
................................................................................
  1528   1532   	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
  1529   1533   	  sqlite3_free (prev);
  1530   1534   	  prev = xml;
  1531   1535   	  xml = sqlite3_mprintf ("%s<Extent>", prev);
  1532   1536   	  sqlite3_free (prev);
  1533   1537   	  prev = xml;
  1534   1538   	  xml =
  1535         -	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
  1536         -			       prev, maxx - minx);
         1539  +	      sqlite3_mprintf
         1540  +	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
         1541  +	       maxx - minx);
  1537   1542   	  sqlite3_free (prev);
  1538   1543   	  prev = xml;
  1539   1544   	  xml =
  1540   1545   	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
  1541   1546   			       prev, maxy - miny);
  1542   1547   	  sqlite3_free (prev);
  1543   1548   	  prev = xml;

Changes to src/rl2openjpeg.c.

    55     55   #include "rasterlite2/rl2tiff.h"
    56     56   #include "rasterlite2_private.h"
    57     57   
    58     58   #ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
    59     59   
    60     60   #ifdef HAVE_OPENJPEG_2_1_OPENJPEG_H
    61     61   #include <openjpeg-2.1/openjpeg.h>
           62  +#else
           63  +#ifdef __ANDROID__		/* Android specific */
           64  +#include <openjpeg.h>
    62     65   #else
    63     66   #include <openjpeg-2.0/openjpeg.h>
           67  +#endif
    64     68   #endif
    65     69   
    66     70   struct jp2_memfile
    67     71   {
    68     72   /* a struct emulating a file [memory mapped] */
    69     73       unsigned char *buffer;
    70     74       int malloc_block;
................................................................................
   688    692         }
   689    693   }
   690    694   
   691    695   RL2_PRIVATE int
   692    696   rl2_decode_jpeg2000_scaled (int scale, const unsigned char *jpeg2000,
   693    697   			    int jpeg2000_sz, unsigned int *xwidth,
   694    698   			    unsigned int *xheight, unsigned char xsample_type,
   695         -			    unsigned char xpixel_type, unsigned char xnum_bands,
   696         -			    unsigned char **pixels, int *pixels_size)
          699  +			    unsigned char xpixel_type,
          700  +			    unsigned char xnum_bands, unsigned char **pixels,
          701  +			    int *pixels_size)
   697    702   {
   698    703   /* attempting to create a raster from a Jpeg2000 image - supporting rescaled size */
   699    704       unsigned char *buf = NULL;
   700    705       int buf_size = 0;
   701    706       unsigned int width;
   702    707       unsigned int height;
   703    708       unsigned char sample_type = RL2_SAMPLE_UNKNOWN;
................................................................................
   854    859   		fprintf (stderr,
   855    860   			 "OpenJpeg Error: opj_decode_tile_data() failed\n");
   856    861   		goto error;
   857    862   	    }
   858    863   	  if (sample_type == RL2_SAMPLE_UINT16)
   859    864   	      save_tile_u16 ((unsigned short *) buf,
   860    865   			     (unsigned short *) jp2_data, tile_x0 / scale,
   861         -			     tile_y0 / scale, tile_x1 / scale, tile_y1 / scale,
   862         -			     num_bands, width / scale, height / scale);
          866  +			     tile_y0 / scale, tile_x1 / scale,
          867  +			     tile_y1 / scale, num_bands, width / scale,
          868  +			     height / scale);
   863    869   	  else
   864    870   	      save_tile_u8 ((unsigned char *) buf, (unsigned char *) jp2_data,
   865    871   			    tile_x0 / scale, tile_y0 / scale, tile_x1 / scale,
   866    872   			    tile_y1 / scale, num_bands, width / scale,
   867    873   			    height / scale);
   868    874   	  free (jp2_data);
   869    875   	  jp2_data = NULL;
................................................................................
   897    903   				    int verbose)
   898    904   {
   899    905   /* checking for strict compatibility */
   900    906       if (coverage->sampleType == RL2_SAMPLE_UINT8
   901    907   	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
   902    908         {
   903    909   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   904         -	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
   905         -	      && forced_conversion == RL2_CONVERT_NO)
          910  +	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
          911  +	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
   906    912   	      return 1;
   907    913   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   908    914   	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
   909    915   	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
   910    916   	      return 1;
   911    917         }
   912    918       if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
   913    919   	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
   914    920         {
   915    921   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   916    922   	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
   917    923   	      && forced_conversion == RL2_CONVERT_NO)
   918    924   	      return 1;
   919    925   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   920         -	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
          926  +	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
          927  +	      && raster->nBands == 1
   921    928   	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
   922    929   	      return 1;
   923    930         }
   924    931       if (coverage->sampleType == RL2_SAMPLE_UINT8
   925    932   	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
   926    933         {
   927    934   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   928         -	      && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1
   929         -	      && forced_conversion == RL2_CONVERT_NO)
          935  +	      && raster->pixelType == RL2_PIXEL_DATAGRID
          936  +	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
   930    937   	      return 1;
   931    938         }
   932    939       if (coverage->sampleType == RL2_SAMPLE_UINT8
   933         -	&& coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3
   934         -							  || coverage->nBands ==
   935         -							  4))
          940  +	&& coverage->pixelType == RL2_PIXEL_MULTIBAND
          941  +	&& (coverage->nBands == 3 || coverage->nBands == 4))
   936    942         {
   937    943   	  if (raster->sampleType == RL2_SAMPLE_UINT8
   938    944   	      && raster->pixelType == RL2_PIXEL_MULTIBAND
   939    945   	      && raster->nBands == coverage->nBands
   940    946   	      && forced_conversion == RL2_CONVERT_NO)
   941    947   	      return 1;
   942    948         }
   943    949       if (coverage->sampleType == RL2_SAMPLE_UINT16
   944    950   	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
   945    951         {
   946    952   	  if (raster->sampleType == RL2_SAMPLE_UINT16
   947         -	      && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1
   948         -	      && forced_conversion == RL2_CONVERT_NO)
          953  +	      && raster->pixelType == RL2_PIXEL_DATAGRID
          954  +	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
   949    955   	      return 1;
   950    956         }
   951    957       if (coverage->sampleType == RL2_SAMPLE_UINT16
   952    958   	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
   953    959         {
   954    960   	  if (raster->sampleType == RL2_SAMPLE_UINT16
   955    961   	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
   956    962   	      && forced_conversion == RL2_CONVERT_NO)
   957    963   	      return 1;
   958    964         }
   959    965       if (coverage->sampleType == RL2_SAMPLE_UINT16
   960         -	&& coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3
   961         -							  || coverage->nBands ==
   962         -							  4))
          966  +	&& coverage->pixelType == RL2_PIXEL_MULTIBAND
          967  +	&& (coverage->nBands == 3 || coverage->nBands == 4))
   963    968         {
   964    969   	  if (raster->sampleType == RL2_SAMPLE_UINT16
   965    970   	      && raster->pixelType == RL2_PIXEL_MULTIBAND
   966    971   	      && raster->nBands == coverage->nBands
   967    972   	      && forced_conversion == RL2_CONVERT_NO)
   968    973   	      return 1;
   969    974         }
   970    975       if (verbose)
   971    976   	fprintf (stderr, "Mismatching Jpeg2000 colorspace !!!\n");
   972    977       return 0;
   973    978   }
   974    979   
   975    980   static int
   976         -read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin, unsigned short width,
   977         -				  unsigned short height, unsigned int startRow,
          981  +read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin,
          982  +				  unsigned short width, unsigned short height,
          983  +				  unsigned int startRow,
   978    984   				  unsigned int startCol, unsigned char *pixels)
   979    985   {
   980    986   /* Grayscale -> RGB */
   981    987       unsigned short x;
   982    988       unsigned short y;
   983    989       unsigned short row;
   984    990       unsigned short col;
................................................................................
   998   1004   		*p_out++ = value;	/* blue */
   999   1005   	    }
  1000   1006         }
  1001   1007       return 1;
  1002   1008   }
  1003   1009   
  1004   1010   static int
  1005         -read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin, unsigned short width,
  1006         -				  unsigned short height, unsigned int startRow,
         1011  +read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin,
         1012  +				  unsigned short width, unsigned short height,
         1013  +				  unsigned int startRow,
  1007   1014   				  unsigned int startCol, unsigned char *pixels)
  1008   1015   {
  1009   1016   /* RGB -> Grayscale */
  1010   1017       unsigned short x;
  1011   1018       unsigned short y;
  1012   1019       unsigned short row;
  1013   1020       unsigned short col;
................................................................................
  1186   1193       if (no_data != NULL)
  1187   1194   	rl2_destroy_pixel (no_data);
  1188   1195       return RL2_ERROR;
  1189   1196   }
  1190   1197   
  1191   1198   RL2_DECLARE rl2RasterPtr
  1192   1199   rl2_get_tile_from_jpeg2000_origin (rl2CoveragePtr cvg, rl2RasterPtr jpeg2000,
  1193         -				   unsigned int startRow, unsigned int startCol,
         1200  +				   unsigned int startRow,
         1201  +				   unsigned int startCol,
  1194   1202   				   unsigned char forced_conversion, int verbose)
  1195   1203   {
  1196   1204   /* attempting to create a Coverage-tile from a Jpeg2000 origin */
  1197   1205       unsigned int x;
  1198   1206       rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg;
  1199   1207       rl2PrivRasterPtr origin = (rl2PrivRasterPtr) jpeg2000;
  1200   1208       rl2RasterPtr raster = NULL;
................................................................................
  1600   1608   	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
  1601   1609   	  sqlite3_free (prev);
  1602   1610   	  prev = xml;
  1603   1611   	  xml = sqlite3_mprintf ("%s<Extent>", prev);
  1604   1612   	  sqlite3_free (prev);
  1605   1613   	  prev = xml;
  1606   1614   	  xml =
  1607         -	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
  1608         -			       prev, maxx - minx);
         1615  +	      sqlite3_mprintf
         1616  +	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
         1617  +	       maxx - minx);
  1609   1618   	  sqlite3_free (prev);
  1610   1619   	  prev = xml;
  1611   1620   	  xml =
  1612   1621   	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
  1613   1622   			       prev, maxy - miny);
  1614   1623   	  sqlite3_free (prev);
  1615   1624   	  prev = xml;

Changes to src/rl2paint.c.

   182    182       int width;
   183    183       int height;
   184    184       unsigned char *rgba;
   185    185       cairo_surface_t *bitmap;
   186    186       cairo_pattern_t *pattern;
   187    187   } RL2GraphBitmap;
   188    188   typedef RL2GraphBitmap *RL2GraphBitmapPtr;
          189  +
          190  +static unsigned char
          191  +unpremultiply (unsigned char c, unsigned char a)
          192  +{
          193  +/* Cairo has premultiplied alphas */
          194  +    double x = ((double) c * 255.0) / (double) a;
          195  +    if (a == 0)
          196  +	return 0;
          197  +    return (unsigned char) x;
          198  +}
   189    199   
   190    200   RL2_DECLARE rl2GraphicsContextPtr
   191    201   rl2_graph_create_context (int width, int height)
   192    202   {
   193    203   /* creating a generic Graphics Context */
   194    204       RL2GraphContextPtr ctx;
   195    205   
................................................................................
   768    778   					 double height, unsigned char red1,
   769    779   					 unsigned char green1,
   770    780   					 unsigned char blue1,
   771    781   					 unsigned char alpha1,
   772    782   					 unsigned char red2,
   773    783   					 unsigned char green2,
   774    784   					 unsigned char blue2,
   775         -					 unsigned char alpha2, double pen_width,
   776         -					 int line_cap, int line_join)
          785  +					 unsigned char alpha2,
          786  +					 double pen_width, int line_cap,
          787  +					 int line_join)
   777    788   {
   778    789   /* setting up a Linear Gradient Pen - solid style */
   779    790       double d_red = (double) red1 / 255.0;
   780    791       double d_green = (double) green1 / 255.0;
   781    792       double d_blue = (double) blue1 / 255.0;
   782    793       double d_alpha = (double) alpha1 / 255.0;
   783    794       RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
................................................................................
  1043   1054       return 1;
  1044   1055   }
  1045   1056   
  1046   1057   RL2_DECLARE int
  1047   1058   rl2_graph_set_linear_gradient_brush (rl2GraphicsContextPtr context, double x,
  1048   1059   				     double y, double width, double height,
  1049   1060   				     unsigned char red1, unsigned char green1,
  1050         -				     unsigned char blue1, unsigned char alpha1,
  1051         -				     unsigned char red2, unsigned char green2,
         1061  +				     unsigned char blue1,
         1062  +				     unsigned char alpha1, unsigned char red2,
         1063  +				     unsigned char green2,
  1052   1064   				     unsigned char blue2, unsigned char alpha2)
  1053   1065   {
  1054   1066   /* setting up a Linear Gradient Brush */
  1055   1067       double d_red = (double) red1 / 255.0;
  1056   1068       double d_green = (double) green1 / 255.0;
  1057   1069       double d_blue = (double) blue1 / 255.0;
  1058   1070       double d_alpha = (double) alpha1 / 255.0;
................................................................................
  1164   1176   	      style = CAIRO_FONT_SLANT_ITALIC;
  1165   1177   	  if (fnt->style == RL2_FONTSTYLE_OBLIQUE)
  1166   1178   	      style = CAIRO_FONT_SLANT_OBLIQUE;
  1167   1179   	  if (fnt->weight == RL2_FONTWEIGHT_BOLD)
  1168   1180   	      weight = CAIRO_FONT_WEIGHT_BOLD;
  1169   1181   	  cairo_select_font_face (cairo, fnt->facename, style, weight);
  1170   1182   	  cairo_set_font_size (cairo, size);
         1183  +	  fnt->cairo_font = cairo_get_font_face (cairo);
  1171   1184         }
  1172   1185       else
  1173   1186         {
  1174   1187   	  /* using a TrueType font */
  1175   1188   	  cairo_font_options_t *font_options = cairo_font_options_create ();
  1176   1189   	  cairo_matrix_t ctm;
  1177   1190   	  cairo_matrix_t font_matrix;
................................................................................
  1554   1567       unsigned char red;
  1555   1568       unsigned char green;
  1556   1569       unsigned char blue;
  1557   1570       unsigned char alpha;
  1558   1571       unsigned char xred;
  1559   1572       unsigned char xgreen;
  1560   1573       unsigned char xblue;
         1574  +    unsigned char xalpha;
  1561   1575       int valid = 0;
         1576  +    int has_black = 0;
  1562   1577       unsigned char *bitmap;
  1563   1578       RL2PrivGraphPatternPtr pattern = (RL2PrivGraphPatternPtr) ptrn;
  1564   1579       if (pattern == NULL)
  1565   1580   	return RL2_ERROR;
  1566   1581   
  1567   1582       width = pattern->width;
  1568   1583       height = pattern->height;
................................................................................
  1571   1586       if (bitmap == NULL)
  1572   1587   	return RL2_ERROR;
  1573   1588   /* checking for a Monochrome Pattern */
  1574   1589       for (y = 0; y < height; y++)
  1575   1590         {
  1576   1591   	  for (x = 0; x < width; x++)
  1577   1592   	    {
  1578         -		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
  1579         -				       &alpha);
         1593  +		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
         1594  +				       &blue, &alpha);
  1580   1595   		if (alpha != 0)
  1581   1596   		  {
         1597  +		      if (red < 64 && green < 64 && blue < 64)
         1598  +			  has_black++;
  1582   1599   		      if (valid)
  1583   1600   			{
  1584         -			    if (xred == red && xgreen == green && xblue == blue)
         1601  +			    if (xred == red && xgreen == green
         1602  +				&& xblue == blue && alpha == xalpha)
  1585   1603   				;
  1586   1604   			    else
  1587         -				return RL2_ERROR;
         1605  +				goto not_mono;
  1588   1606   			}
  1589   1607   		      else
  1590   1608   			{
  1591   1609   			    xred = red;
  1592   1610   			    xgreen = green;
  1593   1611   			    xblue = blue;
         1612  +			    xalpha = alpha;
  1594   1613   			    valid = 1;
  1595   1614   			}
  1596   1615   		  }
  1597   1616   	    }
  1598   1617         }
  1599   1618   /* all right, applying the new color */
  1600   1619       for (y = 0; y < height; y++)
  1601   1620         {
  1602   1621   	  for (x = 0; x < width; x++)
  1603   1622   	    {
  1604         -		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
  1605         -				       &alpha);
         1623  +		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
         1624  +				       &blue, &alpha);
  1606   1625   		if (alpha != 0)
  1607   1626   		    aux_pattern_set_pixel (x, y, width, bitmap, r, g, b, alpha);
  1608   1627   	    }
  1609   1628         }
  1610   1629       cairo_surface_mark_dirty (pattern->bitmap);
  1611   1630       return RL2_OK;
         1631  +
         1632  +  not_mono:
         1633  +    if (has_black)
         1634  +      {
         1635  +	  /* recoloring only the black pixels */
         1636  +	  for (y = 0; y < height; y++)
         1637  +	    {
         1638  +		for (x = 0; x < width; x++)
         1639  +		  {
         1640  +		      aux_pattern_get_pixel (x, y, width, bitmap, &red,
         1641  +					     &green, &blue, &alpha);
         1642  +		      if (red < 64 && green < 64 && blue < 64)
         1643  +			  aux_pattern_set_pixel (x, y, width, bitmap, r, g, b,
         1644  +						 alpha);
         1645  +		  }
         1646  +	    }
         1647  +	  cairo_surface_mark_dirty (pattern->bitmap);
         1648  +	  return RL2_OK;
         1649  +      }
         1650  +    return RL2_ERROR;
  1612   1651   }
  1613   1652   
  1614   1653   RL2_DECLARE int
  1615   1654   rl2_graph_pattern_transparency (rl2GraphicsPatternPtr ptrn, unsigned char aleph)
  1616   1655   {
  1617   1656   /* changing the Pattern's transparency */
  1618   1657       int x;
................................................................................
  1635   1674       if (bitmap == NULL)
  1636   1675   	return RL2_ERROR;
  1637   1676   /* applying the new transparency */
  1638   1677       for (y = 0; y < height; y++)
  1639   1678         {
  1640   1679   	  for (x = 0; x < width; x++)
  1641   1680   	    {
  1642         -		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
  1643         -				       &alpha);
         1681  +		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
         1682  +				       &blue, &alpha);
  1644   1683   		if (alpha != 0)
  1645   1684   		    aux_pattern_set_pixel (x, y, width, bitmap, red, green,
  1646   1685   					   blue, aleph);
  1647   1686   	    }
  1648   1687         }
  1649   1688       cairo_surface_mark_dirty (pattern->bitmap);
  1650   1689       return RL2_OK;
................................................................................
  1765   1804         }
  1766   1805   
  1767   1806   /* destroying the cached font */
  1768   1807       rl2_destroy_private_tt_font (font);
  1769   1808   }
  1770   1809   
  1771   1810   RL2_DECLARE rl2GraphicsFontPtr
  1772         -rl2_graph_create_TrueType_font (const void *priv_data, const unsigned char *ttf,
  1773         -				int ttf_bytes, double size)
         1811  +rl2_graph_create_TrueType_font (const void *priv_data,
         1812  +				const unsigned char *ttf, int ttf_bytes,
         1813  +				double size)
  1774   1814   {
  1775   1815   /* creating a TrueType font */
  1776   1816       RL2GraphFontPtr fnt;
  1777   1817       char *facename;
  1778   1818       int is_bold;
  1779   1819       int is_italic;
  1780   1820       unsigned char *font = NULL;
................................................................................
  1908   1948   }
  1909   1949   
  1910   1950   RL2_DECLARE void
  1911   1951   rl2_graph_destroy_font (rl2GraphicsFontPtr font)
  1912   1952   {
  1913   1953   /* destroying a font */
  1914   1954       RL2GraphFontPtr fnt = (RL2GraphFontPtr) font;
  1915         -
  1916   1955       if (fnt == NULL)
  1917   1956   	return;
  1918   1957       if (fnt->toy_font == 0)
  1919   1958         {
  1920   1959   	  if (fnt->cairo_scaled_font != NULL)
  1921   1960   	      cairo_scaled_font_destroy (fnt->cairo_scaled_font);
  1922         -	  if (fnt->cairo_font != NULL)
  1923         -	      cairo_font_face_destroy (fnt->cairo_font);
  1924   1961         }
  1925   1962       else
  1926   1963         {
  1927   1964   	  if (fnt->facename != NULL)
  1928   1965   	      free (fnt->facename);
  1929         -	  free (fnt);
  1930   1966         }
         1967  +    if (fnt->cairo_font != NULL)
         1968  +      {
         1969  +	  if (cairo_font_face_get_reference_count (fnt->cairo_font) > 0)
         1970  +	      cairo_font_face_destroy (fnt->cairo_font);
         1971  +      }
         1972  +    free (fnt);
  1931   1973   }
  1932   1974   
  1933   1975   RL2_DECLARE int
  1934   1976   rl2_graph_font_set_color (rl2GraphicsFontPtr font, unsigned char red,
  1935   1977   			  unsigned char green, unsigned char blue,
  1936   1978   			  unsigned char alpha)
  1937   1979   {
................................................................................
  2262   2304       set_current_pen (ctx);
  2263   2305       cairo_stroke (cairo);
  2264   2306       return 1;
  2265   2307   }
  2266   2308   
  2267   2309   RL2_DECLARE int
  2268   2310   rl2_graph_draw_circle_sector (rl2GraphicsContextPtr context, double center_x,
  2269         -			      double center_y, double radius, double from_angle,
  2270         -			      double to_angle)
         2311  +			      double center_y, double radius,
         2312  +			      double from_angle, double to_angle)
  2271   2313   {
  2272   2314   /* drawing a filled circular sector */
  2273   2315       cairo_t *cairo;
  2274   2316       RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
  2275   2317       if (ctx == NULL)
  2276   2318   	return 0;
  2277   2319       if (ctx->type == RL2_SURFACE_PDF)
................................................................................
  2427   2469       *height = extents.height;
  2428   2470       *post_x = extents.x_advance;
  2429   2471       *post_y = extents.y_advance;
  2430   2472       return 1;
  2431   2473   }
  2432   2474   
  2433   2475   RL2_DECLARE int
  2434         -rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text, double x,
  2435         -		     double y, double angle, double anchor_point_x,
         2476  +rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text,
         2477  +		     double x, double y, double angle, double anchor_point_x,
  2436   2478   		     double anchor_point_y)
  2437   2479   {
  2438   2480   /* drawing a text string (using the current font) */
  2439   2481       double rads;
  2440   2482       double pre_x;
  2441   2483       double pre_y;
  2442   2484       double width;
................................................................................
  2576   2618   			  rl2_geometry_from_blob (blob3, size3);
  2577   2619   		      if (result == NULL)
  2578   2620   			  break;
  2579   2621   		      if (result->first_point == NULL)
  2580   2622   			  break;
  2581   2623   		      *x = result->first_point->x;
  2582   2624   		      *y = result->first_point->y;
         2625  +		      rl2_destroy_geometry (result);
  2583   2626   		      ok = 1;
  2584   2627   		  }
  2585   2628   	    }
  2586   2629   	  else
  2587   2630   	      goto error;
  2588   2631         }
  2589   2632       if (ok == 0)
................................................................................
  2609   2652       rl2GetPoint (ln->coords, ln->points - 1, &xx, &yy);
  2610   2653       if (xx == x && yy == y)
  2611   2654   	return 1;
  2612   2655       return 0;
  2613   2656   }
  2614   2657   
  2615   2658   static rl2GeometryPtr
  2616         -aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom, rl2GeometryPtr circle,
  2617         -		  double x, double y)
         2659  +aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom,
         2660  +		  rl2GeometryPtr circle, double x, double y)
  2618   2661   {
  2619   2662   /* reducing a Curve by discarding the alreasdy processed portion */
  2620   2663       sqlite3_stmt *stmt = NULL;
  2621   2664       const char *sql;
  2622   2665       int ret;
  2623   2666       unsigned char *blob1;
  2624   2667       int size1;
  2625   2668       unsigned char *blob2;
  2626   2669       int size2;
  2627   2670       rl2GeometryPtr out = NULL;
  2628   2671       rl2LinestringPtr ln;
  2629         -    rl2LinestringPtr save_ln = NULL;
  2630   2672       int count = 0;
  2631   2673   
  2632   2674       rl2_serialize_linestring (geom->first_linestring, &blob1, &size1);
  2633   2675       rl2_serialize_linestring (circle->first_linestring, &blob2, &size2);
  2634   2676   
  2635   2677   /* preparing the SQL query statement */
  2636   2678       sql = "SELECT ST_Split(?, ?)";
................................................................................
  2660   2702   		      ln = result->first_linestring;
  2661   2703   		      while (ln != NULL)
  2662   2704   			{
  2663   2705   			    if (aux_is_discarded_portion (ln, x, y))
  2664   2706   				;
  2665   2707   			    else
  2666   2708   			      {
  2667         -				  save_ln = ln;
         2709  +				  if (out != NULL)
         2710  +				      rl2_destroy_geometry (out);
         2711  +				  out = rl2_clone_linestring (ln);
  2668   2712   				  count++;
  2669   2713   			      }
  2670   2714   			    ln = ln->next;
  2671   2715   			}
         2716  +		      rl2_destroy_geometry (result);
  2672   2717   		  }
  2673   2718   	    }
  2674   2719   	  else
  2675   2720   	      goto error;
  2676   2721         }
  2677         -    if (save_ln == NULL || count != 1)
         2722  +    if (out == NULL || count != 1)
  2678   2723   	goto error;
  2679         -    out = rl2_clone_linestring (save_ln);
  2680   2724       sqlite3_finalize (stmt);
  2681   2725       return out;
  2682   2726   
  2683   2727     error:
  2684   2728       if (stmt != NULL)
  2685   2729   	sqlite3_finalize (stmt);
         2730  +    if (out != NULL)
         2731  +	rl2_destroy_geometry (out);
  2686   2732       return NULL;
  2687   2733   }
         2734  +
         2735  +static int
         2736  +check_reverse (rl2GeometryPtr geom)
         2737  +{
         2738  +/* testing for an inverse label */
         2739  +    rl2LinestringPtr ln;
         2740  +    double x0;
         2741  +    double y0;
         2742  +    double x1;
         2743  +    double y1;
         2744  +    double width;
         2745  +    double height;
         2746  +    int last;
         2747  +
         2748  +    if (geom == NULL)
         2749  +	return 0;
         2750  +    ln = geom->first_linestring;
         2751  +    if (ln == NULL)
         2752  +	return 0;
         2753  +    if (ln->points < 2)
         2754  +	return 0;
         2755  +    last = ln->points - 1;
         2756  +
         2757  +    rl2GetPoint (ln->coords, 0, &x0, &y0);
         2758  +    rl2GetPoint (ln->coords, last, &x1, &y1);
         2759  +    width = fabs (x0 - x1);
         2760  +    height = fabs (y0 - y1);
         2761  +    if (width > 3.0)
         2762  +      {
         2763  +	  if (x0 > x1)
         2764  +	      return 1;
         2765  +      }
         2766  +    else
         2767  +      {
         2768  +	  if (y0 > y1)
         2769  +	      return 1;
         2770  +      }
         2771  +    return 0;
         2772  +}
         2773  +
         2774  +static void
         2775  +reverse_text (const char *in, char *dest, int len)
         2776  +{
         2777  +/* reversing a text string */
         2778  +    char *out;
         2779  +    int n = 1;
         2780  +    while (*in != '\0')
         2781  +      {
         2782  +	  out = dest + len - n;
         2783  +	  *out = *in++;
         2784  +	  n++;
         2785  +      }
         2786  +    *(dest + len) = '\0';
         2787  +}
  2688   2788   
  2689   2789   static rl2GeometryPtr
  2690   2790   rl2_draw_wrapped_label (sqlite3 * handle, rl2GraphicsContextPtr context,
  2691   2791   			cairo_t * cairo, const char *text, rl2GeometryPtr geom)
  2692   2792   {
  2693   2793   /* placing each character along the modelling line */
  2694   2794       double x0;
................................................................................
  2699   2799       double m;
  2700   2800       double rads;
  2701   2801       double angle;
  2702   2802       char buf[2];
  2703   2803       rl2GeometryPtr g2;
  2704   2804       rl2GeometryPtr g = rl2_clone_curve (geom);
  2705   2805       rl2GeometryPtr circle;
         2806  +    char *rev_text = NULL;
  2706   2807       const char *c = text;
  2707   2808       cairo_font_extents_t extents;
  2708   2809   
  2709   2810       cairo_font_extents (cairo, &extents);
  2710   2811       radius =
  2711   2812   	sqrt ((extents.max_x_advance * extents.max_x_advance) +
  2712   2813   	      (extents.height * extents.height)) / 2.0;
         2814  +    if (check_reverse (g))
         2815  +      {
         2816  +	  /* reverse text */
         2817  +	  int len = strlen (text);
         2818  +	  rev_text = malloc (len + 1);
         2819  +	  reverse_text (text, rev_text, len);
         2820  +	  c = rev_text;
         2821  +      }
  2713   2822       while (*c != '\0' && g != NULL)
  2714   2823         {
  2715   2824   	  buf[0] = *c;
  2716   2825   	  buf[1] = '\0';
  2717   2826   	  get_aux_start_point (g, &x0, &y0);
  2718   2827   	  circle = rl2_build_circle (x0, y0, radius);
  2719   2828   	  if (!get_aux_interception_point (handle, g, circle, &x1, &y1))
................................................................................
  2722   2831   		rl2_destroy_geometry (g);
  2723   2832   		g = NULL;
  2724   2833   		break;
  2725   2834   	    }
  2726   2835   	  m = (y1 - y0) / (x1 - x0);
  2727   2836   	  rads = atan (m);
  2728   2837   	  angle = rads / .0174532925199432958;
  2729         -	  if (x1 < x0)
         2838  +	  if (x1 < x0 && rev_text == NULL)
  2730   2839   	      angle += 180.0;
  2731   2840   	  rl2_graph_draw_text (context, buf, x0, y0, angle, 0.5, 0.5);
  2732   2841   	  c++;
  2733   2842   	  g2 = aux_reduce_curve (handle, g, circle, x0, y0);
  2734   2843   	  rl2_destroy_geometry (circle);
  2735   2844   	  rl2_destroy_geometry (g);
  2736   2845   	  g = g2;
  2737   2846         }
         2847  +    if (rev_text)
         2848  +	free (rev_text);
  2738   2849       return g;
  2739   2850   }
  2740   2851   
  2741   2852   RL2_DECLARE int
  2742   2853   rl2_graph_draw_warped_text (sqlite3 * handle, rl2GraphicsContextPtr context,
  2743         -			    const char *text, int points, double *x, double *y,
  2744         -			    double initial_gap, double gap, int repeated)
         2854  +			    const char *text, int points, double *x,
         2855  +			    double *y, double initial_gap, double gap,
         2856  +			    int repeated)
  2745   2857   {
  2746   2858   /* drawing a text string warped along a modelling curve (using the current font) */
  2747   2859       double curve_len;
  2748   2860       double text_len;
  2749   2861       double extra_len;
  2750   2862       double start;
  2751   2863       double from;
  2752   2864       rl2GeometryPtr geom = NULL;
  2753   2865       rl2GeometryPtr geom2 = NULL;
         2866  +    rl2GeometryPtr geom3 = NULL;
  2754   2867       cairo_t *cairo;
  2755   2868       RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
  2756   2869   
  2757   2870       if (ctx == NULL)
  2758   2871   	return 0;
  2759   2872       if (text == NULL)
  2760   2873   	return 0;
................................................................................
  2765   2878   
  2766   2879       geom = rl2_curve_from_XY (points, x, y);
  2767   2880       if (geom == NULL)
  2768   2881   	return 0;
  2769   2882   
  2770   2883       curve_len = rl2_compute_curve_length (geom);
  2771   2884       do_estimate_text_length (cairo, text, &text_len, &extra_len);
  2772         -    if ((text_len + (2.0 * extra_len)) > curve_len)
         2885  +    if ((initial_gap + text_len + (2.0 * extra_len)) > curve_len)
  2773   2886   	return 0;		/* not enough room to place the label */
  2774   2887   
  2775   2888       if (repeated)
  2776   2889         {
  2777   2890   	  /* repeated labels */
  2778   2891   	  int first = 1;
  2779         -	  rl2GeometryPtr geom3 = rl2_clone_linestring (geom->first_linestring);
         2892  +	  geom3 = rl2_clone_linestring (geom->first_linestring);
  2780   2893   	  while (geom3 != NULL)
  2781   2894   	    {
  2782   2895   		if (first)
  2783   2896   		  {
  2784   2897   		      start = initial_gap + extra_len;
  2785   2898   		      first = 0;
  2786   2899   		  }
  2787   2900   		else
  2788   2901   		    start = gap + extra_len;
  2789   2902   		curve_len = rl2_compute_curve_length (geom3);
         2903  +		if ((start + text_len + extra_len) > curve_len)
         2904  +		    break;	/* not enough room to place the label */
  2790   2905   		from = start / curve_len;
  2791   2906   		/* extracting the sub-path modelling the label */
  2792   2907   		geom2 = rl2_curve_substring (handle, geom3, from, 1.0);
  2793   2908   		rl2_destroy_geometry (geom3);
  2794   2909   		if (geom2 == NULL)
  2795   2910   		    goto error;
  2796   2911   		geom3 =
................................................................................
  2804   2919   	  /* single label */
  2805   2920   	  start = (curve_len - text_len) / 2.0;
  2806   2921   	  from = start / curve_len;
  2807   2922   	  /* extracting the sub-path modelling the label */
  2808   2923   	  geom2 = rl2_curve_substring (handle, geom, from, 1.0);
  2809   2924   	  if (geom2 == NULL)
  2810   2925   	      goto error;
  2811         -	  rl2_draw_wrapped_label (handle, context, cairo, text, geom2);
         2926  +	  geom3 = rl2_draw_wrapped_label (handle, context, cairo, text, geom2);
  2812   2927   	  rl2_destroy_geometry (geom2);
         2928  +	  rl2_destroy_geometry (geom3);
  2813   2929         }
  2814   2930   
  2815   2931       rl2_destroy_geometry (geom);
  2816   2932       return 1;
  2817   2933   
  2818   2934     error:
  2819   2935       rl2_destroy_geometry (geom);
................................................................................
  2887   3003       cairo_scale (cairo, scale_x, scale_y);
  2888   3004       cairo_set_source (cairo, bmp->pattern);
  2889   3005       cairo_paint (cairo);
  2890   3006       cairo_restore (cairo);
  2891   3007       cairo_surface_flush (surface);
  2892   3008       return 1;
  2893   3009   }
         3010  +
         3011  +RL2_DECLARE int
         3012  +rl2_rescale_pixbuf (const unsigned char *inbuf, unsigned int inwidth,
         3013  +		    unsigned int inheight, unsigned char pixtype,
         3014  +		    const unsigned char *outbuf, unsigned int outwidth,
         3015  +		    unsigned int outheight)
         3016  +{
         3017  +/* drawing a rescaled pixbufx (RGB or GRAYSCALE) */
         3018  +    unsigned char *pixbuf = NULL;
         3019  +    int bufsz;
         3020  +    const unsigned char *p_in;
         3021  +    unsigned char *p_out;
         3022  +    unsigned int x;
         3023  +    unsigned int y;
         3024  +    int stride;
         3025  +    double scale_x = (double) outwidth / (double) inwidth;
         3026  +    double scale_y = (double) outheight / (double) inheight;
         3027  +    int little_endian = rl2cr_endian_arch ();
         3028  +    cairo_t *cairo;
         3029  +    cairo_surface_t *surface;
         3030  +    cairo_surface_t *bitmap;
         3031  +    cairo_pattern_t *pattern;
         3032  +    if (pixtype != RL2_PIXEL_RGB && pixtype != RL2_PIXEL_GRAYSCALE)
         3033  +	return 0;
         3034  +
         3035  +/* creating a Cairo context */
         3036  +    surface =
         3037  +	cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outwidth, outheight);
         3038  +    if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS)
         3039  +	;
         3040  +    else
         3041  +	goto error1;
         3042  +    cairo = cairo_create (surface);
         3043  +    if (cairo_status (cairo) == CAIRO_STATUS_NO_MEMORY)
         3044  +	goto error2;
         3045  +
         3046  +/* allocating and populating data for Cairo */
         3047  +    stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, inwidth);
         3048  +    bufsz = stride * inheight;
         3049  +    pixbuf = malloc (bufsz);
         3050  +    if (pixbuf == NULL)
         3051  +      {
         3052  +	  goto error2;
         3053  +      }
         3054  +    p_in = inbuf;
         3055  +    p_out = pixbuf;
         3056  +    for (y = 0; y < inheight; y++)
         3057  +      {
         3058  +	  for (x = 0; x < inwidth; x++)
         3059  +	    {
         3060  +		unsigned char r;
         3061  +		unsigned char g;
         3062  +		unsigned char b;
         3063  +		if (pixtype == RL2_PIXEL_RGB)
         3064  +		  {
         3065  +		      r = *p_in++;
         3066  +		      g = *p_in++;
         3067  +		      b = *p_in++;
         3068  +		  }
         3069  +		else
         3070  +		  {
         3071  +		      r = *p_in++;
         3072  +		      g = r;
         3073  +		      b = r;
         3074  +		  }
         3075  +		if (little_endian)
         3076  +		  {
         3077  +		      *p_out++ = b;
         3078  +		      *p_out++ = g;
         3079  +		      *p_out++ = r;
         3080  +		      *p_out++ = 0xff;
         3081  +		  }
         3082  +		else
         3083  +		  {
         3084  +		      *p_out++ = 0xff;
         3085  +		      *p_out++ = r;
         3086  +		      *p_out++ = g;
         3087  +		      *p_out++ = b;
         3088  +		  }
         3089  +	    }
         3090  +      }
         3091  +
         3092  +/* creating the input pattern */
         3093  +    bitmap =
         3094  +	cairo_image_surface_create_for_data (pixbuf, CAIRO_FORMAT_ARGB32,
         3095  +					     inwidth, inheight, stride);
         3096  +    pattern = cairo_pattern_create_for_surface (bitmap);
         3097  +    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
         3098  +
         3099  +/* rescaling the image */
         3100  +    cairo_save (cairo);
         3101  +    cairo_scale (cairo, scale_x, scale_y);
         3102  +    cairo_set_source (cairo, pattern);
         3103  +    cairo_paint (cairo);
         3104  +    cairo_restore (cairo);
         3105  +    cairo_surface_flush (surface);
         3106  +
         3107  +/* cleaning up the input pattern */
         3108  +    cairo_pattern_destroy (pattern);
         3109  +    cairo_surface_destroy (bitmap);
         3110  +    free (pixbuf);
         3111  +
         3112  +/* exporting the rescaled image */
         3113  +    p_in = cairo_image_surface_get_data (surface);
         3114  +    p_out = (unsigned char *) outbuf;
         3115  +    for (y = 0; y < outheight; y++)
         3116  +      {
         3117  +	  for (x = 0; x < outwidth; x++)
         3118  +	    {
         3119  +		unsigned char r;
         3120  +		unsigned char g;
         3121  +		unsigned char b;
         3122  +		unsigned char a;
         3123  +		if (little_endian)
         3124  +		  {
         3125  +		      b = *p_in++;
         3126  +		      g = *p_in++;
         3127  +		      r = *p_in++;
         3128  +		      a = *p_in++;
         3129  +		  }
         3130  +		else
         3131  +		  {
         3132  +		      a = *p_in++;
         3133  +		      r = *p_in++;
         3134  +		      g = *p_in++;
         3135  +		      b = *p_in++;
         3136  +		  }
         3137  +		if (pixtype == RL2_PIXEL_RGB)
         3138  +		  {
         3139  +		      *p_out++ = unpremultiply (r, a);
         3140  +		      *p_out++ = unpremultiply (g, a);
         3141  +		      *p_out++ = unpremultiply (b, a);
         3142  +
         3143  +		  }
         3144  +		else
         3145  +		    *p_out++ = unpremultiply (r, a);
         3146  +	    }
         3147  +      }
         3148  +
         3149  +/* destroying the Cairo context */
         3150  +    cairo_destroy (cairo);
         3151  +    cairo_surface_destroy (surface);
         3152  +    return 1;
         3153  +
         3154  +  error2:
         3155  +    if (pixbuf != NULL)
         3156  +	free (pixbuf);
         3157  +    cairo_destroy (cairo);
         3158  +    cairo_surface_destroy (surface);
         3159  +    return 0;
         3160  +  error1:
         3161  +    cairo_surface_destroy (surface);
         3162  +    return 0;
         3163  +}
  2894   3164   
  2895   3165   RL2_DECLARE int
  2896   3166   rl2_graph_draw_graphic_symbol (rl2GraphicsContextPtr context,
  2897   3167   			       rl2GraphicsPatternPtr symbol, double width,
  2898   3168   			       double height, double x,
  2899   3169   			       double y, double angle,
  2900   3170   			       double anchor_point_x, double anchor_point_y)
................................................................................
  3119   3389         }
  3120   3390       cairo_restore (cairo);
  3121   3391       cairo_surface_flush (surface);
  3122   3392   
  3123   3393       return 1;
  3124   3394   }
  3125   3395   
  3126         -static unsigned char
  3127         -unpremultiply (unsigned char c, unsigned char a)
  3128         -{
  3129         -/* Cairo has premultiplied alphas */
  3130         -    double x = ((double) c * 255.0) / (double) a;
  3131         -    if (a == 0)
  3132         -	return 0;
  3133         -    return (unsigned char) x;
  3134         -}
  3135         -
  3136   3396   RL2_DECLARE unsigned char *
  3137   3397   rl2_graph_get_context_rgb_array (rl2GraphicsContextPtr context)
  3138   3398   {
  3139   3399   /* creating an RGB buffer from the given Context */
  3140   3400       int width;
  3141   3401       int height;
  3142   3402       int x;

Changes to src/rl2png.c.

   224    224   	rl2_free (green);
   225    225       if (blue != NULL)
   226    226   	rl2_free (blue);
   227    227       return RL2_ERROR;
   228    228   }
   229    229   
   230    230   static int
   231         -compress_grayscale_png8 (const unsigned char *pixels, const unsigned char *mask,
   232         -			 double opacity, unsigned int width,
   233         -			 unsigned int height, unsigned char sample_type,
   234         -			 unsigned char pixel_type, unsigned char **png,
   235         -			 int *png_size)
          231  +compress_grayscale_png8 (const unsigned char *pixels,
          232  +			 const unsigned char *mask, double opacity,
          233  +			 unsigned int width, unsigned int height,
          234  +			 unsigned char sample_type, unsigned char pixel_type,
          235  +			 unsigned char **png, int *png_size)
   236    236   {
   237    237   /* compressing a PNG image of the GRAYSCALE type - 8 bits */
   238    238       png_structp png_ptr;
   239    239       png_infop info_ptr;
   240    240       int bit_depth;
   241    241       png_bytep *row_pointers = NULL;
   242    242       png_bytep p_out;
................................................................................
  1080   1080       *png = blob;
  1081   1081       *png_size = blob_size;
  1082   1082       return RL2_OK;
  1083   1083   }
  1084   1084   
  1085   1085   RL2_DECLARE int
  1086   1086   rl2_rgb_real_alpha_to_png (unsigned int width, unsigned int height,
  1087         -			   const unsigned char *rgb, const unsigned char *alpha,
  1088         -			   unsigned char **png, int *png_size)
         1087  +			   const unsigned char *rgb,
         1088  +			   const unsigned char *alpha, unsigned char **png,
         1089  +			   int *png_size)
  1089   1090   {
  1090   1091   /* creating a PNG image from two distinct RGB + Alpha buffer */
  1091   1092       unsigned char *blob;
  1092   1093       int blob_size;
  1093   1094       if (rgb == NULL || alpha == NULL)
  1094   1095   	return RL2_ERROR;
  1095   1096   
................................................................................
  1171   1172         case RL2_PIXEL_DATAGRID:
  1172   1173   	  if (sample_type == RL2_SAMPLE_UINT16)
  1173   1174   	      ret =
  1174   1175   		  compress_grayscale_png16 (pixels, width, height,
  1175   1176   					    sample_type, &blob, &blob_size);
  1176   1177   	  else
  1177   1178   	      ret =
  1178         -		  compress_grayscale_png8 (pixels, mask, opacity, width, height,
  1179         -					   sample_type, pixel_type, &blob,
  1180         -					   &blob_size);
         1179  +		  compress_grayscale_png8 (pixels, mask, opacity, width,
         1180  +					   height, sample_type, pixel_type,
         1181  +					   &blob, &blob_size);
  1181   1182   	  break;
  1182   1183         case RL2_PIXEL_RGB:
  1183   1184   	  if (sample_type == RL2_SAMPLE_UINT8)
  1184   1185   	      ret =
  1185   1186   		  compress_rgb_png8 (pixels, mask, opacity, width, height,
  1186   1187   				     &blob, &blob_size);
  1187   1188   	  else if (sample_type == RL2_SAMPLE_UINT16)
................................................................................
  1189   1190   		  compress_rgb_png16 (pixels, width, height, &blob, &blob_size);
  1190   1191   	  break;
  1191   1192         case RL2_PIXEL_MULTIBAND:
  1192   1193   	  if (sample_type == RL2_SAMPLE_UINT8)
  1193   1194   	    {
  1194   1195   		if (num_bands == 3)
  1195   1196   		    ret =
  1196         -			compress_rgb_png8 (pixels, mask, opacity, width, height,
  1197         -					   &blob, &blob_size);
         1197  +			compress_rgb_png8 (pixels, mask, opacity, width,
         1198  +					   height, &blob, &blob_size);
  1198   1199   		else if (num_bands == 4)
  1199   1200   		    ret =
  1200   1201   			compress_4bands_png8 (pixels, width, height, &blob,
  1201   1202   					      &blob_size);
  1202   1203   	    }
  1203   1204   	  else if (sample_type == RL2_SAMPLE_UINT16)
  1204   1205   	    {
................................................................................
  1411   1412   	  if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  1412   1413   	      nBands = 4;
  1413   1414         }
  1414   1415       if (*xpixel_type == RL2_PIXEL_DATAGRID)
  1415   1416   	pixel_type = RL2_PIXEL_DATAGRID;
  1416   1417       if (pixel_type == RL2_PIXEL_PALETTE)
  1417   1418         {
  1418         -	  if (png_get_tRNS (png_ptr, info_ptr, &transp, &nTransp, &transpValues)
  1419         -	      == PNG_INFO_tRNS)
         1419  +	  if (png_get_tRNS
         1420  +	      (png_ptr, info_ptr, &transp, &nTransp,
         1421  +	       &transpValues) == PNG_INFO_tRNS)
  1420   1422   	    {
  1421   1423   		/* a Transparency palette is defined */
  1422   1424   		int i;
  1423   1425   		for (i = 0; i < nTransp; i++)
  1424   1426   		    *(alpha + i) = *(transp + i);
  1425   1427   		has_alpha = 1;
  1426   1428   	    }

Changes to src/rl2pyramid.c.

   255    255   #endif
   256    256   
   257    257       table = sqlite3_mprintf ("%s_tiles", coverage);
   258    258       xtable = rl2_double_quoted_sql (table);
   259    259       sqlite3_free (table);
   260    260       sql =
   261    261   	sqlite3_mprintf ("SELECT Count(*) FROM \"%s\" "
   262         -			 "WHERE section_id = %s AND pyramid_level > 0", xtable,
   263         -			 sect_id);
          262  +			 "WHERE section_id = %s AND pyramid_level > 0",
          263  +			 xtable, sect_id);
   264    264       free (xtable);
   265    265       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
   266    266       sqlite3_free (sql);
   267    267       if (ret != SQLITE_OK)
   268    268   	return 1;
   269    269       while (1)
   270    270         {
................................................................................
   347    347         }
   348    348       sqlite3_finalize (stmt);
   349    349       stmt = NULL;
   350    350       if (!ok)
   351    351   	goto error;
   352    352   
   353    353   /* Coverage's palette and no-data */
   354         -    sql = sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages "
   355         -			   "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
          354  +    sql =
          355  +	sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages "
          356  +			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
   356    357       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
   357    358       sqlite3_free (sql);
   358    359       if (ret != SQLITE_OK)
   359    360         {
   360    361   	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
   361    362   	  goto error;
   362    363         }
................................................................................
   487    488   	  free (tile_in);
   488    489   	  tile_in = tile_in_n;
   489    490         }
   490    491       free (pyr);
   491    492   }
   492    493   
   493    494   static int
   494         -insert_tile_into_section_pyramid (SectionPyramidPtr pyr, sqlite3_int64 tile_id,
   495         -				  double minx, double miny, double maxx,
   496         -				  double maxy)
          495  +insert_tile_into_section_pyramid (SectionPyramidPtr pyr,
          496  +				  sqlite3_int64 tile_id, double minx,
          497  +				  double miny, double maxx, double maxy)
   497    498   {
   498    499   /* inserting a base tile into the Pyramid level */
   499    500       SectionPyramidTileInPtr tile;
   500    501       if (pyr == NULL)
   501    502   	return 0;
   502    503       tile = alloc_section_pyramid_tile (tile_id, minx, miny, maxx, maxy);
   503    504       if (tile == NULL)
................................................................................
   572    573         {
   573    574   	  if (tile->cx > minx && tile->cx < maxx && tile->cy > miny
   574    575   	      && tile->cy < maxy)
   575    576   	    {
   576    577   		if (first)
   577    578   		  {
   578    579   		      out =
   579         -			  add_pyramid_out_tile (pyr, row, col, minx, miny, maxx,
   580         -						maxy);
          580  +			  add_pyramid_out_tile (pyr, row, col, minx, miny,
          581  +						maxx, maxy);
   581    582   		      first = 0;
   582    583   		  }
   583    584   		if (out != NULL)
   584    585   		    add_pyramid_sub_tile (out, tile);
   585    586   	    }
   586    587   	  tile = tile->next;
   587    588         }
................................................................................
   763    764   	  for (col = 0; col < (unsigned int) tic_x; col++)
   764    765   	    {
   765    766   		unsigned int xx = col + x;
   766    767   		char *p_out = p_out_base + xx;
   767    768   		if (xx >= tileWidth)
   768    769   		    break;
   769    770   		*p_out =
   770         -		    rescale_pixel_int8 (buf_in, tileWidth, tileHeight, col * 8,
   771         -					row * 8, nd);
          771  +		    rescale_pixel_int8 (buf_in, tileWidth, tileHeight,
          772  +					col * 8, row * 8, nd);
   772    773   	    }
   773    774         }
   774    775   }
   775    776   
   776    777   static double
   777    778   rescale_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
   778    779   		     unsigned int tileHeight, int x, int y, unsigned char nd)
................................................................................
   843    844   	  for (col = 0; col < (unsigned int) tic_x; col++)
   844    845   	    {
   845    846   		unsigned int xx = col + x;
   846    847   		unsigned char *p_out = p_out_base + xx;
   847    848   		if (xx >= tileWidth)
   848    849   		    break;
   849    850   		*p_out =
   850         -		    rescale_pixel_uint8 (buf_in, tileWidth, tileHeight, col * 8,
   851         -					 row * 8, nd);
          851  +		    rescale_pixel_uint8 (buf_in, tileWidth, tileHeight,
          852  +					 col * 8, row * 8, nd);
   852    853   	    }
   853    854         }
   854    855   }
   855    856   
   856    857   static double
   857    858   rescale_pixel_int16 (const short *buf_in, unsigned int tileWidth,
   858    859   		     unsigned int tileHeight, int x, int y, short nd)
................................................................................
   923    924   	  for (col = 0; col < (unsigned int) tic_x; col++)
   924    925   	    {
   925    926   		unsigned int xx = col + x;
   926    927   		short *p_out = p_out_base + xx;
   927    928   		if (xx >= tileWidth)
   928    929   		    break;
   929    930   		*p_out =
   930         -		    rescale_pixel_int16 (buf_in, tileWidth, tileHeight, col * 8,
   931         -					 row * 8, nd);
          931  +		    rescale_pixel_int16 (buf_in, tileWidth, tileHeight,
          932  +					 col * 8, row * 8, nd);
   932    933   	    }
   933    934         }
   934    935   }
   935    936   
   936    937   static double
   937    938   rescale_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
   938    939   		      unsigned int tileHeight, int x, int y, unsigned short nd)
................................................................................
  1083   1084   	  for (col = 0; col < (unsigned int) tic_x; col++)
  1084   1085   	    {
  1085   1086   		unsigned int xx = col + x;
  1086   1087   		int *p_out = p_out_base + xx;
  1087   1088   		if (xx >= tileWidth)
  1088   1089   		    break;
  1089   1090   		*p_out =
  1090         -		    rescale_pixel_int32 (buf_in, tileWidth, tileHeight, col * 8,
  1091         -					 row * 8, nd);
         1091  +		    rescale_pixel_int32 (buf_in, tileWidth, tileHeight,
         1092  +					 col * 8, row * 8, nd);
  1092   1093   	    }
  1093   1094         }
  1094   1095   }
  1095   1096   
  1096   1097   static double
  1097   1098   rescale_pixel_uint32 (const unsigned int *buf_in, unsigned int tileWidth,
  1098   1099   		      unsigned int tileHeight, int x, int y, unsigned int nd)
................................................................................
  1243   1244   	  for (col = 0; col < (unsigned int) tic_x; col++)
  1244   1245   	    {
  1245   1246   		unsigned int xx = col + x;
  1246   1247   		float *p_out = p_out_base + xx;
  1247   1248   		if (xx >= tileWidth)
  1248   1249   		    break;
  1249   1250   		*p_out =
  1250         -		    rescale_pixel_float (buf_in, tileWidth, tileHeight, col * 8,
  1251         -					 row * 8, nd);
         1251  +		    rescale_pixel_float (buf_in, tileWidth, tileHeight,
         1252  +					 col * 8, row * 8, nd);
  1252   1253   	    }
  1253   1254         }
  1254   1255   }
  1255   1256   
  1256   1257   static double
  1257   1258   rescale_pixel_double (const double *buf_in, unsigned int tileWidth,
  1258   1259   		      unsigned int tileHeight, int x, int y, double nd)
................................................................................
  1344   1345         {
  1345   1346         case RL2_SAMPLE_INT8:
  1346   1347   	  rescale_grid_int8 ((char *) buf_out, tileWidth, tileHeight,
  1347   1348   			     (const char *) buf_in, x, y, tic_x, tic_y,
  1348   1349   			     no_data);
  1349   1350   	  break;
  1350   1351         case RL2_SAMPLE_UINT8:
  1351         -	  rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth, tileHeight,
  1352         -			      (const unsigned char *) buf_in, x, y, tic_x,
  1353         -			      tic_y, no_data);
         1352  +	  rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth,
         1353  +			      tileHeight, (const unsigned char *) buf_in, x,
         1354  +			      y, tic_x, tic_y, no_data);
  1354   1355   	  break;
  1355   1356         case RL2_SAMPLE_INT16:
  1356   1357   	  rescale_grid_int16 ((short *) buf_out, tileWidth, tileHeight,
  1357   1358   			      (const short *) buf_in, x, y, tic_x, tic_y,
  1358   1359   			      no_data);
  1359   1360   	  break;
  1360   1361         case RL2_SAMPLE_UINT16:
................................................................................
  1364   1365   	  break;
  1365   1366         case RL2_SAMPLE_INT32:
  1366   1367   	  rescale_grid_int32 ((int *) buf_out, tileWidth, tileHeight,
  1367   1368   			      (const int *) buf_in, x, y, tic_x, tic_y,
  1368   1369   			      no_data);
  1369   1370   	  break;
  1370   1371         case RL2_SAMPLE_UINT32:
  1371         -	  rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth, tileHeight,
  1372         -			       (const unsigned int *) buf_in, x, y, tic_x,
  1373         -			       tic_y, no_data);
         1372  +	  rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth,
         1373  +			       tileHeight, (const unsigned int *) buf_in, x,
         1374  +			       y, tic_x, tic_y, no_data);
  1374   1375   	  break;
  1375   1376         case RL2_SAMPLE_FLOAT:
  1376   1377   	  rescale_grid_float ((float *) buf_out, tileWidth, tileHeight,
  1377   1378   			      (const float *) buf_in, x, y, tic_x, tic_y,
  1378   1379   			      no_data);
  1379   1380   	  break;
  1380   1381         case RL2_SAMPLE_DOUBLE:
................................................................................
  1515   1516   				  break;
  1516   1517   			      }
  1517   1518   			    pos_x += geo_x;
  1518   1519   			}
  1519   1520   		      pos_y -= geo_y;
  1520   1521   		  }
  1521   1522   		rst = (rl2PrivRasterPtr) raster_in;
  1522         -		rescale_grid (buf_out, tileWidth, tileHeight, rst->rasterBuffer,
  1523         -			      sample_type, x, y, tic_x, tic_y, no_data);
         1523  +		rescale_grid (buf_out, tileWidth, tileHeight,
         1524  +			      rst->rasterBuffer, sample_type, x, y, tic_x,
         1525  +			      tic_y, no_data);
  1524   1526   		rl2_destroy_raster (raster_in);
  1525   1527   		raster_in = NULL;
  1526   1528   		tile_in = tile_in->next;
  1527   1529   	    }
  1528   1530   
  1529   1531   	  raster_out = NULL;
  1530   1532   	  raster_out =
................................................................................
  1546   1548   		goto error;
  1547   1549   	    }
  1548   1550   	  rl2_destroy_raster (raster_out);
  1549   1551   	  raster_out = NULL;
  1550   1552   
  1551   1553   	  /* INSERTing the tile */
  1552   1554   	  if (!do_insert_pyramid_tile
  1553         -	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
  1554         -	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
  1555         -	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))
         1555  +	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
         1556  +	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
         1557  +	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
         1558  +	       stmt_data))
  1556   1559   	      goto error;
  1557   1560   
  1558   1561   	  tile_out = tile_out->next;
  1559   1562         }
  1560   1563   
  1561   1564       return 1;
  1562   1565   
................................................................................
  1570   1573       if (mask != NULL)
  1571   1574   	free (mask);
  1572   1575       return 0;
  1573   1576   }
  1574   1577   
  1575   1578   static double
  1576   1579   rescale_mb_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
  1577         -			unsigned int tileHeight, unsigned int x, unsigned int y,
  1578         -			unsigned char nd, unsigned char nb,
         1580  +			unsigned int tileHeight, unsigned int x,
         1581  +			unsigned int y, unsigned char nd, unsigned char nb,
  1579   1582   			unsigned char num_bands)
  1580   1583   {
  1581   1584   /* rescaling a MultiBand pixel sample (8x8) - UINT8 */
  1582   1585       unsigned int row;
  1583   1586       unsigned int col;
  1584   1587       int nodata = 0;
  1585   1588       int valid = 0;
................................................................................
  1648   1651   				&& pxl->nBands == num_bands)
  1649   1652   			      {
  1650   1653   				  rl2PrivSamplePtr sample = pxl->Samples + nb;
  1651   1654   				  nd = sample->uint8;
  1652   1655   			      }
  1653   1656   			}
  1654   1657   		      *(p_out + nb) =
  1655         -			  rescale_mb_pixel_uint8 (buf_in, tileWidth, tileHeight,
  1656         -						  col * 8, row * 8, nd, nb,
  1657         -						  num_bands);
         1658  +			  rescale_mb_pixel_uint8 (buf_in, tileWidth,
         1659  +						  tileHeight, col * 8,
         1660  +						  row * 8, nd, nb, num_bands);
  1658   1661   		  }
  1659   1662   	    }
  1660   1663         }
  1661   1664   }
  1662   1665   
  1663   1666   static double
  1664   1667   rescale_mb_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
................................................................................
  1738   1741   			      {
  1739   1742   				  rl2PrivSamplePtr sample = pxl->Samples + nb;
  1740   1743   				  nd = sample->uint16;
  1741   1744   			      }
  1742   1745   			}
  1743   1746   		      *(p_out + nb) =
  1744   1747   			  rescale_mb_pixel_uint16 (buf_in, tileWidth,
  1745         -						   tileHeight, col * 8, row * 8,
  1746         -						   nd, nb, num_bands);
         1748  +						   tileHeight, col * 8,
         1749  +						   row * 8, nd, nb, num_bands);
  1747   1750   		  }
  1748   1751   	    }
  1749   1752         }
  1750   1753   }
  1751   1754   
  1752   1755   static void
  1753   1756   rescale_multiband (void *buf_out, unsigned int tileWidth,
................................................................................
  1762   1765         case RL2_SAMPLE_UINT8:
  1763   1766   	  rescale_multiband_uint8 ((unsigned char *) buf_out, tileWidth,
  1764   1767   				   tileHeight, (const unsigned char *) buf_in,
  1765   1768   				   x, y, tic_x, tic_y, num_bands, no_data);
  1766   1769   	  break;
  1767   1770         case RL2_SAMPLE_UINT16:
  1768   1771   	  rescale_multiband_uint16 ((unsigned short *) buf_out, tileWidth,
  1769         -				    tileHeight, (const unsigned short *) buf_in,
  1770         -				    x, y, tic_x, tic_y, num_bands, no_data);
         1772  +				    tileHeight,
         1773  +				    (const unsigned short *) buf_in, x, y,
         1774  +				    tic_x, tic_y, num_bands, no_data);
  1771   1775   	  break;
  1772   1776         };
  1773   1777   }
  1774   1778   
  1775   1779   static int
  1776   1780   update_sect_pyramid_multiband (sqlite3 * handle, sqlite3_stmt * stmt_rd,
  1777   1781   			       sqlite3_stmt * stmt_tils,
................................................................................
  1896   1900   			      }
  1897   1901   			    pos_x += geo_x;
  1898   1902   			}
  1899   1903   		      pos_y -= geo_y;
  1900   1904   		  }
  1901   1905   		rst = (rl2PrivRasterPtr) raster_in;
  1902   1906   		rescale_multiband (buf_out, tileWidth, tileHeight,
  1903         -				   rst->rasterBuffer, sample_type, num_bands, x,
  1904         -				   y, tic_x, tic_y, no_data);
         1907  +				   rst->rasterBuffer, sample_type, num_bands,
         1908  +				   x, y, tic_x, tic_y, no_data);
  1905   1909   		rl2_destroy_raster (raster_in);
  1906   1910   		raster_in = NULL;
  1907   1911   		tile_in = tile_in->next;
  1908   1912   	    }
  1909   1913   
  1910   1914   	  raster_out = NULL;
  1911   1915   	  raster_out =
................................................................................
  1927   1931   		goto error;
  1928   1932   	    }
  1929   1933   	  rl2_destroy_raster (raster_out);
  1930   1934   	  raster_out = NULL;
  1931   1935   
  1932   1936   	  /* INSERTing the tile */
  1933   1937   	  if (!do_insert_pyramid_tile
  1934         -	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
  1935         -	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
  1936         -	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))
         1938  +	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
         1939  +	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
         1940  +	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
         1941  +	       stmt_data))
  1937   1942   	      goto error;
  1938   1943   
  1939   1944   	  tile_out = tile_out->next;
  1940   1945         }
  1941   1946   
  1942   1947       return 1;
  1943   1948   
................................................................................
  2118   2123   							    0);
  2119   2124   			}
  2120   2125   		      compression = RL2_COMPRESSION_PNG;
  2121   2126   		  }
  2122   2127   		else
  2123   2128   		    nd = rl2_clone_pixel (no_data);
  2124   2129   		raster =
  2125         -		    rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8,
  2126         -				       RL2_PIXEL_GRAYSCALE, 1, gray,
  2127         -				       tileWidth * tileHeight, NULL, alpha,
  2128         -				       tileWidth * tileHeight, nd);
         2130  +		    rl2_create_raster (tileWidth, tileHeight,
         2131  +				       RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
         2132  +				       1, gray, tileWidth * tileHeight, NULL,
         2133  +				       alpha, tileWidth * tileHeight, nd);
  2129   2134   	    }
  2130   2135   	  else if (pyr->pixel_type == RL2_PIXEL_RGB)
  2131   2136   	    {
  2132   2137   		/* RGB Pyramid */
  2133   2138   		nd = rl2_clone_pixel (no_data);
  2134   2139   		raster =
  2135         -		    rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8,
  2136         -				       RL2_PIXEL_RGB, 3, rgb,
  2137         -				       tileWidth * tileHeight * 3, NULL, alpha,
  2138         -				       tileWidth * tileHeight, nd);
         2140  +		    rl2_create_raster (tileWidth, tileHeight,
         2141  +				       RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3,
         2142  +				       rgb, tileWidth * tileHeight * 3, NULL,
         2143  +				       alpha, tileWidth * tileHeight, nd);
  2139   2144   	    }
  2140   2145   	  if (raster == NULL)
  2141   2146   	    {
  2142   2147   		fprintf (stderr, "ERROR: unable to create a Pyramid Tile\n");
  2143   2148   		goto error;
  2144   2149   	    }
  2145   2150   	  if (rl2_raster_encode
................................................................................
  2152   2157   	  rl2_destroy_raster (raster);
  2153   2158   	  raster = NULL;
  2154   2159   	  rl2_graph_destroy_context (ctx);
  2155   2160   	  ctx = NULL;
  2156   2161   
  2157   2162   	  /* INSERTing the tile */
  2158   2163   	  if (!do_insert_pyramid_tile
  2159         -	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
  2160         -	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
  2161         -	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))
         2164  +	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
         2165  +	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
         2166  +	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
         2167  +	       stmt_data))
  2162   2168   	      goto error;
  2163   2169   
  2164   2170   	  tile_out = tile_out->next;
  2165   2171         }
  2166   2172   
  2167   2173       return 1;
  2168   2174   
................................................................................
  2340   2346   	rl2_graph_destroy_context (ctx);
  2341   2347       return 0;
  2342   2348   }
  2343   2349   
  2344   2350   #define floor2(exp) ((long) exp)
  2345   2351   
  2346   2352   static rl2RasterPtr
  2347         -create_124_rescaled_raster (const unsigned char *rgba, unsigned char pixel_type,
  2348         -			    unsigned int tileWidth, unsigned int tileHeight,
  2349         -			    int scale)
         2353  +create_124_rescaled_raster (const unsigned char *rgba,
         2354  +			    unsigned char pixel_type, unsigned int tileWidth,
         2355  +			    unsigned int tileHeight, int scale)
  2350   2356   {
  2351   2357   /* creating a rescaled raster (1,2 or 4 bit pyramids) 
  2352   2358   /
  2353   2359   / this function builds an high quality rescaled sub-image by applying pixel interpolation
  2354   2360   /
  2355   2361   / this code is widely inspired by the original GD gdImageCopyResampled() function
  2356   2362   */
................................................................................
  2529   2535   			    *p_msk = 1;
  2530   2536   			}
  2531   2537   		  }
  2532   2538   	    }
  2533   2539         }
  2534   2540   
  2535   2541       raster =
  2536         -	rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8, pixel_type,
  2537         -			   num_bands, rgb, rgb_sz, NULL, mask, mask_sz, NULL);
         2542  +	rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8,
         2543  +			   pixel_type, num_bands, rgb, rgb_sz, NULL, mask,
         2544  +			   mask_sz, NULL);
  2538   2545       return raster;
  2539   2546   }
  2540   2547   
  2541   2548   static void
  2542   2549   copy_124_rescaled (rl2RasterPtr raster_out, rl2RasterPtr raster_in,
  2543   2550   		   unsigned int base_x, unsigned int base_y)
  2544   2551   {
................................................................................
  2740   2747   		double tile_x = sqlite3_column_double (stmt_geo, 1);
  2741   2748   		double tile_y = sqlite3_column_double (stmt_geo, 2);
  2742   2749   
  2743   2750   		rgba = load_tile_base (stmt_data, tile_id, palette, no_data);
  2744   2751   		if (rgba == NULL)
  2745   2752   		    goto error;
  2746   2753   		base_tile =
  2747         -		    create_124_rescaled_raster (rgba, out_pixel_type, tileWidth,
  2748         -						tileHeight, factor);
         2754  +		    create_124_rescaled_raster (rgba, out_pixel_type,
         2755  +						tileWidth, tileHeight, factor);
  2749   2756   		free (rgba);
  2750   2757   		if (base_tile == NULL)
  2751   2758   		    goto error;
  2752   2759   		shift_x = tile_x - minx;
  2753   2760   		shift_y = maxy - tile_y;
  2754   2761   		x = (int) (shift_x / res_x);
  2755   2762   		y = (int) (shift_y / res_y);
................................................................................
  3115   3122       for (ib = 0; ib < num_bands; ib++)
  3116   3123   	*p_out++ = (unsigned char) (*(sum + ib) / (double) valid);
  3117   3124       free (sum);
  3118   3125       *p_msk = 1;
  3119   3126   }
  3120   3127   
  3121   3128   static void
  3122         -mb_prime_nodata_u8 (unsigned char *buf, unsigned int width, unsigned int height,
  3123         -		    unsigned char num_bands, rl2PixelPtr no_data)
         3129  +mb_prime_nodata_u8 (unsigned char *buf, unsigned int width,
         3130  +		    unsigned int height, unsigned char num_bands,
         3131  +		    rl2PixelPtr no_data)
  3124   3132   {
  3125   3133   /* priming a void buffer */
  3126   3134       rl2PrivPixelPtr nd = (rl2PrivPixelPtr) no_data;
  3127   3135       unsigned int x;
  3128   3136       unsigned int y;
  3129   3137       unsigned char ib;
  3130   3138       unsigned char *p = buf;
................................................................................
  3244   3252   					    (unsigned char *) buf_in, mask_in,
  3245   3253   					    (unsigned char *) buf, mask, x, y,
  3246   3254   					    ox, oy, no_data);
  3247   3255   		      break;
  3248   3256   		  case RL2_SAMPLE_UINT16:
  3249   3257   		      rescale_multiband_u16 (tileWidth, tileHeight, num_bands,
  3250   3258   					     out_width, out_height, factor,
  3251         -					     (unsigned short *) buf_in, mask_in,
  3252         -					     (unsigned short *) buf, mask, x, y,
  3253         -					     ox, oy, no_data);
         3259  +					     (unsigned short *) buf_in,
         3260  +					     mask_in, (unsigned short *) buf,
         3261  +					     mask, x, y, ox, oy, no_data);
  3254   3262   		      break;
  3255   3263   		  };
  3256   3264   		ox++;
  3257   3265   	    }
  3258   3266   	  oy++;
  3259   3267         }
  3260   3268   
................................................................................
  4036   4044   					   out_height, factor,
  4037   4045   					   (unsigned char *) buf_in,
  4038   4046   					   (unsigned char *) buf, mask, x, y,
  4039   4047   					   ox, oy, no_data_u8);
  4040   4048   		      break;
  4041   4049   		  case RL2_SAMPLE_INT16:
  4042   4050   		      rescale_datagrid_16 (tileWidth, tileHeight, out_width,
  4043         -					   out_height, factor, (short *) buf_in,
  4044         -					   (short *) buf, mask, x, y, ox, oy,
  4045         -					   no_data_16);
         4051  +					   out_height, factor,
         4052  +					   (short *) buf_in, (short *) buf,
         4053  +					   mask, x, y, ox, oy, no_data_16);
  4046   4054   		      break;
  4047   4055   		  case RL2_SAMPLE_UINT16:
  4048   4056   		      rescale_datagrid_u16 (tileWidth, tileHeight, out_width,
  4049   4057   					    out_height, factor,
  4050   4058   					    (unsigned short *) buf_in,
  4051         -					    (unsigned short *) buf, mask, x, y,
  4052         -					    ox, oy, no_data_u16);
         4059  +					    (unsigned short *) buf, mask, x,
         4060  +					    y, ox, oy, no_data_u16);
  4053   4061   		      break;
  4054   4062   		  case RL2_SAMPLE_INT32:
  4055   4063   		      rescale_datagrid_32 (tileWidth, tileHeight, out_width,
  4056   4064   					   out_height, factor, (int *) buf_in,
  4057   4065   					   (int *) buf, mask, x, y, ox, oy,
  4058   4066   					   no_data_32);
  4059   4067   		      break;
................................................................................
  4089   4097       return raster;
  4090   4098   }
  4091   4099   
  4092   4100   static int
  4093   4101   rescale_monolithic_multiband (int id_level,
  4094   4102   			      unsigned int tileWidth, unsigned int tileHeight,
  4095   4103   			      unsigned char sample_type,
  4096         -			      unsigned char num_bands, int factor, double res_x,
  4097         -			      double res_y, double minx, double miny,
  4098         -			      double maxx, double maxy, unsigned char *buffer,
  4099         -			      int buf_size, unsigned char *mask, int *mask_size,
         4104  +			      unsigned char num_bands, int factor,
         4105  +			      double res_x, double res_y, double minx,
         4106  +			      double miny, double maxx, double maxy,
         4107  +			      unsigned char *buffer, int buf_size,
         4108  +			      unsigned char *mask, int *mask_size,
  4100   4109   			      rl2PixelPtr no_data, sqlite3_stmt * stmt_geo,
  4101   4110   			      sqlite3_stmt * stmt_data)
  4102   4111   {
  4103   4112   /* rescaling monolithic MultiBand */
  4104   4113       rl2RasterPtr raster = NULL;
  4105   4114       rl2RasterPtr base_tile = NULL;
  4106   4115       rl2PrivRasterPtr rst;
................................................................................
  4118   4127       p_out = mask;
  4119   4128       for (y = 0; y < tileHeight; y++)
  4120   4129         {
  4121   4130   	  /* priming full transparency */
  4122   4131   	  for (x = 0; x < tileWidth; x++)
  4123   4132   	      *p_out++ = 0;
  4124   4133         }
  4125         -    rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type, num_bands,
  4126         -			 no_data);
         4134  +    rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type,
         4135  +			 num_bands, no_data);
  4127   4136   /* creating the output raster */
  4128   4137       raster =
  4129   4138   	rl2_create_raster (tileWidth, tileHeight, sample_type,
  4130   4139   			   RL2_PIXEL_MULTIBAND, num_bands, buffer, buf_size,
  4131   4140   			   NULL, mask, *mask_size, nd);
  4132   4141       if (raster == NULL)
  4133   4142   	goto error;
................................................................................
  4329   4338   	  rl2_destroy_raster (raster);
  4330   4339         }
  4331   4340       return 0;
  4332   4341   }
  4333   4342   
  4334   4343   static int
  4335   4344   prepare_section_pyramid_stmts (sqlite3 * handle, const char *coverage,
  4336         -			       int mixed_resolutions, sqlite3_stmt ** xstmt_rd,
         4345  +			       int mixed_resolutions,
         4346  +			       sqlite3_stmt ** xstmt_rd,
  4337   4347   			       sqlite3_stmt ** xstmt_levl,
  4338   4348   			       sqlite3_stmt ** xstmt_tils,
  4339   4349   			       sqlite3_stmt ** xstmt_data)
  4340   4350   {
  4341   4351   /* preparing the section pyramid related SQL statements */
  4342   4352       char *table_tile_data;
  4343   4353       char *xtable_tile_data;
................................................................................
  4500   4510   
  4501   4511       if (!get_section_infos
  4502   4512   	(handle, coverage, section_id, &sect_width, &sect_height, &minx,
  4503   4513   	 &miny, &maxx, &maxy, &palette, &no_data))
  4504   4514   	goto error;
  4505   4515   
  4506   4516       if (!prepare_section_pyramid_stmts
  4507         -	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
  4508         -	 &stmt_data))
         4517  +	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
         4518  +	 &stmt_tils, &stmt_data))
  4509   4519   	goto error;
  4510   4520   
  4511   4521       while (1)
  4512   4522         {
  4513   4523   	  /* looping on pyramid levels */
  4514   4524   	  if (mixed_resolutions)
  4515   4525   	      table_levels = sqlite3_mprintf ("%s_section_levels", coverage);
................................................................................
  4580   4590   		      scale = 8;
  4581   4591   		      if (first)
  4582   4592   			{
  4583   4593   			    pyr =
  4584   4594   				alloc_sect_pyramid (section_id, sect_width,
  4585   4595   						    sect_height, sample_type,
  4586   4596   						    pixel_type, num_samples,
  4587         -						    compression, quality, srid,
  4588         -						    new_res_x, new_res_y,
         4597  +						    compression, quality,
         4598  +						    srid, new_res_x,
         4599  +						    new_res_y,
  4589   4600   						    (double) tileWidth *
  4590   4601   						    new_res_x,
  4591   4602   						    (double) tileHeight *
  4592         -						    new_res_y, minx, miny, maxx,
  4593         -						    maxy, scale);
         4603  +						    new_res_y, minx, miny,
         4604  +						    maxx, maxy, scale);
  4594   4605   			    first = 0;
  4595   4606   			    if (pyr == NULL)
  4596   4607   				goto error;
  4597   4608   			}
  4598   4609   		      if (!insert_tile_into_section_pyramid
  4599   4610   			  (pyr, tile_id, tminx, tminy, tmaxx, tmaxy))
  4600   4611   			  goto error;
................................................................................
  4612   4623   	  if (pyr == NULL)
  4613   4624   	      goto error;
  4614   4625   
  4615   4626   	  out_maxy = maxy;
  4616   4627   	  for (row = 0; row < pyr->scaled_height; row += tileHeight)
  4617   4628   	    {
  4618   4629   		out_miny = out_maxy - pyr->tile_height;
         4630  +		if (out_miny < miny)
         4631  +		    out_miny = miny;
  4619   4632   		out_minx = minx;
  4620   4633   		for (col = 0; col < pyr->scaled_width; col += tileWidth)
  4621   4634   		  {
  4622   4635   		      out_maxx = out_minx + pyr->tile_width;
         4636  +		      if (out_maxx > maxx)
         4637  +			  out_maxx = maxx;
  4623   4638   		      set_pyramid_tile_destination (pyr, out_minx, out_miny,
  4624   4639   						    out_maxx, out_maxy, row,
  4625   4640   						    col);
  4626   4641   		      out_minx += pyr->tile_width;
  4627   4642   		  }
  4628   4643   		out_maxy -= pyr->tile_height;
  4629   4644   	    }
................................................................................
  4954   4969   }
  4955   4970   
  4956   4971   static int
  4957   4972   get_section_raw_raster_data (sqlite3 * handle, int max_threads,
  4958   4973   			     const char *coverage, sqlite3_int64 sect_id,
  4959   4974   			     unsigned int width, unsigned int height,
  4960   4975   			     unsigned char sample_type,
  4961         -			     unsigned char pixel_type, unsigned char num_bands,
  4962         -			     double minx, double maxy, double x_res,
         4976  +			     unsigned char pixel_type,
         4977  +			     unsigned char num_bands, double minx, double miny,
         4978  +			     double maxx, double maxy, double x_res,
  4963   4979   			     double y_res, unsigned char **buffer,
  4964   4980   			     int *buf_size, rl2PalettePtr palette,
  4965   4981   			     rl2PixelPtr no_data)
  4966   4982   {
  4967   4983   /* attempting to return a buffer containing raw pixels from the whole DBMS Section */
  4968   4984       unsigned char *bufpix = NULL;
  4969   4985       int bufpix_size;
................................................................................
  5002   5018   
  5003   5019   /* preparing the "tiles" SQL query */
  5004   5020       xtiles = sqlite3_mprintf ("%s_tiles", coverage);
  5005   5021       xxtiles = rl2_double_quoted_sql (xtiles);
  5006   5022       sql =
  5007   5023   	sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
  5008   5024   			 "FROM \"%s\" "
  5009         -			 "WHERE pyramid_level = 0 AND section_id = ?", xxtiles);
         5025  +			 "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
         5026  +			 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
         5027  +			 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles,
         5028  +			 xtiles);
  5010   5029       sqlite3_free (xtiles);
  5011   5030       free (xxtiles);
  5012   5031       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
  5013   5032       sqlite3_free (sql);
  5014   5033       if (ret != SQLITE_OK)
  5015   5034         {
  5016   5035   	  printf ("SELECT section raw tiles SQL error: %s\n",
................................................................................
  5038   5057       if (pixel_type == RL2_PIXEL_PALETTE)
  5039   5058   	void_raw_buffer_palette (bufpix, width, height, no_data);
  5040   5059       else
  5041   5060   	void_raw_buffer (bufpix, width, height, sample_type, num_bands,
  5042   5061   			 no_data);
  5043   5062       if (!rl2_load_dbms_tiles_section
  5044   5063   	(handle, max_threads, sect_id, stmt_tiles, stmt_data, bufpix, width,
  5045         -	 height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, maxy,
  5046         -	 RL2_SCALE_1, palette, no_data))
         5064  +	 height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, miny,
         5065  +	 maxx, maxy, 0, RL2_SCALE_1, palette, no_data))
  5047   5066   	goto error;
  5048   5067       sqlite3_finalize (stmt_tiles);
  5049   5068       sqlite3_finalize (stmt_data);
  5050   5069       *buffer = bufpix;
  5051   5070       *buf_size = bufpix_size;
  5052   5071       return 1;
  5053   5072   
................................................................................
  5059   5078       if (bufpix != NULL)
  5060   5079   	free (bufpix);
  5061   5080       return 0;
  5062   5081   }
  5063   5082   
  5064   5083   static void
  5065   5084   raster_tile_124_rescaled (unsigned char *outbuf,
  5066         -			  unsigned char pixel_type, const unsigned char *inbuf,
         5085  +			  unsigned char pixel_type,
         5086  +			  const unsigned char *inbuf,
  5067   5087   			  unsigned int section_width,
  5068   5088   			  unsigned int section_height, unsigned int out_width,
  5069   5089   			  unsigned int out_height, rl2PalettePtr palette)
  5070   5090   {
  5071   5091   /* 
  5072   5092   / this function builds an high quality rescaled sub-image by applying pixel interpolation
  5073   5093   /
................................................................................
  5357   5377   do_build_124_bit_section_pyramid (sqlite3 * handle, int max_threads,
  5358   5378   				  const char *coverage, int mixed_resolutions,
  5359   5379   				  sqlite3_int64 section_id,
  5360   5380   				  unsigned char sample_type,
  5361   5381   				  unsigned char pixel_type,
  5362   5382   				  unsigned char num_samples, int srid,
  5363   5383   				  unsigned int tileWidth,
  5364         -				  unsigned int tileHeight, unsigned char bgRed,
  5365         -				  unsigned char bgGreen, unsigned char bgBlue)
         5384  +				  unsigned int tileHeight,
         5385  +				  unsigned char bgRed, unsigned char bgGreen,
         5386  +				  unsigned char bgBlue)
  5366   5387   {
  5367   5388   /* attempting to (re)build a 1,2,4-bit section pyramid from scratch */
  5368   5389       double base_res_x;
  5369   5390       double base_res_y;
  5370   5391       unsigned int sect_width;
  5371   5392       unsigned int sect_height;
  5372   5393       int id_level = 0;
................................................................................
  5420   5441         {
  5421   5442   	  if (!find_base_resolution
  5422   5443   	      (handle, coverage, &base_res_x, &base_res_y))
  5423   5444   	      goto error;
  5424   5445         }
  5425   5446       if (!get_section_raw_raster_data
  5426   5447   	(handle, max_threads, coverage, section_id, sect_width, sect_height,
  5427         -	 sample_type, pixel_type, num_samples, minx, maxy, base_res_x,
  5428         -	 base_res_y, &inbuf, &inbuf_size, palette, no_data))
         5448  +	 sample_type, pixel_type, num_samples, minx, miny, maxx, maxy,
         5449  +	 base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data))
  5429   5450   	goto error;
  5430   5451   
  5431   5452       if (!prepare_section_pyramid_stmts
  5432         -	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
  5433         -	 &stmt_data))
         5453  +	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
         5454  +	 &stmt_tils, &stmt_data))
  5434   5455   	goto error;
  5435   5456   
  5436   5457       id_level = 1;
  5437   5458       scale = 2;
  5438   5459       x_res = base_res_x * 2.0;
  5439   5460       y_res = base_res_y * 2.0;
  5440   5461       while (1)
................................................................................
  5502   5523   		    goto error;
  5503   5524   	    }
  5504   5525   
  5505   5526   	  for (row = 0; row < out_height; row += tileHeight)
  5506   5527   	    {
  5507   5528   		t_minx = minx;
  5508   5529   		t_miny = t_maxy - (tileHeight * y_res);
         5530  +		if (t_miny < miny)
         5531  +		    t_miny = miny;
  5509   5532   		for (col = 0; col < out_width; col += tileWidth)
  5510   5533   		  {
  5511   5534   		      if (pixel_type == RL2_PIXEL_MONOCHROME)
  5512   5535   			{
  5513   5536   			    if (no_data == NULL)
  5514   5537   				nd = NULL;
  5515   5538   			    else
................................................................................
  5528   5551   			    if (no_data == NULL)
  5529   5552   				nd = NULL;
  5530   5553   			    else
  5531   5554   			      {
  5532   5555   				  /* converting the NO-DATA pixel */
  5533   5556   				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
  5534   5557   							 RL2_PIXEL_RGB, 3);
  5535         -				  rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND,
         5558  +				  rl2_set_pixel_sample_uint8 (nd,
         5559  +							      RL2_RED_BAND,
  5536   5560   							      bgRed);
  5537   5561   				  rl2_set_pixel_sample_uint8 (nd,
  5538   5562   							      RL2_GREEN_BAND,
  5539   5563   							      bgGreen);
  5540         -				  rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,
         5564  +				  rl2_set_pixel_sample_uint8 (nd,
         5565  +							      RL2_BLUE_BAND,
  5541   5566   							      bgBlue);
  5542   5567   			      }
  5543   5568   			}
  5544   5569   		      t_maxx = t_minx + (tileWidth * x_res);
         5570  +		      if (t_maxx > maxx)
         5571  +			  t_maxx = maxx;
  5545   5572   		      if (!copy_124_tile
  5546   5573   			  (out_pixel_type, outbuf, &tilebuf,
  5547   5574   			   &tilebuf_sz, &tilemask, &tilemask_sz, row, col,
  5548   5575   			   out_width, out_height, tileWidth, tileHeight,
  5549   5576   			   no_data))
  5550   5577   			{
  5551   5578   			    fprintf (stderr,
................................................................................
  5563   5590   		      if (raster == NULL)
  5564   5591   			{
  5565   5592   			    fprintf (stderr,
  5566   5593   				     "ERROR: unable to create a Pyramid Tile\n");
  5567   5594   			    goto error;
  5568   5595   			}
  5569   5596   		      if (rl2_raster_encode
  5570         -			  (raster, RL2_COMPRESSION_PNG, &blob_odd, &blob_odd_sz,
  5571         -			   &blob_even, &blob_even_sz, 100, 1) != RL2_OK)
         5597  +			  (raster, RL2_COMPRESSION_PNG, &blob_odd,
         5598  +			   &blob_odd_sz, &blob_even, &blob_even_sz, 100,
         5599  +			   1) != RL2_OK)
  5572   5600   			{
  5573   5601   			    fprintf (stderr,
  5574   5602   				     "ERROR: unable to encode a Pyramid tile\n");
  5575   5603   			    goto error;
  5576   5604   			}
  5577   5605   
  5578   5606   		      /* INSERTing the tile */
................................................................................
  5634   5662   }
  5635   5663   
  5636   5664   static int
  5637   5665   do_build_palette_section_pyramid (sqlite3 * handle, int max_threads,
  5638   5666   				  const char *coverage, int mixed_resolutions,
  5639   5667   				  sqlite3_int64 section_id, int srid,
  5640   5668   				  unsigned int tileWidth,
  5641         -				  unsigned int tileHeight, unsigned char bgRed,
  5642         -				  unsigned char bgGreen, unsigned char bgBlue)
         5669  +				  unsigned int tileHeight,
         5670  +				  unsigned char bgRed, unsigned char bgGreen,
         5671  +				  unsigned char bgBlue)
  5643   5672   {
  5644   5673   /* attempting to (re)build a Palette section pyramid from scratch */
  5645   5674       double base_res_x;
  5646   5675       double base_res_y;
  5647   5676       unsigned int sect_width;
  5648   5677       unsigned int sect_height;
  5649   5678       int id_level = 0;
................................................................................
  5699   5728         {
  5700   5729   	  if (!find_base_resolution
  5701   5730   	      (handle, coverage, &base_res_x, &base_res_y))
  5702   5731   	      goto error;
  5703   5732         }
  5704   5733       if (!get_section_raw_raster_data
  5705   5734   	(handle, max_threads, coverage, section_id, sect_width, sect_height,
  5706         -	 RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, maxy, base_res_x,
  5707         -	 base_res_y, &inbuf, &inbuf_size, palette, no_data))
         5735  +	 RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, miny, maxx, maxy,
         5736  +	 base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data))
  5708   5737   	goto error;
  5709   5738   
  5710   5739       if (!prepare_section_pyramid_stmts
  5711         -	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
  5712         -	 &stmt_data))
         5740  +	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
         5741  +	 &stmt_tils, &stmt_data))
  5713   5742   	goto error;
  5714   5743   
  5715   5744       id_level = 1;
  5716   5745       scale = 2;
  5717   5746       x_res = base_res_x * 2.0;
  5718   5747       y_res = base_res_y * 2.0;
  5719   5748       while (1)
................................................................................
  5761   5790   		    goto error;
  5762   5791   	    }
  5763   5792   
  5764   5793   	  for (row = 0; row < out_height; row += tileHeight)
  5765   5794   	    {
  5766   5795   		t_minx = minx;
  5767   5796   		t_miny = t_maxy - (tileHeight * y_res);
         5797  +		if (t_miny < miny)
         5798  +		    t_miny = miny;
  5768   5799   		for (col = 0; col < out_width; col += tileWidth)
  5769   5800   		  {
  5770   5801   		      if (no_data == NULL)
  5771   5802   			  nd = NULL;
  5772   5803   		      else
  5773   5804   			{
  5774   5805   			    /* converting the NO-DATA pixel */
................................................................................
  5779   5810   			    rl2_set_pixel_sample_uint8 (nd,
  5780   5811   							RL2_GREEN_BAND,
  5781   5812   							bgGreen);
  5782   5813   			    rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,
  5783   5814   							bgBlue);
  5784   5815   			}
  5785   5816   		      t_maxx = t_minx + (tileWidth * x_res);
         5817  +		      if (t_maxx > maxx)
         5818  +			  t_maxx = maxx;
  5786   5819   		      if (!copy_124_tile (out_pixel_type, outbuf, &tilebuf,
  5787         -					  &tilebuf_sz, &tilemask, &tilemask_sz,
  5788         -					  row, col, out_width, out_height,
  5789         -					  tileWidth, tileHeight, no_data))
         5820  +					  &tilebuf_sz, &tilemask,
         5821  +					  &tilemask_sz, row, col, out_width,
         5822  +					  out_height, tileWidth, tileHeight,
         5823  +					  no_data))
  5790   5824   			{
  5791   5825   			    fprintf (stderr,
  5792   5826   				     "ERROR: unable to extract a Pyramid Tile\n");
  5793   5827   			    goto error;
  5794   5828   			}
  5795   5829   
  5796   5830   		      raster =
................................................................................
  6049   6083   		    goto error;
  6050   6084   	    }
  6051   6085   	  else
  6052   6086   	    {
  6053   6087   		/* ordinary RGB, Grayscale, MultiBand or DataGrid Pyramid */
  6054   6088   		if (!do_build_section_pyramid
  6055   6089   		    (handle, coverage, section_id, sample_type, pixel_type,
  6056         -		     num_bands, compression, ptrcvg->mixedResolutions, quality,
  6057         -		     srid, tileWidth, tileHeight))
         6090  +		     num_bands, compression, ptrcvg->mixedResolutions,
         6091  +		     quality, srid, tileWidth, tileHeight))
  6058   6092   		    goto error;
  6059   6093   	    }
  6060   6094   	  if (verbose)
  6061   6095   	    {
  6062   6096   		printf ("  ----------\n");
  6063   6097   #if defined(_WIN32) && !defined(__MINGW32__)
  6064   6098   		printf
................................................................................
  6107   6141   	  ret = sqlite3_step (stmt);
  6108   6142   	  if (ret == SQLITE_DONE)
  6109   6143   	      break;
  6110   6144   	  if (ret == SQLITE_ROW)
  6111   6145   	    {
  6112   6146   		sqlite3_int64 section_id = sqlite3_column_int64 (stmt, 0);
  6113   6147   		if (rl2_build_section_pyramid
  6114         -		    (handle, max_threads, coverage, section_id, forced_rebuild,
  6115         -		     verbose) != RL2_OK)
         6148  +		    (handle, max_threads, coverage, section_id,
         6149  +		     forced_rebuild, verbose) != RL2_OK)
  6116   6150   		    goto error;
  6117   6151   	    }
  6118   6152   	  else
  6119   6153   	    {
  6120   6154   		fprintf (stderr,
  6121   6155   			 "SELECT section_id; sqlite3_step() error: %s\n",
  6122   6156   			 sqlite3_errmsg (handle));
................................................................................
  6281   6315   	  out_sample_type = RL2_SAMPLE_UINT8;
  6282   6316   	  out_pixel_type = RL2_PIXEL_RGB;
  6283   6317   	  out_num_bands = 3;
  6284   6318   	  out_compression = RL2_COMPRESSION_PNG;
  6285   6319   	  out_quality = 100;
  6286   6320   	  virt_levels = 1;
  6287   6321         }
  6288         -    else if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE
  6289         -	     && num_bands == 1)
         6322  +    else if (sample_type == RL2_SAMPLE_UINT8
         6323  +	     && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1)
  6290   6324         {
  6291   6325   	  /* palette 8: output colorspace is RGB compression PNG */
  6292   6326   	  out_sample_type = RL2_SAMPLE_UINT8;
  6293   6327   	  out_pixel_type = RL2_PIXEL_RGB;
  6294   6328   	  out_num_bands = 3;
  6295   6329   	  out_compression = RL2_COMPRESSION_PNG;
  6296   6330   	  out_quality = 100;
................................................................................
  6403   6437   		      if (tile_miny < miny)
  6404   6438   			  end_y = miny;
  6405   6439   
  6406   6440   		      if ((sample_type == RL2_SAMPLE_UINT8
  6407   6441   			   && pixel_type == RL2_PIXEL_GRAYSCALE
  6408   6442   			   && num_bands == 1)
  6409   6443   			  || (sample_type == RL2_SAMPLE_UINT8
  6410         -			      && pixel_type == RL2_PIXEL_RGB && num_bands == 3)
         6444  +			      && pixel_type == RL2_PIXEL_RGB
         6445  +			      && num_bands == 3)
  6411   6446   			  || (sample_type == RL2_SAMPLE_UINT8
  6412   6447   			      && pixel_type == RL2_PIXEL_PALETTE
  6413   6448   			      && num_bands == 1))
  6414   6449   			{
  6415   6450   			    /* RGB, PALETTE or GRAYSCALE datasource (UINT8) */
  6416   6451   			    if (!rescale_monolithic_rgba
  6417         -				(id_level, tileWidth, tileHeight, resize_factor,
  6418         -				 res_x, res_y, tile_minx, tile_miny,
  6419         -				 tile_maxx, tile_maxy, buffer, buf_size, mask,
  6420         -				 &mask_size, palette, no_data, stmt_geo,
  6421         -				 stmt_rd))
         6452  +				(id_level, tileWidth, tileHeight,
         6453  +				 resize_factor, res_x, res_y, tile_minx,
         6454  +				 tile_miny, tile_maxx, tile_maxy, buffer,
         6455  +				 buf_size, mask, &mask_size, palette, no_data,
         6456  +				 stmt_geo, stmt_rd))
  6422   6457   				goto error;
  6423   6458   			    if (mask_size == 0)
  6424   6459   				mask = NULL;
  6425   6460   			}
  6426   6461   		      else if (((sample_type == RL2_SAMPLE_1_BIT
  6427   6462   				 || sample_type == RL2_SAMPLE_2_BIT
  6428   6463   				 || sample_type == RL2_SAMPLE_4_BIT)
................................................................................
  6460   6495   		      else if (pixel_type == RL2_PIXEL_DATAGRID)
  6461   6496   			{
  6462   6497   			    /* DataGrid */
  6463   6498   			    if (!rescale_monolithic_datagrid
  6464   6499   				(id_level, tileWidth, tileHeight, sample_type,
  6465   6500   				 resize_factor, res_x, res_y, tile_minx,
  6466   6501   				 tile_miny, tile_maxx, tile_maxy, buffer,
  6467         -				 buf_size, mask, &mask_size, no_data, stmt_geo,
  6468         -				 stmt_rd))
         6502  +				 buf_size, mask, &mask_size, no_data,
         6503  +				 stmt_geo, stmt_rd))
  6469   6504   				goto error;
  6470   6505   			    if (mask_size == 0)
  6471   6506   				mask = NULL;
  6472   6507   			}
  6473   6508   		      else
  6474   6509   			{
  6475   6510   			    /* unknown */
................................................................................
  6513   6548   			{
  6514   6549   			    if (no_data == NULL)
  6515   6550   				nd = NULL;
  6516   6551   			    else
  6517   6552   			      {
  6518   6553   				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
  6519   6554   							 RL2_PIXEL_RGB, 3);
  6520         -				  rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND,
         6555  +				  rl2_set_pixel_sample_uint8 (nd,
         6556  +							      RL2_RED_BAND,
  6521   6557   							      255);
  6522   6558   				  rl2_set_pixel_sample_uint8 (nd,
  6523   6559   							      RL2_GREEN_BAND,
  6524   6560   							      255);
  6525         -				  rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,
         6561  +				  rl2_set_pixel_sample_uint8 (nd,
         6562  +							      RL2_BLUE_BAND,
  6526   6563   							      255);
  6527   6564   			      }
  6528   6565   			}
  6529   6566   		      else
  6530   6567   			  nd = rl2_clone_pixel (no_data);
  6531   6568   
  6532   6569   		      raster =
................................................................................
  6606   6643       sqlite3_finalize (stmt_rd);
  6607   6644       sqlite3_finalize (stmt_levl);
  6608   6645       sqlite3_finalize (stmt_tils);
  6609   6646       sqlite3_finalize (stmt_data);
  6610   6647       if (verbose)
  6611   6648         {
  6612   6649   	  printf ("  ----------\n");
  6613         -	  printf ("    Monolithic Pyramid levels successfully built for: %s\n",
  6614         -		  coverage);
         6650  +	  printf
         6651  +	      ("    Monolithic Pyramid levels successfully built for: %s\n",
         6652  +	       coverage);
  6615   6653         }
  6616   6654       free (buffer);
  6617   6655       free (mask);
  6618   6656       rl2_destroy_coverage (cvg);
  6619   6657   
  6620   6658       return RL2_OK;
  6621   6659   

Changes to src/rl2rastersym.c.

   690    690   			    for (ib = 0; ib < out_num_bands; ib++)
   691    691   				p_out++;
   692    692   			}
   693    693   		      else
   694    694   			{
   695    695   			    /* opaque pixel */
   696    696   			    p_out =
   697         -				mono_int8_pixel_handler (p_in, p_out, mono_band,
          697  +				mono_int8_pixel_handler (p_in, p_out,
          698  +							 mono_band,
   698    699   							 mono_handling);
   699    700   			}
   700    701   		  }
   701    702   		else
   702    703   		  {
   703    704   		      /* testing for NO-DATA values */
   704    705   		      int match = 0;
................................................................................
   707    708   		      rl2_get_pixel_sample_int8 (no_data, &sample);
   708    709   		      if (sample == *p_save++)
   709    710   			  match++;
   710    711   		      if (match != 1)
   711    712   			{
   712    713   			    /* opaque pixel */
   713    714   			    p_out =
   714         -				mono_int8_pixel_handler (p_in, p_out, mono_band,
          715  +				mono_int8_pixel_handler (p_in, p_out,
          716  +							 mono_band,
   715    717   							 mono_handling);
   716    718   			}
   717    719   		      else
   718    720   			{
   719    721   			    /* NO-DATA pixel */
   720    722   			    for (ib = 0; ib < out_num_bands; ib++)
   721    723   				p_out++;
................................................................................
   729    731   static void
   730    732   copy_uint8_raw_pixels (const unsigned char *buffer, const unsigned char *mask,
   731    733   		       unsigned char *outbuf, unsigned short width,
   732    734   		       unsigned short height, unsigned char num_bands,
   733    735   		       double x_res, double y_res, double minx, double maxy,
   734    736   		       double tile_minx, double tile_maxy,
   735    737   		       unsigned short tile_width, unsigned short tile_height,
   736         -		       rl2PixelPtr no_data)
          738  +		       rl2PixelPtr no_data, unsigned char raster_type)
   737    739   {
   738    740   /* copying UINT8 raw pixels from the DBMS tile into the output image */
   739    741       int x;
   740    742       int y;
   741    743       int b;
   742    744       int out_x;
   743    745       int out_y;
................................................................................
   758    760         {
   759    761   	  ignore_no_data = 0;
   760    762   	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
   761    763   	      != RL2_OK)
   762    764   	      ignore_no_data = 1;
   763    765   	  if (nbands != num_bands)
   764    766   	      ignore_no_data = 1;
   765         -	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT
          767  +	  if (sample_type == RL2_SAMPLE_1_BIT
          768  +	      || sample_type == RL2_SAMPLE_2_BIT
   766    769   	      || sample_type == RL2_SAMPLE_4_BIT
   767    770   	      || sample_type == RL2_SAMPLE_UINT8)
   768    771   	      ;
   769    772   	  else
   770    773   	      ignore_no_data = 1;
   771    774         }
   772         -
   773    775       geo_y = tile_maxy + y_res2;
   774    776       for (y = 0; y < tile_height; y++)
   775    777         {
   776    778   	  geo_y -= y_res;
   777    779   	  out_y = (maxy - geo_y) / y_res;
   778    780   	  if (out_y < 0 || out_y >= height)
   779    781   	    {
................................................................................
   818    820   			}
   819    821   		  }
   820    822   		else
   821    823   		  {
   822    824   		      /* testing for NO-DATA values */
   823    825   		      int match = 0;
   824    826   		      const unsigned char *p_save = p_in;
   825         -		      for (b = 0; b < num_bands; b++)
          827  +		      if (raster_type == RL2_SAMPLE_1_BIT && num_bands == 1)
   826    828   			{
   827         -			    unsigned char sample = 0;
   828         -			    switch (sample_type)
   829         -			      {
   830         -			      case RL2_SAMPLE_1_BIT:
   831         -				  rl2_get_pixel_sample_1bit (no_data, &sample);
   832         -				  break;
   833         -			      case RL2_SAMPLE_2_BIT:
   834         -				  rl2_get_pixel_sample_2bit (no_data, &sample);
   835         -				  break;
   836         -			      case RL2_SAMPLE_4_BIT:
   837         -				  rl2_get_pixel_sample_4bit (no_data, &sample);
   838         -				  break;
   839         -			      case RL2_SAMPLE_UINT8:
   840         -				  rl2_get_pixel_sample_uint8 (no_data, b,
   841         -							      &sample);
   842         -				  break;
   843         -			      };
   844         -			    if (sample == *p_in++)
   845         -				match++;
          829  +			    /* special case: MONOCHROME */
          830  +			    if (*p_in++ == 1)
          831  +				*p_out++ = 0;
          832  +			    else
          833  +				p_out++;
          834  +			    match++;
   846    835   			}
   847         -		      if (match != num_bands)
          836  +		      else
   848    837   			{
   849         -			    /* opaque pixel */
   850         -			    p_in = p_save;
   851    838   			    for (b = 0; b < num_bands; b++)
   852         -				*p_out++ = *p_in++;
   853         -			}
   854         -		      else
   855         -			{
   856         -			    /* NO-DATA pixel */
   857         -			    for (b = 0; b < num_bands; b++)
   858         -				p_out++;
          839  +			      {
          840  +				  unsigned char sample = 0;
          841  +				  switch (sample_type)
          842  +				    {
          843  +				    case RL2_SAMPLE_1_BIT:
          844  +					rl2_get_pixel_sample_1bit (no_data,
          845  +								   &sample);
          846  +					break;
          847  +				    case RL2_SAMPLE_2_BIT:
          848  +					rl2_get_pixel_sample_2bit (no_data,
          849  +								   &sample);
          850  +					break;
          851  +				    case RL2_SAMPLE_4_BIT:
          852  +					rl2_get_pixel_sample_4bit (no_data,
          853  +								   &sample);
          854  +					break;
          855  +				    case RL2_SAMPLE_UINT8:
          856  +					rl2_get_pixel_sample_uint8 (no_data, b,
          857  +								    &sample);
          858  +					break;
          859  +				    };
          860  +				  if (sample == *p_in++)
          861  +				      match++;
          862  +			      }
          863  +			    if (match != num_bands)
          864  +			      {
          865  +				  /* opaque pixel */
          866  +				  p_in = p_save;
          867  +				  for (b = 0; b < num_bands; b++)
          868  +				      *p_out++ = *p_in++;
          869  +			      }
          870  +			    else
          871  +			      {
          872  +				  /* NO-DATA pixel */
          873  +				  for (b = 0; b < num_bands; b++)
          874  +				      p_out++;
          875  +			      }
   859    876   			}
   860    877   		  }
   861    878   	    }
   862    879         }
   863    880   }
   864    881   
   865    882   static unsigned char *
................................................................................
   877    894       return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
   878    895   }
   879    896   
   880    897   static void
   881    898   copy_uint8_raw_selected_pixels (const unsigned char *buffer,
   882    899   				const unsigned char *mask,
   883    900   				unsigned char *outbuf, unsigned short width,
   884         -				unsigned short height, unsigned char num_bands,
   885         -				double x_res, double y_res, double minx,
   886         -				double maxy, double tile_minx, double tile_maxy,
          901  +				unsigned short height,
          902  +				unsigned char num_bands, double x_res,
          903  +				double y_res, double minx, double maxy,
          904  +				double tile_minx, double tile_maxy,
   887    905   				unsigned short tile_width,
   888         -				unsigned short tile_height, rl2PixelPtr no_data,
   889         -				unsigned char red_band,
          906  +				unsigned short tile_height,
          907  +				rl2PixelPtr no_data, unsigned char red_band,
   890    908   				unsigned char green_band,
   891    909   				unsigned char blue_band,
   892    910   				rl2BandHandlingPtr red_handling,
   893    911   				rl2BandHandlingPtr green_handling,
   894    912   				rl2BandHandlingPtr blue_handling)
   895    913   {
   896    914   /* copying UINT8 raw pixels from the DBMS tile into the output image */
................................................................................
   965    983   			    /* skipping a transparent pixel */
   966    984   			    p_out += 3;
   967    985   			}
   968    986   		      else
   969    987   			{
   970    988   			    /* opaque pixel */
   971    989   			    p_out =
   972         -				mono_uint8_pixel_handler (p_in, p_out, red_band,
          990  +				mono_uint8_pixel_handler (p_in, p_out,
          991  +							  red_band,
   973    992   							  red_handling);
   974    993   			    p_out =
   975    994   				mono_uint8_pixel_handler (p_in, p_out,
   976    995   							  green_band,
   977    996   							  green_handling);
   978    997   			    p_out =
   979    998   				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
   993   1012   			    if (sample == *p_save++)
   994   1013   				match++;
   995   1014   			}
   996   1015   		      if (match != num_bands)
   997   1016   			{
   998   1017   			    /* opaque pixel */
   999   1018   			    p_out =
  1000         -				mono_uint8_pixel_handler (p_in, p_out, red_band,
         1019  +				mono_uint8_pixel_handler (p_in, p_out,
         1020  +							  red_band,
  1001   1021   							  red_handling);
  1002   1022   			    p_out =
  1003   1023   				mono_uint8_pixel_handler (p_in, p_out,
  1004   1024   							  green_band,
  1005   1025   							  green_handling);
  1006   1026   			    p_out =
  1007   1027   				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
  1020   1040   }
  1021   1041   
  1022   1042   static void
  1023   1043   copy_uint8_raw_mono_pixels (const unsigned char *buffer,
  1024   1044   			    const unsigned char *mask, unsigned char *outbuf,
  1025   1045   			    unsigned short width, unsigned short height,
  1026   1046   			    unsigned char out_num_bands,
  1027         -			    unsigned char num_bands, double x_res, double y_res,
  1028         -			    double minx, double maxy, double tile_minx,
  1029         -			    double tile_maxy, unsigned short tile_width,
         1047  +			    unsigned char num_bands, double x_res,
         1048  +			    double y_res, double minx, double maxy,
         1049  +			    double tile_minx, double tile_maxy,
         1050  +			    unsigned short tile_width,
  1030   1051   			    unsigned short tile_height, rl2PixelPtr no_data,
  1031   1052   			    unsigned char mono_band,
  1032   1053   			    rl2BandHandlingPtr mono_handling)
  1033   1054   {
  1034   1055   /* copying UINT8 raw pixels from the DBMS tile into the output image */
  1035   1056       int x;
  1036   1057       int y;
................................................................................
  1393   1414   		  }
  1394   1415   		p_in++;
  1395   1416   	    }
  1396   1417         }
  1397   1418   }
  1398   1419   
  1399   1420   static void
  1400         -copy_uint16_raw_pixels (const unsigned short *buffer, const unsigned char *mask,
  1401         -			unsigned short *outbuf, unsigned short width,
  1402         -			unsigned short height, unsigned char num_bands,
  1403         -			double x_res, double y_res, double minx, double maxy,
  1404         -			double tile_minx, double tile_maxy,
  1405         -			unsigned short tile_width, unsigned short tile_height,
  1406         -			rl2PixelPtr no_data)
         1421  +copy_uint16_raw_pixels (const unsigned short *buffer,
         1422  +			const unsigned char *mask, unsigned short *outbuf,
         1423  +			unsigned short width, unsigned short height,
         1424  +			unsigned char num_bands, double x_res, double y_res,
         1425  +			double minx, double maxy, double tile_minx,
         1426  +			double tile_maxy, unsigned short tile_width,
         1427  +			unsigned short tile_height, rl2PixelPtr no_data)
  1407   1428   {
  1408   1429   /* copying UINT16 raw pixels from the DBMS tile into the output image */
  1409   1430       int x;
  1410   1431       int y;
  1411   1432       int b;
  1412   1433       int out_x;
  1413   1434       int out_y;
................................................................................
  1530   1551       return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
  1531   1552   }
  1532   1553   
  1533   1554   static void
  1534   1555   copy_uint16_raw_selected_pixels (const unsigned short *buffer,
  1535   1556   				 const unsigned char *mask,
  1536   1557   				 unsigned char *outbuf, unsigned short width,
  1537         -				 unsigned short height, unsigned char num_bands,
  1538         -				 double x_res, double y_res, double minx,
  1539         -				 double maxy, double tile_minx,
  1540         -				 double tile_maxy, unsigned short tile_width,
         1558  +				 unsigned short height,
         1559  +				 unsigned char num_bands, double x_res,
         1560  +				 double y_res, double minx, double maxy,
         1561  +				 double tile_minx, double tile_maxy,
         1562  +				 unsigned short tile_width,
  1541   1563   				 unsigned short tile_height,
  1542   1564   				 rl2PixelPtr no_data, unsigned char red_band,
  1543   1565   				 unsigned char green_band,
  1544   1566   				 unsigned char blue_band,
  1545   1567   				 rl2BandHandlingPtr red_handling,
  1546   1568   				 rl2BandHandlingPtr green_handling,
  1547   1569   				 rl2BandHandlingPtr blue_handling)
................................................................................
  3075   3097   		if (style->contrastEnhancement ==
  3076   3098   		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
  3077   3099   		  {
  3078   3100   		      r = malloc (sizeof (rl2BandHandling));
  3079   3101   		      r->colorMap = NULL;
  3080   3102   		      r->contrastEnhancement =
  3081   3103   			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
  3082         -		      compute_stretching (band, &(r->minValue), &(r->maxValue),
  3083         -					  &(r->scaleFactor));
         3104  +		      compute_stretching (band, &(r->minValue),
         3105  +					  &(r->maxValue), &(r->scaleFactor));
  3084   3106   		  }
  3085   3107   		else if (style->contrastEnhancement ==
  3086   3108   			 RL2_CONTRAST_ENHANCEMENT_NONE)
  3087   3109   		  {
  3088   3110   		      r = malloc (sizeof (rl2BandHandling));
  3089   3111   		      r->colorMap = NULL;
  3090   3112   		      r->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
  3161   3183   		if (style->contrastEnhancement ==
  3162   3184   		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
  3163   3185   		  {
  3164   3186   		      g = malloc (sizeof (rl2BandHandling));
  3165   3187   		      g->colorMap = NULL;
  3166   3188   		      g->contrastEnhancement =
  3167   3189   			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
  3168         -		      compute_stretching (band, &(g->minValue), &(g->maxValue),
  3169         -					  &(g->scaleFactor));
         3190  +		      compute_stretching (band, &(g->minValue),
         3191  +					  &(g->maxValue), &(g->scaleFactor));
  3170   3192   		  }
  3171   3193   		else if (style->contrastEnhancement ==
  3172   3194   			 RL2_CONTRAST_ENHANCEMENT_NONE)
  3173   3195   		  {
  3174   3196   		      g = malloc (sizeof (rl2BandHandling));
  3175   3197   		      g->colorMap = NULL;
  3176   3198   		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
  3247   3269   		if (style->contrastEnhancement ==
  3248   3270   		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
  3249   3271   		  {
  3250   3272   		      b = malloc (sizeof (rl2BandHandling));
  3251   3273   		      b->colorMap = NULL;
  3252   3274   		      b->contrastEnhancement =
  3253   3275   			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
  3254         -		      compute_stretching (band, &(b->minValue), &(b->maxValue),
  3255         -					  &(b->scaleFactor));
         3276  +		      compute_stretching (band, &(b->minValue),
         3277  +					  &(b->maxValue), &(b->scaleFactor));
  3256   3278   		  }
  3257   3279   		else if (style->contrastEnhancement ==
  3258   3280   			 RL2_CONTRAST_ENHANCEMENT_NONE)
  3259   3281   		  {
  3260   3282   		      b = malloc (sizeof (rl2BandHandling));
  3261   3283   		      b->colorMap = NULL;
  3262   3284   		      b->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
  3599   3621   		if (style->contrastEnhancement ==
  3600   3622   		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
  3601   3623   		  {
  3602   3624   		      g = malloc (sizeof (rl2BandHandling));
  3603   3625   		      g->colorMap = NULL;
  3604   3626   		      g->contrastEnhancement =
  3605   3627   			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
  3606         -		      compute_stretching (band, &(g->minValue), &(g->maxValue),
  3607         -					  &(g->scaleFactor));
         3628  +		      compute_stretching (band, &(g->minValue),
         3629  +					  &(g->maxValue), &(g->scaleFactor));
  3608   3630   		  }
  3609   3631   		else if (style->contrastEnhancement ==
  3610   3632   			 RL2_CONTRAST_ENHANCEMENT_NONE)
  3611   3633   		  {
  3612   3634   		      g = malloc (sizeof (rl2BandHandling));
  3613   3635   		      g->colorMap = NULL;
  3614   3636   		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
  3893   3915   }
  3894   3916   
  3895   3917   static int
  3896   3918   do_copy_raw_selected_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
  3897   3919   			     unsigned int width, unsigned int height,
  3898   3920   			     double x_res, double y_res, double minx,
  3899   3921   			     double maxy, double tile_minx, double tile_maxy,
  3900         -			     unsigned int tile_width, unsigned int tile_height,
  3901         -			     rl2PixelPtr no_data, unsigned char red_band,
  3902         -			     unsigned char green_band, unsigned char blue_band,
         3922  +			     unsigned int tile_width,
         3923  +			     unsigned int tile_height, rl2PixelPtr no_data,
         3924  +			     unsigned char red_band, unsigned char green_band,
         3925  +			     unsigned char blue_band,
  3903   3926   			     rl2BandHandlingPtr red_handling,
  3904   3927   			     rl2BandHandlingPtr green_handling,
  3905   3928   			     rl2BandHandlingPtr blue_handling)
  3906   3929   {
  3907   3930       switch (rst->sampleType)
  3908   3931         {
  3909   3932         case RL2_SAMPLE_UINT8:
................................................................................
  4157   4180         };
  4158   4181       return 0;
  4159   4182   }
  4160   4183   
  4161   4184   static int
  4162   4185   do_copy_raw_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
  4163   4186   		    unsigned int width, unsigned int height,
  4164         -		    unsigned char sample_type, unsigned char num_bands,
  4165         -		    double x_res, double y_res, double minx, double maxy,
  4166         -		    double tile_minx, double tile_maxy, unsigned int tile_width,
         4187  +		    unsigned char raster_type, unsigned char sample_type,
         4188  +		    unsigned char num_bands, double x_res, double y_res,
         4189  +		    double minx, double maxy, double tile_minx,
         4190  +		    double tile_maxy, unsigned int tile_width,
  4167   4191   		    unsigned int tile_height, rl2PixelPtr no_data)
  4168   4192   {
  4169         -
  4170         -
  4171   4193       switch (sample_type)
  4172   4194         {
  4173   4195         case RL2_SAMPLE_INT8:
  4174   4196   	  copy_int8_raw_pixels ((const char *) (rst->rasterBuffer),
  4175   4197   				(const unsigned char *) (rst->maskBuffer),
  4176   4198   				(char *) outbuf, width, height,
  4177   4199   				x_res, y_res, minx, maxy, tile_minx,
................................................................................
  4181   4203   	  copy_int16_raw_pixels ((const short *) (rst->rasterBuffer),
  4182   4204   				 (const unsigned char *) (rst->maskBuffer),
  4183   4205   				 (short *) outbuf, width, height,
  4184   4206   				 x_res, y_res, minx, maxy, tile_minx,
  4185   4207   				 tile_maxy, tile_width, tile_height, no_data);
  4186   4208   	  return 1;
  4187   4209         case RL2_SAMPLE_UINT16:
  4188         -	  copy_uint16_raw_pixels ((const unsigned short *) (rst->rasterBuffer),
         4210  +	  copy_uint16_raw_pixels ((const unsigned short
         4211  +				   *) (rst->rasterBuffer),
  4189   4212   				  (const unsigned char *) (rst->maskBuffer),
  4190   4213   				  (unsigned short *) outbuf, width, height,
  4191   4214   				  num_bands, x_res, y_res, minx, maxy,
  4192   4215   				  tile_minx, tile_maxy, tile_width,
  4193   4216   				  tile_height, no_data);
  4194   4217   	  return 1;
  4195   4218         case RL2_SAMPLE_INT32:
................................................................................
  4222   4245   				  tile_minx, tile_maxy, tile_width,
  4223   4246   				  tile_height, no_data);
  4224   4247   	  return 1;
  4225   4248         default:
  4226   4249   	  copy_uint8_raw_pixels ((const unsigned char *) (rst->rasterBuffer),
  4227   4250   				 (const unsigned char *) (rst->maskBuffer),
  4228   4251   				 (unsigned char *) outbuf, width, height,
  4229         -				 num_bands, x_res, y_res, minx, maxy, tile_minx,
  4230         -				 tile_maxy, tile_width, tile_height, no_data);
         4252  +				 num_bands, x_res, y_res, minx, maxy,
         4253  +				 tile_minx, tile_maxy, tile_width,
         4254  +				 tile_height, no_data, raster_type);
  4231   4255   	  return 1;
  4232   4256         };
  4233   4257       return 0;
  4234   4258   }
  4235   4259   
  4236   4260   RL2_PRIVATE int
  4237   4261   rl2_copy_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
  4238   4262   		     unsigned int width,
  4239   4263   		     unsigned int height, unsigned char sample_type,
  4240   4264   		     unsigned char num_bands, unsigned char auto_ndvi,
  4241         -		     unsigned char red_band_index, unsigned char nir_band_index,
  4242         -		     double x_res, double y_res, double minx, double maxy,
  4243         -		     double tile_minx, double tile_maxy, rl2PixelPtr no_data,
         4265  +		     unsigned char red_band_index,
         4266  +		     unsigned char nir_band_index, double x_res, double y_res,
         4267  +		     double minx, double maxy, double tile_minx,
         4268  +		     double tile_maxy, rl2PixelPtr no_data,
  4244   4269   		     rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats)
  4245   4270   {
  4246   4271   /* copying raw pixels into the output buffer */
  4247   4272       unsigned int tile_width;
  4248   4273       unsigned int tile_height;
  4249   4274       rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
  4250   4275   
................................................................................
  4252   4277   	return 0;
  4253   4278       if (style != NULL && stats != NULL)
  4254   4279         {
  4255   4280   	  /* attempting to apply a RasterSymbolizer */
  4256   4281   	  int yes_no;
  4257   4282   	  int categorize;
  4258   4283   	  int interpolate;
  4259         -	  if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no) ==
  4260         -	      RL2_OK)
         4284  +	  if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no)
         4285  +	      == RL2_OK)
  4261   4286   	    {
  4262   4287   		if ((rst->sampleType == RL2_SAMPLE_UINT8
  4263   4288   		     || rst->sampleType == RL2_SAMPLE_UINT16)
  4264   4289   		    && (rst->pixelType == RL2_PIXEL_RGB
  4265   4290   			|| rst->pixelType == RL2_PIXEL_MULTIBAND) && yes_no)
  4266   4291   		  {
  4267   4292   		      /* triple band selection - false color RGB */
................................................................................
  4287   4312   						  blue_band, &red_handling,
  4288   4313   						  &green_handling,
  4289   4314   						  &blue_handling);
  4290   4315   		      if (red_handling == NULL || green_handling == NULL
  4291   4316   			  || blue_handling == NULL)
  4292   4317   			  return 0;
  4293   4318   		      if (do_copy_raw_selected_pixels
  4294         -			  (rst, outbuf, width, height, x_res, y_res, minx, maxy,
  4295         -			   tile_minx, tile_maxy, tile_width, tile_height,
  4296         -			   no_data, red_band, green_band, blue_band,
  4297         -			   red_handling, green_handling, blue_handling))
         4319  +			  (rst, outbuf, width, height, x_res, y_res, minx,
         4320  +			   maxy, tile_minx, tile_maxy, tile_width,
         4321  +			   tile_height, no_data, red_band, green_band,
         4322  +			   blue_band, red_handling, green_handling,
         4323  +			   blue_handling))
  4298   4324   			  return 1;
  4299   4325   		      if (red_handling != NULL)
  4300   4326   			  free (red_handling);
  4301   4327   		      if (green_handling != NULL)
  4302   4328   			  free (green_handling);
  4303   4329   		      if (blue_handling != NULL)
  4304   4330   			  free (blue_handling);
................................................................................
  4316   4342   		      /* applying Auto NDVI */
  4317   4343   		      rl2BandHandlingPtr ndvi_handling = NULL;
  4318   4344   		      build_ndvi_handling ((rl2PrivRasterSymbolizerPtr)
  4319   4345   					   style, &ndvi_handling);
  4320   4346   		      if (ndvi_handling == NULL)
  4321   4347   			  return 0;
  4322   4348   		      if (do_auto_ndvi_pixels
  4323         -			  (rst, outbuf, width, height, num_bands, x_res, y_res,
  4324         -			   minx, maxy, tile_minx, tile_maxy, tile_width,
  4325         -			   tile_height, no_data, red_band_index, nir_band_index,
  4326         -			   ndvi_handling))
         4349  +			  (rst, outbuf, width, height, num_bands, x_res,
         4350  +			   y_res, minx, maxy, tile_minx, tile_maxy,
         4351  +			   tile_width, tile_height, no_data, red_band_index,
         4352  +			   nir_band_index, ndvi_handling))
  4327   4353   			  return 1;
  4328   4354   		      if (ndvi_handling != NULL)
  4329   4355   			  destroy_ndvi_handling (ndvi_handling);
  4330   4356   		  }
  4331   4357   		if (((rst->sampleType == RL2_SAMPLE_UINT8
  4332   4358   		      || rst->sampleType == RL2_SAMPLE_UINT16)
  4333   4359   		     || rst->pixelType == RL2_PIXEL_DATAGRID) && yes_no)
................................................................................
  4344   4370   						style,
  4345   4371   						(rl2PrivRasterStatisticsPtr)
  4346   4372   						stats, mono_band,
  4347   4373   						&mono_handling);
  4348   4374   		      if (mono_handling == NULL)
  4349   4375   			  return 0;
  4350   4376   		      if (do_copy_raw_mono_pixels
  4351         -			  (rst, outbuf, width, height, num_bands, x_res, y_res,
  4352         -			   minx, maxy, tile_minx, tile_maxy, tile_width,
  4353         -			   tile_height, no_data, mono_band, mono_handling))
         4377  +			  (rst, outbuf, width, height, num_bands, x_res,
         4378  +			   y_res, minx, maxy, tile_minx, tile_maxy,
         4379  +			   tile_width, tile_height, no_data, mono_band,
         4380  +			   mono_handling))
  4354   4381   			  return 1;
  4355   4382   		      if (mono_handling != NULL)
  4356   4383   			  destroy_mono_handling (mono_handling);
  4357   4384   		  }
  4358   4385   	    }
  4359   4386         }
  4360   4387   
  4361   4388       if (do_copy_raw_pixels
  4362         -	(rst, outbuf, width, height, sample_type, num_bands, x_res, y_res, minx,
  4363         -	 maxy, tile_minx, tile_maxy, tile_width, tile_height, no_data))
         4389  +	(rst, outbuf, width, height, rst->sampleType, sample_type, num_bands,
         4390  +	 x_res, y_res, minx, maxy, tile_minx, tile_maxy, tile_width,
         4391  +	 tile_height, no_data))
  4364   4392   	return 1;
  4365   4393   
  4366   4394       return 0;
  4367   4395   }
         4396  +
         4397  +static void
         4398  +do_copy_raw_mask (rl2PrivRasterPtr rst, unsigned char *maskbuf,
         4399  +		  unsigned int width, unsigned int height, double x_res,
         4400  +		  double y_res, double minx, double maxy, double tile_minx,
         4401  +		  double tile_maxy, unsigned int tile_width,
         4402  +		  unsigned int tile_height)
         4403  +{
         4404  +/* copying mask pixels from the DBMS tile into the output mask */
         4405  +    unsigned int x;
         4406  +    unsigned int y;
         4407  +    int out_x;
         4408  +    int out_y;
         4409  +    double geo_x;
         4410  +    double geo_y;
         4411  +    const unsigned char *p_in = rst->maskBuffer;
         4412  +    unsigned char *p_out;
         4413  +    double y_res2 = y_res / 2.0;
         4414  +    double x_res2 = x_res / 2.0;
         4415  +
         4416  +    geo_y = tile_maxy + y_res2;
         4417  +    for (y = 0; y < tile_height; y++)
         4418  +      {
         4419  +	  geo_y -= y_res;
         4420  +	  out_y = (maxy - geo_y) / y_res;
         4421  +	  if (out_y < 0 || out_y >= (int) height)
         4422  +	    {
         4423  +		p_in += tile_width;
         4424  +		continue;
         4425  +	    }
         4426  +	  geo_x = tile_minx - x_res2;
         4427  +	  for (x = 0; x < tile_width; x++)
         4428  +	    {
         4429  +		geo_x += x_res;
         4430  +		out_x = (geo_x - minx) / x_res;
         4431  +		if (out_x < 0 || out_x >= (int) width)
         4432  +		  {
         4433  +		      p_in++;
         4434  +		      continue;
         4435  +		  }
         4436  +		p_out = maskbuf + (out_y * width) + out_x;
         4437  +		if (*p_in++ == 0)
         4438  +		    *p_out++ = 255;
         4439  +	    }
         4440  +      }
         4441  +}
         4442  +
         4443  +RL2_PRIVATE int
         4444  +rl2_copy_raw_mask (rl2RasterPtr raster, unsigned char *maskbuf,
         4445  +		   unsigned int width,
         4446  +		   unsigned int height, double x_res, double y_res,
         4447  +		   double minx, double maxy, double tile_minx, double tile_maxy)
         4448  +{
         4449  +/* copying a raw transparency mask into the output buffer */
         4450  +    unsigned int tile_width;
         4451  +    unsigned int tile_height;
         4452  +    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
         4453  +
         4454  +    if (rl2_get_raster_size (raster, &tile_width, &tile_height) != RL2_OK)
         4455  +	return 0;
         4456  +
         4457  +    if (rst->maskBuffer == NULL)
         4458  +      {
         4459  +	  /* tile without mask - ok */
         4460  +	  return 1;
         4461  +      }
         4462  +    do_copy_raw_mask (rst, maskbuf, width, height, x_res, y_res, minx, maxy,
         4463  +		      tile_minx, tile_maxy, tile_width, tile_height);
         4464  +    return 1;
         4465  +}
  4368   4466   
  4369   4467   static void
  4370   4468   get_int8_ennuple (const char *rawbuf, unsigned short row, unsigned short col,
  4371   4469   		  unsigned short row_stride, rl2PixelPtr no_data,
  4372   4470   		  double ennuple[], int *has_no_data)
  4373   4471   {
  4374   4472   /* extracting a 3x3 "super-pixel" - INT8 */
................................................................................
  4451   4549   	  /* checking for NoData values */
  4452   4550   	  if (ennuple[i] == nd_val)
  4453   4551   	      *has_no_data = 1;
  4454   4552         }
  4455   4553   }
  4456   4554   
  4457   4555   static void
  4458         -get_int16_ennuple (const short *rawbuf, unsigned short row, unsigned short col,
  4459         -		   unsigned short row_stride, rl2PixelPtr no_data,
  4460         -		   double ennuple[], int *has_no_data)
         4556  +get_int16_ennuple (const short *rawbuf, unsigned short row,
         4557  +		   unsigned short col, unsigned short row_stride,
         4558  +		   rl2PixelPtr no_data, double ennuple[], int *has_no_data)
  4461   4559   {
  4462   4560   /* extracting a 3x3 "super-pixel" - INT16 */
  4463   4561       const short *p_in;
  4464   4562       short nd_val = 0;
  4465   4563       int i;
  4466   4564   
  4467   4565       if (no_data != NULL)
................................................................................
  4627   4725   	  /* checking for NoData values */
  4628   4726   	  if (ennuple[i] == nd_val)
  4629   4727   	      *has_no_data = 1;
  4630   4728         }
  4631   4729   }
  4632   4730   
  4633   4731   static void
  4634         -get_float_ennuple (const float *rawbuf, unsigned short row, unsigned short col,
  4635         -		   unsigned short row_stride, rl2PixelPtr no_data,
  4636         -		   double ennuple[], int *has_no_data)
         4732  +get_float_ennuple (const float *rawbuf, unsigned short row,
         4733  +		   unsigned short col, unsigned short row_stride,
         4734  +		   rl2PixelPtr no_data, double ennuple[], int *has_no_data)
  4637   4735   {
  4638   4736   /* extracting a 3x3 "super-pixel" - FLOAT */
  4639   4737       const float *p_in;
  4640   4738       float nd_val = 0.0;
  4641   4739       int i;
  4642   4740   
  4643   4741       if (no_data != NULL)
................................................................................
  4937   5035   	      free (shadower->opaque_thread_id);
  4938   5036   	  shadower->opaque_thread_id = NULL;
  4939   5037         }
  4940   5038   }
  4941   5039   
  4942   5040   RL2_PRIVATE int
  4943   5041   rl2_build_shaded_relief_mask (sqlite3 * handle, int max_threads,
  4944         -			      rl2CoveragePtr cvg, double relief_factor,
  4945         -			      double scale_factor, unsigned int width,
  4946         -			      unsigned int height, double minx, double miny,
  4947         -			      double maxx, double maxy, double x_res,
  4948         -			      double y_res, float **shaded_relief,
  4949         -			      int *shaded_relief_sz)
         5042  +			      rl2CoveragePtr cvg,
         5043  +			      int by_section, sqlite3_int64 section_id,
         5044  +			      double relief_factor, double scale_factor,
         5045  +			      unsigned int width, unsigned int height,
         5046  +			      double minx, double miny, double maxx,
         5047  +			      double maxy, double x_res, double y_res,
         5048  +			      float **shaded_relief, int *shaded_relief_sz)
  4950   5049   {
  4951   5050   /* attempting to return a Shaded Relief mask from the DBMS Coverage */
  4952   5051       rl2PixelPtr no_data = NULL;
  4953   5052       const char *coverage;
  4954   5053       unsigned char level;
  4955   5054       unsigned char scale;
  4956   5055       double xx_res = x_res;
................................................................................
  4981   5080   
  4982   5081       if (cvg == NULL || handle == NULL)
  4983   5082   	goto error;
  4984   5083       coverage = rl2_get_coverage_name (cvg);
  4985   5084       if (coverage == NULL)
  4986   5085   	goto error;
  4987   5086       if (rl2_find_matching_resolution
  4988         -	(handle, cvg, 0, 0, &xx_res, &yy_res, &level, &scale) != RL2_OK)
         5087  +	(handle, cvg, by_section, section_id, &xx_res, &yy_res, &level,
         5088  +	 &scale) != RL2_OK)
  4989   5089   	goto error;
  4990   5090       if (rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands) !=
  4991   5091   	RL2_OK)
  4992   5092   	goto error;
  4993   5093       if (pixel_type != RL2_PIXEL_DATAGRID && num_bands != 1)
  4994   5094   	goto error;
  4995   5095       no_data = rl2_get_coverage_no_data (cvg);
................................................................................
  4996   5096       if (no_data == NULL)
  4997   5097   	goto error;
  4998   5098   
  4999   5099   /* preparing the "tiles" SQL query */
  5000   5100       xtiles = sqlite3_mprintf ("%s_tiles", coverage);
  5001   5101       xxtiles = rl2_double_quoted_sql (xtiles);
  5002   5102       sql =
  5003         -	sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
  5004         -			 "FROM \"%s\" "
  5005         -			 "WHERE pyramid_level = ? AND ROWID IN ( "
  5006         -			 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
  5007         -			 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles,
  5008         -			 xtiles);
         5103  +	sqlite3_mprintf
         5104  +	("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
         5105  +	 "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( "
         5106  +	 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
         5107  +	 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
  5009   5108       sqlite3_free (xtiles);
  5010   5109       free (xxtiles);
  5011   5110       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
  5012   5111       sqlite3_free (sql);
  5013   5112       if (ret != SQLITE_OK)
  5014   5113         {
  5015   5114   	  printf ("SELECT shadedRelief tiles SQL error: %s\n",
................................................................................
  5112   5211   	  /* executing in a single thread */
  5113   5212   	  p_out = sr_mask;
  5114   5213   	  for (row = 0; row < height; row++)
  5115   5214   	    {
  5116   5215   		for (col = 0; col < width; col++)
  5117   5216   		    *p_out++ =
  5118   5217   			shaded_relief_value (relief_factor, scale_factor,
  5119         -					     altRadians, azRadians, rawbuf, row,
  5120         -					     col, row_stride, sample_type,
  5121         -					     no_data);
         5218  +					     altRadians, azRadians, rawbuf,
         5219  +					     row, col, row_stride,
         5220  +					     sample_type, no_data);
  5122   5221   	    }
  5123   5222         }
  5124   5223       else
  5125   5224         {
  5126   5225   	  /* executing as many concurrent threads */
  5127   5226   	  rl2AuxShadowerPtr aux = NULL;
  5128   5227   	  rl2AuxShadowerPtr shadower;

Changes to src/rl2raw.c.

   367    367   		  }
   368    368   		break;
   369    369   	    case RL2_PIXEL_GRAYSCALE:
   370    370   		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
   371    371   				  &transpR, &transpG, &transpB);
   372    372   		break;
   373    373   	    case RL2_PIXEL_RGB:
   374         -		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
   375         -					    &transpR);
          374  +		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
          375  +					    RL2_RED_BAND, &transpR);
   376    376   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   377    377   					    RL2_GREEN_BAND, &transpG);
   378    378   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   379    379   					    RL2_BLUE_BAND, &transpB);
   380    380   		break;
   381    381   	    };
   382    382         }
................................................................................
   601    601   		  }
   602    602   		break;
   603    603   	    case RL2_PIXEL_GRAYSCALE:
   604    604   		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
   605    605   				  &transpR, &transpG, &transpB);
   606    606   		break;
   607    607   	    case RL2_PIXEL_RGB:
   608         -		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
   609         -					    &transpR);
          608  +		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
          609  +					    RL2_RED_BAND, &transpR);
   610    610   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   611    611   					    RL2_GREEN_BAND, &transpG);
   612    612   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   613    613   					    RL2_BLUE_BAND, &transpB);
   614    614   		break;
   615    615   	    };
   616    616         }
................................................................................
   889    889   		  }
   890    890   		break;
   891    891   	    case RL2_PIXEL_GRAYSCALE:
   892    892   		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
   893    893   				  &transpR, &transpG, &transpB);
   894    894   		break;
   895    895   	    case RL2_PIXEL_RGB:
   896         -		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
   897         -					    &transpR);
          896  +		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
          897  +					    RL2_RED_BAND, &transpR);
   898    898   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   899    899   					    RL2_GREEN_BAND, &transpG);
   900    900   		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
   901    901   					    RL2_BLUE_BAND, &transpB);
   902    902   		break;
   903    903   	    };
   904    904         }
................................................................................
  1506   1506   
  1507   1507       *buffer = buf;
  1508   1508       *buf_size = sz;
  1509   1509       return RL2_OK;
  1510   1510   }
  1511   1511   
  1512   1512   RL2_DECLARE int
  1513         -rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band, unsigned short **buffer,
  1514         -			   int *buf_size)
         1513  +rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band,
         1514  +			   unsigned short **buffer, int *buf_size)
  1515   1515   {
  1516   1516   /* attempting to export Raster BAND data as a UINT-16 array */
  1517   1517       unsigned short *buf;
  1518   1518       int sz;
  1519   1519       unsigned int row;
  1520   1520       unsigned int col;
  1521   1521       int nBand;
................................................................................
  1971   1971   	    }
  1972   1972         }
  1973   1973   }
  1974   1974   
  1975   1975   RL2_PRIVATE unsigned char *
  1976   1976   rl2_copy_endian_raw_pixels (const unsigned char *pixels, int pixels_sz,
  1977   1977   			    unsigned int width, unsigned int height,
  1978         -			    unsigned char sample_type, unsigned char num_bands,
  1979         -			    int big_endian)
         1978  +			    unsigned char sample_type,
         1979  +			    unsigned char num_bands, int big_endian)
  1980   1980   {
  1981   1981   /* copying RAW pixels (in endian safe mode) */
  1982   1982       int sample_bytes = 0;
  1983   1983       int outsize = width * height * num_bands;
  1984   1984       unsigned char *outbuf = NULL;
  1985   1985   
  1986   1986       switch (sample_type)
................................................................................
  2022   2022   	  copy_endian_raw_u8 (outbuf, pixels, width, height, num_bands);
  2023   2023   	  break;
  2024   2024         case RL2_SAMPLE_INT8:
  2025   2025   	  copy_endian_raw_i8 ((char *) outbuf, (const char *) pixels, width,
  2026   2026   			      height, num_bands);
  2027   2027   	  break;
  2028   2028         case RL2_SAMPLE_INT16:
  2029         -	  copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels, width,
  2030         -			       height, num_bands, big_endian);
         2029  +	  copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels,
         2030  +			       width, height, num_bands, big_endian);
  2031   2031   	  break;
  2032   2032         case RL2_SAMPLE_UINT16:
  2033   2033   	  copy_endian_raw_u16 ((unsigned short *) outbuf,
  2034   2034   			       (const unsigned short *) pixels, width, height,
  2035   2035   			       num_bands, big_endian);
  2036   2036   	  break;
  2037   2037         case RL2_SAMPLE_INT32:
................................................................................
  2040   2040   	  break;
  2041   2041         case RL2_SAMPLE_UINT32:
  2042   2042   	  copy_endian_raw_u32 ((unsigned int *) outbuf,
  2043   2043   			       (const unsigned int *) pixels, width, height,
  2044   2044   			       num_bands, big_endian);
  2045   2045   	  break;
  2046   2046         case RL2_SAMPLE_FLOAT:
  2047         -	  copy_endian_raw_flt ((float *) outbuf, (const float *) pixels, width,
  2048         -			       height, num_bands, big_endian);
         2047  +	  copy_endian_raw_flt ((float *) outbuf, (const float *) pixels,
         2048  +			       width, height, num_bands, big_endian);
  2049   2049   	  break;
  2050   2050         case RL2_SAMPLE_DOUBLE:
  2051   2051   	  copy_endian_raw_dbl ((double *) outbuf, (const double *) pixels,
  2052   2052   			       width, height, num_bands, big_endian);
  2053   2053   	  break;
  2054   2054         };
  2055   2055       return outbuf;
................................................................................
  2065   2065   	&& coverage->nBands == raster->nBands)
  2066   2066   	return 1;
  2067   2067       fprintf (stderr, "Mismatching RAW pixels !!!\n");
  2068   2068       return 0;
  2069   2069   }
  2070   2070   
  2071   2071   static void
  2072         -copy_tile_raw_i8 (const char *in, unsigned int in_width, unsigned int in_height,
  2073         -		  unsigned int startRow, unsigned int startCol, char *out,
  2074         -		  unsigned int tileWidth, unsigned int tileHeight,
  2075         -		  unsigned char num_bands)
         2072  +copy_tile_raw_i8 (const char *in, unsigned int in_width,
         2073  +		  unsigned int in_height, unsigned int startRow,
         2074  +		  unsigned int startCol, char *out, unsigned int tileWidth,
         2075  +		  unsigned int tileHeight, unsigned char num_bands)
  2076   2076   {
  2077   2077   /* signed int8 */
  2078   2078       unsigned int x;
  2079   2079       unsigned int y;
  2080   2080       unsigned char b;
  2081   2081       for (y = 0; y < tileHeight; y++)
  2082   2082         {
................................................................................
  2187   2187   		for (b = 0; b < num_bands; b++)
  2188   2188   		    *p_out++ = *p_in++;
  2189   2189   	    }
  2190   2190         }
  2191   2191   }
  2192   2192   
  2193   2193   static void
  2194         -copy_tile_raw_i32 (const int *in, unsigned int in_width, unsigned int in_height,
  2195         -		   unsigned int startRow, unsigned int startCol, int *out,
  2196         -		   unsigned int tileWidth, unsigned int tileHeight,
  2197         -		   unsigned char num_bands)
         2194  +copy_tile_raw_i32 (const int *in, unsigned int in_width,
         2195  +		   unsigned int in_height, unsigned int startRow,
         2196  +		   unsigned int startCol, int *out, unsigned int tileWidth,
         2197  +		   unsigned int tileHeight, unsigned char num_bands)
  2198   2198   {
  2199   2199   /* signed int32 */
  2200   2200       unsigned int x;
  2201   2201       unsigned int y;
  2202   2202       unsigned char b;
  2203   2203       for (y = 0; y < tileHeight; y++)
  2204   2204         {
................................................................................
  2309   2309   		    *p_out++ = *p_in++;
  2310   2310   	    }
  2311   2311         }
  2312   2312   }
  2313   2313   
  2314   2314   static int
  2315   2315   build_tile_from_raw_pixels (rl2PrivRasterPtr origin, unsigned int tileWidth,
  2316         -			    unsigned int tileHeight, unsigned char sample_type,
         2316  +			    unsigned int tileHeight,
         2317  +			    unsigned char sample_type,
  2317   2318   			    unsigned char num_bands, unsigned int startRow,
  2318   2319   			    unsigned int startCol, rl2PixelPtr no_data,
  2319   2320   			    unsigned char **pixels, int *pixels_sz)
  2320   2321   {
  2321   2322   /* extracting a Tile from the RAW buffer */
  2322   2323       unsigned char *out;
  2323   2324       int outsz = tileWidth * tileHeight * num_bands;
................................................................................
  2349   2350         case RL2_SAMPLE_INT8:
  2350   2351   	  copy_tile_raw_i8 ((const char *) (origin->rasterBuffer),
  2351   2352   			    origin->width, origin->height, startRow, startCol,
  2352   2353   			    (char *) out, tileWidth, tileHeight, num_bands);
  2353   2354   	  break;
  2354   2355         case RL2_SAMPLE_INT16:
  2355   2356   	  copy_tile_raw_i16 ((const short *) (origin->rasterBuffer),
  2356         -			     origin->width, origin->height, startRow, startCol,
  2357         -			     (short *) out, tileWidth, tileHeight, num_bands);
         2357  +			     origin->width, origin->height, startRow,
         2358  +			     startCol, (short *) out, tileWidth, tileHeight,
         2359  +			     num_bands);
  2358   2360   	  break;
  2359   2361         case RL2_SAMPLE_UINT16:
  2360   2362   	  copy_tile_raw_u16 ((const unsigned short *) (origin->rasterBuffer),
  2361         -			     origin->width, origin->height, startRow, startCol,
  2362         -			     (unsigned short *) out, tileWidth, tileHeight,
  2363         -			     num_bands);
         2363  +			     origin->width, origin->height, startRow,
         2364  +			     startCol, (unsigned short *) out, tileWidth,
         2365  +			     tileHeight, num_bands);
  2364   2366   	  break;
  2365   2367         case RL2_SAMPLE_INT32:
  2366   2368   	  copy_tile_raw_i32 ((const int *) (origin->rasterBuffer),
  2367         -			     origin->width, origin->height, startRow, startCol,
  2368         -			     (int *) out, tileWidth, tileHeight, num_bands);
         2369  +			     origin->width, origin->height, startRow,
         2370  +			     startCol, (int *) out, tileWidth, tileHeight,
         2371  +			     num_bands);
  2369   2372   	  break;
  2370   2373         case RL2_SAMPLE_UINT32:
  2371   2374   	  copy_tile_raw_u32 ((const unsigned int *) (origin->rasterBuffer),
  2372         -			     origin->width, origin->height, startRow, startCol,
  2373         -			     (unsigned int *) out, tileWidth, tileHeight,
  2374         -			     num_bands);
         2375  +			     origin->width, origin->height, startRow,
         2376  +			     startCol, (unsigned int *) out, tileWidth,
         2377  +			     tileHeight, num_bands);
  2375   2378   	  break;
  2376   2379         case RL2_SAMPLE_FLOAT:
  2377   2380   	  copy_tile_raw_flt ((const float *) (origin->rasterBuffer),
  2378         -			     origin->width, origin->height, startRow, startCol,
  2379         -			     (float *) out, tileWidth, tileHeight, num_bands);
         2381  +			     origin->width, origin->height, startRow,
         2382  +			     startCol, (float *) out, tileWidth, tileHeight,
         2383  +			     num_bands);
  2380   2384   	  break;
  2381   2385         case RL2_SAMPLE_DOUBLE:
  2382   2386   	  copy_tile_raw_dbl ((const double *) (origin->rasterBuffer),
  2383         -			     origin->width, origin->height, startRow, startCol,
  2384         -			     (double *) out, tileWidth, tileHeight, num_bands);
         2387  +			     origin->width, origin->height, startRow,
         2388  +			     startCol, (double *) out, tileWidth, tileHeight,
         2389  +			     num_bands);
  2385   2390   	  break;
  2386   2391         default:
  2387   2392   	  copy_tile_raw_u8 ((const unsigned char *) (origin->rasterBuffer),
  2388   2393   			    origin->width, origin->height, startRow, startCol,
  2389   2394   			    (unsigned char *) out, tileWidth, tileHeight,
  2390   2395   			    num_bands);
  2391   2396   	  break;

Changes to src/rl2sql.c.

   657    657       else
   658    658         {
   659    659   	  blob_even = sqlite3_value_blob (argv[3]);
   660    660   	  blob_even_sz = sqlite3_value_bytes (argv[3]);
   661    661         }
   662    662   
   663    663       if (!get_coverage_defs
   664         -	(sqlite, coverage, &tile_width, &tile_height, &sample_type, &pixel_type,
   665         -	 &num_bands, &compression))
          664  +	(sqlite, coverage, &tile_width, &tile_height, &sample_type,
          665  +	 &pixel_type, &num_bands, &compression))
   666    666         {
   667    667   	  sqlite3_result_int (context, -1);
   668    668   	  return;
   669    669         }
   670    670       ret =
   671         -	rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height, blob_odd,
   672         -				       blob_odd_sz, blob_even, blob_even_sz,
   673         -				       sample_type, pixel_type, num_bands,
   674         -				       compression);
          671  +	rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height,
          672  +				       blob_odd, blob_odd_sz, blob_even,
          673  +				       blob_even_sz, sample_type, pixel_type,
          674  +				       num_bands, compression);
   675    675       if (ret == RL2_OK)
   676    676   	sqlite3_result_int (context, 1);
   677    677       else
   678    678   	sqlite3_result_int (context, 0);
   679    679   }
   680    680   
   681    681   static void
................................................................................
  1533   1533       if (pxl1 != NULL)
  1534   1534   	rl2_destroy_pixel (pxl1);
  1535   1535       if (pxl2 != NULL)
  1536   1536   	rl2_destroy_pixel (pxl2);
  1537   1537   }
  1538   1538   
  1539   1539   static void
  1540         -fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context, int argc,
  1541         -					    sqlite3_value ** argv)
         1540  +fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context,
         1541  +					    int argc, sqlite3_value ** argv)
  1542   1542   {
  1543   1543   /* SQL function:
  1544   1544   / GetRasterStatistics_NoDataPixelsCount(BLOBencoded statistics)
  1545   1545   /
  1546   1546   / will return the total count of NoData pixels
  1547   1547   / or NULL (INVALID ARGS)
  1548   1548   /
................................................................................
  1568   1568         }
  1569   1569       st = (rl2PrivRasterStatisticsPtr) stats;
  1570   1570       sqlite3_result_int64 (context, st->no_data);
  1571   1571       rl2_destroy_raster_statistics (stats);
  1572   1572   }
  1573   1573   
  1574   1574   static void
  1575         -fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context, int argc,
  1576         -					   sqlite3_value ** argv)
         1575  +fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context,
         1576  +					   int argc, sqlite3_value ** argv)
  1577   1577   {
  1578   1578   /* SQL function:
  1579   1579   / GetRasterStatistics_ValidPixelsCount(BLOBencoded statistics)
  1580   1580   /
  1581   1581   / will return the total count of valid pixels
  1582   1582   / or NULL (INVALID ARGS)
  1583   1583   /
................................................................................
  3883   3883   	  return;
  3884   3884         }
  3885   3885       if (rl2_get_coverage_srid (coverage, &srid) != RL2_OK)
  3886   3886         {
  3887   3887   	  sqlite3_result_int (context, -1);
  3888   3888   	  return;
  3889   3889         }
  3890         -    if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands)
  3891         -	!= RL2_OK)
         3890  +    if (rl2_get_coverage_type
         3891  +	(coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK)
  3892   3892         {
  3893   3893   	  sqlite3_result_int (context, -1);
  3894   3894   	  return;
  3895   3895         }
  3896   3896       no_data = rl2_get_coverage_no_data (coverage);
  3897   3897       if (rl2_get_coverage_compression (coverage, &compression, &quality)
  3898   3898   	!= RL2_OK)
................................................................................
  4047   4047       cvg = (rl2PrivCoveragePtr) coverage;
  4048   4048       for (y = maxy; y > miny; y -= tileh)
  4049   4049         {
  4050   4050   	  for (x = minx; x < maxx; x += tilew)
  4051   4051   	    {
  4052   4052   		char *err_msg = NULL;
  4053   4053   		unsigned char *rgba_tile =
  4054         -		    do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer,
         4054  +		    do_wms_GetMap_get (NULL, url, proxy, wms_version,
         4055  +				       wms_layer,
  4055   4056   				       wms_crs, swap_xy, x, y - tileh,
  4056   4057   				       x + tilew, y, tile_width, tile_height,
  4057   4058   				       wms_style, wms_format, opaque, 0,
  4058   4059   				       &err_msg);
  4059   4060   		if (rgba_tile == NULL)
  4060   4061   		  {
  4061   4062   		      add_retry (retry_list, x, y - tileh, x + tilew, y);
................................................................................
  4109   4110   		if (retry->done)
  4110   4111   		  {
  4111   4112   		      retry = retry->next;
  4112   4113   		      continue;
  4113   4114   		  }
  4114   4115   		retry->count += 1;
  4115   4116   		rgba_tile =
  4116         -		    do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer,
  4117         -				       wms_crs, swap_xy, retry->minx,
  4118         -				       retry->miny, retry->maxx, retry->maxy,
  4119         -				       tile_width, tile_height, wms_style,
  4120         -				       wms_format, opaque, 0, &err_msg);
         4117  +		    do_wms_GetMap_get (NULL, url, proxy, wms_version,
         4118  +				       wms_layer, wms_crs, swap_xy,
         4119  +				       retry->minx, retry->miny, retry->maxx,
         4120  +				       retry->maxy, tile_width, tile_height,
         4121  +				       wms_style, wms_format, opaque, 0,
         4122  +				       &err_msg);
  4121   4123   		if (rgba_tile == NULL)
  4122   4124   		  {
  4123   4125   		      retry = retry->next;
  4124   4126   		      continue;
  4125   4127   		  }
  4126   4128   
  4127   4129   		params.sqlite = sqlite;
................................................................................
  4485   4487   	  double ext_x = (double) width * horz_res;
  4486   4488   	  double ext_y = (double) height * vert_res;
  4487   4489   	  minx = pt_x - ext_x / 2.0;
  4488   4490   	  maxx = minx + ext_x;
  4489   4491   	  miny = pt_y - ext_y / 2.0;
  4490   4492   	  maxy = miny + ext_y;
  4491   4493         }
  4492         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  4493         -	     != RL2_OK)
         4494  +    else if (rl2_parse_bbox
         4495  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  4494   4496         {
  4495   4497   	  errcode = -1;
  4496   4498   	  goto error;
  4497   4499         }
  4498   4500   
  4499   4501   /* attempting to load the Coverage definitions from the DBMS */
  4500   4502       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  4515   4517   						    height, compression,
  4516   4518   						    tile_sz, worldfile);
  4517   4519         }
  4518   4520       else
  4519   4521         {
  4520   4522   	  /* whole Coverage */
  4521   4523   	  ret =
  4522         -	      rl2_export_geotiff_from_dbms (sqlite, max_threads, path, coverage,
  4523         -					    horz_res, vert_res, minx, miny,
  4524         -					    maxx, maxy, width, height,
  4525         -					    compression, tile_sz, worldfile);
         4524  +	      rl2_export_geotiff_from_dbms (sqlite, max_threads, path,
         4525  +					    coverage, horz_res, vert_res,
         4526  +					    minx, miny, maxx, maxy, width,
         4527  +					    height, compression, tile_sz,
         4528  +					    worldfile);
  4526   4529         }
  4527   4530       if (ret != RL2_OK)
  4528   4531         {
  4529   4532   	  errcode = 0;
  4530   4533   	  goto error;
  4531   4534         }
  4532   4535       rl2_destroy_coverage (coverage);
................................................................................
  4864   4867   	  double ext_x = (double) width * horz_res;
  4865   4868   	  double ext_y = (double) height * vert_res;
  4866   4869   	  minx = pt_x - ext_x / 2.0;
  4867   4870   	  maxx = minx + ext_x;
  4868   4871   	  miny = pt_y - ext_y / 2.0;
  4869   4872   	  maxy = miny + ext_y;
  4870   4873         }
  4871         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  4872         -	     != RL2_OK)
         4874  +    else if (rl2_parse_bbox
         4875  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  4873   4876         {
  4874   4877   	  errcode = -1;
  4875   4878   	  goto error;
  4876   4879         }
  4877   4880   
  4878   4881   /* attempting to load the Coverage definitions from the DBMS */
  4879   4882       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  4887   4890         {
  4888   4891   	  /* single Section */
  4889   4892   	  ret =
  4890   4893   	      rl2_export_section_triple_band_geotiff_from_dbms (sqlite, path,
  4891   4894   								coverage,
  4892   4895   								section_id,
  4893   4896   								horz_res,
  4894         -								vert_res, minx,
  4895         -								miny, maxx,
  4896         -								maxy, width,
  4897         -								height,
         4897  +								vert_res,
         4898  +								minx, miny,
         4899  +								maxx, maxy,
         4900  +								width, height,
  4898   4901   								red_band,
  4899   4902   								green_band,
  4900   4903   								blue_band,
  4901   4904   								compression,
  4902   4905   								tile_sz,
  4903   4906   								worldfile);
  4904   4907         }
  4905   4908       else
  4906   4909         {
  4907   4910   	  /* whole Coverage */
  4908   4911   
  4909   4912   	  ret =
  4910         -	      rl2_export_triple_band_geotiff_from_dbms (sqlite, path, coverage,
  4911         -							horz_res, vert_res,
  4912         -							minx, miny, maxx, maxy,
  4913         -							width, height, red_band,
         4913  +	      rl2_export_triple_band_geotiff_from_dbms (sqlite, path,
         4914  +							coverage, horz_res,
         4915  +							vert_res, minx, miny,
         4916  +							maxx, maxy, width,
         4917  +							height, red_band,
  4914   4918   							green_band, blue_band,
  4915   4919   							compression, tile_sz,
  4916   4920   							worldfile);
  4917   4921         }
  4918   4922       if (ret != RL2_OK)
  4919   4923         {
  4920   4924   	  errcode = 0;
................................................................................
  5244   5248   	  double ext_x = (double) width * horz_res;
  5245   5249   	  double ext_y = (double) height * vert_res;
  5246   5250   	  minx = pt_x - ext_x / 2.0;
  5247   5251   	  maxx = minx + ext_x;
  5248   5252   	  miny = pt_y - ext_y / 2.0;
  5249   5253   	  maxy = miny + ext_y;
  5250   5254         }
  5251         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  5252         -	     != RL2_OK)
         5255  +    else if (rl2_parse_bbox
         5256  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  5253   5257         {
  5254   5258   	  errcode = -1;
  5255   5259   	  goto error;
  5256   5260         }
  5257   5261   
  5258   5262   /* attempting to load the Coverage definitions from the DBMS */
  5259   5263       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  5268   5272   	  /* single Section */
  5269   5273   	  ret =
  5270   5274   	      rl2_export_section_mono_band_geotiff_from_dbms (sqlite, path,
  5271   5275   							      coverage,
  5272   5276   							      section_id,
  5273   5277   							      horz_res,
  5274   5278   							      vert_res, minx,
  5275         -							      miny, maxx, maxy,
  5276         -							      width, height,
         5279  +							      miny, maxx,
         5280  +							      maxy, width,
         5281  +							      height,
  5277   5282   							      mono_band,
  5278   5283   							      compression,
  5279   5284   							      tile_sz,
  5280   5285   							      worldfile);
  5281   5286         }
  5282   5287       else
  5283   5288         {
  5284   5289   	  /* whole Coverage */
  5285   5290   	  ret =
  5286   5291   	      rl2_export_mono_band_geotiff_from_dbms (sqlite, path, coverage,
  5287         -						      horz_res, vert_res, minx,
  5288         -						      miny, maxx, maxy, width,
  5289         -						      height, mono_band,
  5290         -						      compression, tile_sz,
  5291         -						      worldfile);
         5292  +						      horz_res, vert_res,
         5293  +						      minx, miny, maxx, maxy,
         5294  +						      width, height,
         5295  +						      mono_band, compression,
         5296  +						      tile_sz, worldfile);
  5292   5297         }
  5293   5298   
  5294   5299       if (ret != RL2_OK)
  5295   5300         {
  5296   5301   	  errcode = 0;
  5297   5302   	  goto error;
  5298   5303         }
................................................................................
  5598   5603   	  double ext_x = (double) width * horz_res;
  5599   5604   	  double ext_y = (double) height * vert_res;
  5600   5605   	  minx = pt_x - ext_x / 2.0;
  5601   5606   	  maxx = minx + ext_x;
  5602   5607   	  miny = pt_y - ext_y / 2.0;
  5603   5608   	  maxy = miny + ext_y;
  5604   5609         }
  5605         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  5606         -	     != RL2_OK)
         5610  +    else if (rl2_parse_bbox
         5611  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  5607   5612         {
  5608   5613   	  errcode = -1;
  5609   5614   	  goto error;
  5610   5615         }
  5611   5616   
  5612   5617   /* attempting to load the Coverage definitions from the DBMS */
  5613   5618       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  5621   5626   	  /* only a single Section */
  5622   5627   	  if (with_worldfile)
  5623   5628   	    {
  5624   5629   		/* TIFF + Worldfile */
  5625   5630   		ret =
  5626   5631   		    rl2_export_section_tiff_worldfile_from_dbms (sqlite,
  5627   5632   								 max_threads,
  5628         -								 path, coverage,
         5633  +								 path,
         5634  +								 coverage,
  5629   5635   								 section_id,
  5630   5636   								 horz_res,
  5631         -								 vert_res, minx,
  5632         -								 miny, maxx,
  5633         -								 maxy, width,
         5637  +								 vert_res,
         5638  +								 minx, miny,
         5639  +								 maxx, maxy,
         5640  +								 width,
  5634   5641   								 height,
  5635   5642   								 compression,
  5636   5643   								 tile_sz);
  5637   5644   	    }
  5638   5645   	  else
  5639   5646   	    {
  5640   5647   		/* plain TIFF, no Worldfile */
................................................................................
  5654   5661   	  if (with_worldfile)
  5655   5662   	    {
  5656   5663   		/* TIFF + Worldfile */
  5657   5664   		ret =
  5658   5665   		    rl2_export_tiff_worldfile_from_dbms (sqlite, max_threads,
  5659   5666   							 path, coverage,
  5660   5667   							 horz_res, vert_res,
  5661         -							 minx, miny, maxx, maxy,
  5662         -							 width, height,
         5668  +							 minx, miny, maxx,
         5669  +							 maxy, width, height,
  5663   5670   							 compression, tile_sz);
  5664   5671   	    }
  5665   5672   	  else
  5666   5673   	    {
  5667   5674   		/* plain TIFF, no Worldfile */
  5668   5675   		ret =
  5669   5676   		    rl2_export_tiff_from_dbms (sqlite, max_threads, path,
................................................................................
  5969   5976   	  double ext_x = (double) width * horz_res;
  5970   5977   	  double ext_y = (double) height * vert_res;
  5971   5978   	  minx = pt_x - ext_x / 2.0;
  5972   5979   	  maxx = minx + ext_x;
  5973   5980   	  miny = pt_y - ext_y / 2.0;
  5974   5981   	  maxy = miny + ext_y;
  5975   5982         }
  5976         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  5977         -	     != RL2_OK)
         5983  +    else if (rl2_parse_bbox
         5984  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  5978   5985         {
  5979   5986   	  errcode = -1;
  5980   5987   	  goto error;
  5981   5988         }
  5982   5989   
  5983   5990   /* attempting to load the Coverage definitions from the DBMS */
  5984   5991       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  5989   5996         }
  5990   5997   
  5991   5998       if (by_section)
  5992   5999         {
  5993   6000   	  /* single Section */
  5994   6001   	  ret =
  5995   6002   	      rl2_export_section_jpeg_from_dbms (sqlite, max_threads, path,
  5996         -						 coverage, section_id, horz_res,
  5997         -						 vert_res, minx, miny, maxx,
  5998         -						 maxy, width, height, quality,
         6003  +						 coverage, section_id,
         6004  +						 horz_res, vert_res, minx,
         6005  +						 miny, maxx, maxy, width,
         6006  +						 height, quality,
  5999   6007   						 with_worldfile);
  6000   6008         }
  6001   6009       else
  6002   6010         {
  6003   6011   	  /* whole Coverage */
  6004   6012   	  ret =
  6005   6013   	      rl2_export_jpeg_from_dbms (sqlite, max_threads, path, coverage,
................................................................................
  6366   6374   	  double ext_x = (double) width * horz_res;
  6367   6375   	  double ext_y = (double) height * vert_res;
  6368   6376   	  minx = pt_x - ext_x / 2.0;
  6369   6377   	  maxx = minx + ext_x;
  6370   6378   	  miny = pt_y - ext_y / 2.0;
  6371   6379   	  maxy = miny + ext_y;
  6372   6380         }
  6373         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  6374         -	     != RL2_OK)
         6381  +    else if (rl2_parse_bbox
         6382  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  6375   6383         {
  6376   6384   	  errcode = -1;
  6377   6385   	  goto error;
  6378   6386         }
  6379   6387   
  6380   6388   /* attempting to load the Coverage definitions from the DBMS */
  6381   6389       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  6397   6405   		     minx, miny, maxx, maxy, width, height, red_band,
  6398   6406   		     green_band, blue_band, compression, tile_sz);
  6399   6407   	    }
  6400   6408   	  else
  6401   6409   	    {
  6402   6410   		/* plain TIFF, no Worldfile */
  6403   6411   		ret =
  6404         -		    rl2_export_section_triple_band_tiff_from_dbms (sqlite, path,
         6412  +		    rl2_export_section_triple_band_tiff_from_dbms (sqlite,
         6413  +								   path,
  6405   6414   								   coverage,
  6406   6415   								   section_id,
  6407   6416   								   horz_res,
  6408   6417   								   vert_res,
  6409   6418   								   minx, miny,
  6410   6419   								   maxx, maxy,
  6411   6420   								   width,
................................................................................
  6425   6434   		/* TIFF + Worldfile */
  6426   6435   		ret =
  6427   6436   		    rl2_export_triple_band_tiff_worldfile_from_dbms (sqlite,
  6428   6437   								     path,
  6429   6438   								     coverage,
  6430   6439   								     horz_res,
  6431   6440   								     vert_res,
  6432         -								     minx, miny,
  6433         -								     maxx, maxy,
         6441  +								     minx,
         6442  +								     miny,
         6443  +								     maxx,
         6444  +								     maxy,
  6434   6445   								     width,
  6435   6446   								     height,
  6436   6447   								     red_band,
  6437   6448   								     green_band,
  6438   6449   								     blue_band,
  6439   6450   								     compression,
  6440   6451   								     tile_sz);
................................................................................
  6441   6452   	    }
  6442   6453   	  else
  6443   6454   	    {
  6444   6455   		/* plain TIFF, no Worldfile */
  6445   6456   		ret =
  6446   6457   		    rl2_export_triple_band_tiff_from_dbms (sqlite, path,
  6447   6458   							   coverage, horz_res,
  6448         -							   vert_res, minx, miny,
  6449         -							   maxx, maxy, width,
  6450         -							   height, red_band,
         6459  +							   vert_res, minx,
         6460  +							   miny, maxx, maxy,
         6461  +							   width, height,
         6462  +							   red_band,
  6451   6463   							   green_band,
  6452   6464   							   blue_band,
  6453   6465   							   compression,
  6454   6466   							   tile_sz);
  6455   6467   	    }
  6456   6468         }
  6457   6469       if (ret != RL2_OK)
................................................................................
  6815   6827   	  double ext_x = (double) width * horz_res;
  6816   6828   	  double ext_y = (double) height * vert_res;
  6817   6829   	  minx = pt_x - ext_x / 2.0;
  6818   6830   	  maxx = minx + ext_x;
  6819   6831   	  miny = pt_y - ext_y / 2.0;
  6820   6832   	  maxy = miny + ext_y;
  6821   6833         }
  6822         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  6823         -	     != RL2_OK)
         6834  +    else if (rl2_parse_bbox
         6835  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  6824   6836         {
  6825   6837   	  errcode = -1;
  6826   6838   	  goto error;
  6827   6839         }
  6828   6840   
  6829   6841   /* attempting to load the Coverage definitions from the DBMS */
  6830   6842       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  6850   6862   	    {
  6851   6863   		/* plain TIFF, no Worldfile */
  6852   6864   		ret =
  6853   6865   		    rl2_export_section_mono_band_tiff_from_dbms (sqlite, path,
  6854   6866   								 coverage,
  6855   6867   								 section_id,
  6856   6868   								 horz_res,
  6857         -								 vert_res, minx,
  6858         -								 miny, maxx,
  6859         -								 maxy, width,
         6869  +								 vert_res,
         6870  +								 minx, miny,
         6871  +								 maxx, maxy,
         6872  +								 width,
  6860   6873   								 height,
  6861   6874   								 mono_band,
  6862   6875   								 compression,
  6863   6876   								 tile_sz);
  6864   6877   	    }
  6865   6878         }
  6866   6879       else
  6867   6880         {
  6868   6881   	  /* whole Coverage */
  6869   6882   	  if (with_worldfile)
  6870   6883   	    {
  6871   6884   		/* TIFF + Worldfile */
  6872   6885   		ret =
  6873         -		    rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite, path,
         6886  +		    rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite,
         6887  +								   path,
  6874   6888   								   coverage,
  6875   6889   								   horz_res,
  6876   6890   								   vert_res,
  6877   6891   								   minx, miny,
  6878   6892   								   maxx, maxy,
  6879   6893   								   width,
  6880   6894   								   height,
................................................................................
  6882   6896   								   compression,
  6883   6897   								   tile_sz);
  6884   6898   	    }
  6885   6899   	  else
  6886   6900   	    {
  6887   6901   		/* plain TIFF, no Worldfile */
  6888   6902   		ret =
  6889         -		    rl2_export_mono_band_tiff_from_dbms (sqlite, path, coverage,
  6890         -							 horz_res, vert_res,
  6891         -							 minx, miny, maxx, maxy,
  6892         -							 width, height,
  6893         -							 mono_band, compression,
  6894         -							 tile_sz);
         6903  +		    rl2_export_mono_band_tiff_from_dbms (sqlite, path,
         6904  +							 coverage, horz_res,
         6905  +							 vert_res, minx, miny,
         6906  +							 maxx, maxy, width,
         6907  +							 height, mono_band,
         6908  +							 compression, tile_sz);
  6895   6909   	    }
  6896   6910         }
  6897   6911       if (ret != RL2_OK)
  6898   6912         {
  6899   6913   	  errcode = 0;
  6900   6914   	  goto error;
  6901   6915         }
................................................................................
  7188   7202   	  double ext_x = (double) width * resolution;
  7189   7203   	  double ext_y = (double) height * resolution;
  7190   7204   	  minx = pt_x - ext_x / 2.0;
  7191   7205   	  maxx = minx + ext_x;
  7192   7206   	  miny = pt_y - ext_y / 2.0;
  7193   7207   	  maxy = miny + ext_y;
  7194   7208         }
  7195         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  7196         -	     != RL2_OK)
         7209  +    else if (rl2_parse_bbox
         7210  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  7197   7211         {
  7198   7212   	  errcode = -1;
  7199   7213   	  goto error;
  7200   7214         }
  7201   7215   
  7202   7216   /* attempting to load the Coverage definitions from the DBMS */
  7203   7217       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  7220   7234   						       decimal_digits);
  7221   7235         }
  7222   7236       else
  7223   7237         {
  7224   7238   	  /* whole Coverage */
  7225   7239   	  ret =
  7226   7240   	      rl2_export_ascii_grid_from_dbms (sqlite, max_threads, path,
  7227         -					       coverage, resolution, minx, miny,
  7228         -					       maxx, maxy, width, height,
  7229         -					       is_centered, decimal_digits);
         7241  +					       coverage, resolution, minx,
         7242  +					       miny, maxx, maxy, width,
         7243  +					       height, is_centered,
         7244  +					       decimal_digits);
  7230   7245         }
  7231   7246       if (ret != RL2_OK)
  7232   7247         {
  7233   7248   	  errcode = 0;
  7234   7249   	  goto error;
  7235   7250         }
  7236   7251       rl2_destroy_coverage (coverage);
................................................................................
  7477   7492   	  double ext_x = (double) width * resolution;
  7478   7493   	  double ext_y = (double) height * resolution;
  7479   7494   	  minx = pt_x - ext_x / 2.0;
  7480   7495   	  maxx = minx + ext_x;
  7481   7496   	  miny = pt_y - ext_y / 2.0;
  7482   7497   	  maxy = miny + ext_y;
  7483   7498         }
  7484         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  7485         -	     != RL2_OK)
         7499  +    else if (rl2_parse_bbox
         7500  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  7486   7501         {
  7487   7502   	  errcode = -1;
  7488   7503   	  goto error;
  7489   7504         }
  7490   7505   
  7491   7506   /* attempting to load the Coverage definitions from the DBMS */
  7492   7507       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
  7496   7511   	  return;
  7497   7512         }
  7498   7513   
  7499   7514       if (by_section)
  7500   7515         {
  7501   7516   	  /* single Section */
  7502   7517   	  ret =
  7503         -	      rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite, max_threads,
  7504         -							    path, coverage,
         7518  +	      rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite,
         7519  +							    max_threads, path,
         7520  +							    coverage,
  7505   7521   							    section_id,
  7506   7522   							    resolution, minx,
  7507   7523   							    miny, maxx, maxy,
  7508   7524   							    width, height,
  7509         -							    red_band, nir_band,
         7525  +							    red_band,
         7526  +							    nir_band,
  7510   7527   							    is_centered,
  7511   7528   							    decimal_digits);
  7512   7529         }
  7513   7530       else
  7514   7531         {
  7515   7532   	  /* whole Coverage */
  7516   7533   	  ret =
  7517   7534   	      rl2_export_ndvi_ascii_grid_from_dbms (sqlite, max_threads, path,
  7518         -						    coverage, resolution, minx,
  7519         -						    miny, maxx, maxy, width,
  7520         -						    height, red_band, nir_band,
  7521         -						    is_centered,
         7535  +						    coverage, resolution,
         7536  +						    minx, miny, maxx, maxy,
         7537  +						    width, height, red_band,
         7538  +						    nir_band, is_centered,
  7522   7539   						    decimal_digits);
  7523   7540         }
  7524   7541       if (ret != RL2_OK)
  7525   7542         {
  7526   7543   	  errcode = 0;
  7527   7544   	  goto error;
  7528   7545         }
................................................................................
  7579   7596   /
  7580   7597   / will return 1 (TRUE, success) or 0 (FALSE, failure)
  7581   7598   / or -1 (INVALID ARGS)
  7582   7599   /
  7583   7600   */
  7584   7601       common_write_ndvi_ascii_grid (1, context, argc, argv);
  7585   7602   }
         7603  +
         7604  +static int
         7605  +test_geographic_srid (sqlite3 * handle, int srid)
         7606  +{
         7607  +/* testing if some SRID is of the Geographic type */
         7608  +    int ret;
         7609  +    int is_geographic = 0;
         7610  +    sqlite3_stmt *stmt = NULL;
         7611  +    const char *sql;
         7612  +
         7613  +    sql = "SELECT SridIsGeographic(?)";
         7614  +    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
         7615  +    if (ret != SQLITE_OK)
         7616  +	return 0;
         7617  +
         7618  +    sqlite3_reset (stmt);
         7619  +    sqlite3_clear_bindings (stmt);
         7620  +    sqlite3_bind_int (stmt, 1, srid);
         7621  +    while (1)
         7622  +      {
         7623  +	  /* scrolling the result set rows */
         7624  +	  ret = sqlite3_step (stmt);
         7625  +	  if (ret == SQLITE_DONE)
         7626  +	      break;		/* end of result set */
         7627  +	  if (ret == SQLITE_ROW)
         7628  +	      is_geographic = sqlite3_column_int (stmt, 0);
         7629  +      }
         7630  +    sqlite3_finalize (stmt);
         7631  +    return is_geographic;
         7632  +}
         7633  +
         7634  +static double
         7635  +standard_scale (sqlite3 * handle, int srid, int width, int height,
         7636  +		double ext_x, double ext_y)
         7637  +{
         7638  +/* computing the standard (normalized) scale */
         7639  +    double linear_res;
         7640  +    double factor;
         7641  +    int is_geographic = test_geographic_srid (handle, srid);
         7642  +    if (is_geographic)
         7643  +      {
         7644  +	  /* geographic (long/lat) CRS */
         7645  +	  double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0;
         7646  +	  linear_res = metres / (double) width;
         7647  +      }
         7648  +    else
         7649  +      {
         7650  +	  /* planar (projected) CRS */
         7651  +	  double x_res = ext_x / (double) width;
         7652  +	  double y_res = ext_y / (double) height;
         7653  +	  linear_res = sqrt (x_res * y_res);
         7654  +      }
         7655  +    factor = linear_res / 0.000254;
         7656  +    return factor * (0.28 / 0.254);
         7657  +}
  7586   7658   
  7587   7659   static void
  7588   7660   fnct_GetMapImageFromRaster (sqlite3_context * context, int argc,
  7589   7661   			    sqlite3_value ** argv)
  7590   7662   {
  7591   7663   /* SQL function:
  7592   7664   / GetMapImageFromRaster(text coverage, BLOB geom, int width, int height)
................................................................................
  7641   7713       double ext_y;
  7642   7714       double x_res;
  7643   7715       double y_res;
  7644   7716       int srid;
  7645   7717       int level_id;
  7646   7718       int scale;
  7647   7719       int xscale;
         7720  +    double map_scale;
  7648   7721       double xx_res;
  7649   7722       double yy_res;
  7650   7723       double aspect_org;
  7651   7724       double aspect_dst;
  7652   7725       int ok_style;
  7653   7726       int ok_format;
  7654   7727       unsigned char *outbuf = NULL;
................................................................................
  7790   7863   	  aux.reaspect = reaspect;
  7791   7864   	  rl2_aux_group_renderer (&aux);
  7792   7865   	  return;
  7793   7866         }
  7794   7867   
  7795   7868       x_res = ext_x / (double) width;
  7796   7869       y_res = ext_y / (double) height;
         7870  +    map_scale = standard_scale (sqlite, out_srid, width, height, ext_x, ext_y);
  7797   7871   /* validating the style */
  7798   7872       ok_style = 0;
  7799   7873       if (strcasecmp (style, "default") == 0)
  7800   7874   	ok_style = 1;
  7801   7875       else
  7802   7876         {
  7803   7877   	  /* attempting to get a Coverage Style */
  7804   7878   	  cvg_stl =
  7805   7879   	      rl2_create_coverage_style_from_dbms (sqlite, cvg_name, style);
  7806   7880   	  if (cvg_stl == NULL)
  7807   7881   	      goto error;
  7808         -	  symbolizer = rl2_get_symbolizer_from_coverage_style (cvg_stl, 1.0);
         7882  +	  symbolizer =
         7883  +	      rl2_get_symbolizer_from_coverage_style (cvg_stl, map_scale);
  7809   7884   	  if (symbolizer == NULL)
  7810         -	      goto error;
         7885  +	    {
         7886  +		/* invisible at the currect scale */
         7887  +		if (!rl2_aux_default_image
         7888  +		    (width, height, bg_red, bg_green, bg_blue, format_id,
         7889  +		     transparent, quality, &image, &image_size))
         7890  +		    goto error;
         7891  +		goto done;
         7892  +	    }
  7811   7893   	  stats = rl2_create_raster_statistics_from_dbms (sqlite, cvg_name);
  7812   7894   	  if (stats == NULL)
  7813   7895   	      goto error;
  7814   7896   	  ok_style = 1;
  7815   7897         }
  7816   7898       if (!ok_style)
  7817   7899   	goto error;
................................................................................
  7976   8058         }
  7977   8059       else
  7978   8060         {
  7979   8061   	  /* ordinary Coverage */
  7980   8062   	  by_section = 0;
  7981   8063   	  /* retrieving the optimal resolution level */
  7982   8064   	  if (!rl2_find_best_resolution_level
  7983         -	      (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale, &xscale,
  7984         -	       &xx_res, &yy_res))
         8065  +	      (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale,
         8066  +	       &xscale, &xx_res, &yy_res))
  7985   8067   	      goto error;
  7986   8068         }
  7987   8069       base_width = (int) (ext_x / xx_res);
  7988   8070       base_height = (int) (ext_y / yy_res);
  7989   8071       if ((base_width <= 0 && base_width >= USHRT_MAX)
  7990   8072   	|| (base_height <= 0 && base_height >= USHRT_MAX))
  7991   8073   	goto error;
................................................................................
  8096   8178       aux.symbolizer = symbolizer;
  8097   8179       aux.stats = stats;
  8098   8180       aux.outbuf = outbuf;
  8099   8181       aux.palette = palette;
  8100   8182       aux.out_pixel = out_pixel;
  8101   8183       if (!rl2_aux_render_image (&aux, &image, &image_size))
  8102   8184   	goto error;
         8185  +
         8186  +  done:
  8103   8187       sqlite3_result_blob (context, image, image_size, free);
  8104   8188       rl2_destroy_coverage (coverage);
  8105   8189       if (palette != NULL)
  8106   8190   	rl2_destroy_palette (palette);
  8107   8191       if (cvg_stl != NULL)
  8108   8192   	rl2_destroy_coverage_style (cvg_stl);
  8109   8193       if (stats != NULL)
................................................................................
  8118   8202       if (cvg_stl != NULL)
  8119   8203   	rl2_destroy_coverage_style (cvg_stl);
  8120   8204       if (stats != NULL)
  8121   8205   	rl2_destroy_raster_statistics (stats);
  8122   8206       sqlite3_result_null (context);
  8123   8207   }
  8124   8208   
  8125         -static int
  8126         -test_geographic_srid (sqlite3 * handle, int srid)
  8127         -{
  8128         -/* testing if some SRID is of the Geographic type */
  8129         -    int ret;
  8130         -    int is_geographic = 0;
  8131         -    sqlite3_stmt *stmt = NULL;
  8132         -    const char *sql;
  8133         -
  8134         -    sql = "SELECT SridIsGeographic(?)";
  8135         -    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  8136         -    if (ret != SQLITE_OK)
  8137         -	return 0;
  8138         -
  8139         -    sqlite3_reset (stmt);
  8140         -    sqlite3_clear_bindings (stmt);
  8141         -    sqlite3_bind_int (stmt, 1, srid);
  8142         -    while (1)
  8143         -      {
  8144         -	  /* scrolling the result set rows */
  8145         -	  ret = sqlite3_step (stmt);
  8146         -	  if (ret == SQLITE_DONE)
  8147         -	      break;		/* end of result set */
  8148         -	  if (ret == SQLITE_ROW)
  8149         -	      is_geographic = sqlite3_column_int (stmt, 0);
  8150         -      }
  8151         -    sqlite3_finalize (stmt);
  8152         -    return is_geographic;
  8153         -}
  8154         -
  8155         -static double
  8156         -standard_scale (sqlite3 * handle, int srid, int width, int height, double ext_x,
  8157         -		double ext_y)
  8158         -{
  8159         -/* computing the standard (normalized) scale */
  8160         -    double linear_res;
  8161         -    double factor;
  8162         -    int is_geographic = test_geographic_srid (handle, srid);
  8163         -    if (is_geographic)
  8164         -      {
  8165         -	  /* geographic (long/lat) CRS */
  8166         -	  double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0;
  8167         -	  linear_res = metres / (double) width;
  8168         -      }
  8169         -    else
  8170         -      {
  8171         -	  /* planar (projected) CRS */
  8172         -	  double x_res = ext_x / (double) width;
  8173         -	  double y_res = ext_y / (double) height;
  8174         -	  linear_res = sqrt (x_res * y_res);
  8175         -      }
  8176         -    factor = linear_res / 0.000254;
  8177         -    return factor * (0.28 / 0.254);
  8178         -}
  8179         -
  8180   8209   static void
  8181   8210   fnct_GetMapImageFromVector (sqlite3_context * context, int argc,
  8182   8211   			    sqlite3_value ** argv)
  8183   8212   {
  8184   8213   /* SQL function:
  8185   8214   / GetMapImageFromVector(text coverage, BLOB geom, int width, int height)
  8186   8215   / GetMapImageFromVector(text coverage, BLOB geom, int width, int height,
................................................................................
  8219   8248       unsigned char bg_green;
  8220   8249       unsigned char bg_blue;
  8221   8250       int transparent = 0;
  8222   8251       int quality = 80;
  8223   8252       int reaspect = 0;
  8224   8253       sqlite3 *sqlite;
  8225   8254       sqlite3_stmt *stmt = NULL;
         8255  +    const void *data;
  8226   8256       double minx;
  8227   8257       double maxx;
  8228   8258       double miny;
  8229   8259       double maxy;
  8230   8260       double ext_x;
  8231   8261       double ext_y;
  8232   8262       double x_res;
................................................................................
  8300   8330       if (argc > 8)
  8301   8331   	quality = sqlite3_value_int (argv[8]);
  8302   8332       if (argc > 9)
  8303   8333   	reaspect = sqlite3_value_int (argv[9]);
  8304   8334   
  8305   8335   /* coarse args validation */
  8306   8336       sqlite = sqlite3_context_db_handle (context);
         8337  +    data = sqlite3_user_data (context);
  8307   8338       if (width < 64)
  8308   8339   	goto error;
  8309   8340       if (height < 64)
  8310   8341   	goto error;
  8311   8342   /* validating the format */
  8312   8343       ok_format = 0;
  8313   8344       if (strcmp (format, "image/png") == 0)
................................................................................
  8501   8532   			      {
  8502   8533   			      case SQLITE_INTEGER:
  8503   8534   				  rl2_set_variant_int (variant, i, col_name,
  8504   8535   						       sqlite3_column_int64
  8505   8536   						       (stmt, i + 1));
  8506   8537   				  break;
  8507   8538   			      case SQLITE_FLOAT:
  8508         -				  rl2_set_variant_double (variant, i, col_name,
         8539  +				  rl2_set_variant_double (variant, i,
         8540  +							  col_name,
  8509   8541   							  sqlite3_column_double
  8510   8542   							  (stmt, i + 1));
  8511   8543   				  break;
  8512   8544   			      case SQLITE_TEXT:
  8513   8545   				  rl2_set_variant_text (variant, i, col_name,
  8514   8546   							(const char *)
  8515   8547   							sqlite3_column_text
................................................................................
  8529   8561   				  break;
  8530   8562   			      };
  8531   8563   			}
  8532   8564   		  }
  8533   8565   		if (geom != NULL)
  8534   8566   		  {
  8535   8567   		      /* drawing a styled Feature */
  8536         -		      int scale_forbidden;
         8568  +		      int scale_forbidden = 0;
  8537   8569   		      symbolizer = NULL;
  8538   8570   		      if (lyr_stl != NULL)
  8539   8571   			  symbolizer =
  8540   8572   			      rl2_get_symbolizer_from_feature_type_style
  8541   8573   			      (lyr_stl, scale, variant, &scale_forbidden);
  8542   8574   		      if (!scale_forbidden)
  8543         -			  rl2_draw_vector_feature (ctx, sqlite, symbolizer,
  8544         -						   height, minx, miny, x_res,
         8575  +			  rl2_draw_vector_feature (ctx, sqlite, data,
         8576  +						   symbolizer, height, minx,
         8577  +						   miny, maxx, maxy, x_res,
  8545   8578   						   y_res, geom, variant);
  8546   8579   		      rl2_destroy_geometry (geom);
  8547   8580   		  }
  8548   8581   	    }
  8549   8582         }
  8550   8583       sqlite3_finalize (stmt);
  8551   8584   
................................................................................
  8805   8838   			    *p_rgba++ = 0;	/* transparent */
  8806   8839   			}
  8807   8840   		  }
  8808   8841   		switch (pixel_type)
  8809   8842   		  {
  8810   8843   		  case RL2_PIXEL_MONOCHROME:
  8811   8844   		      ret =
  8812         -			  get_rgba_from_monochrome_mask (width, height, buffer,
  8813         -							 mask, no_data, rgba);
         8845  +			  get_rgba_from_monochrome_mask (width, height,
         8846  +							 buffer, mask,
         8847  +							 no_data, rgba);
  8814   8848   		      buffer = NULL;
  8815   8849   		      mask = NULL;
  8816   8850   		      if (!ret)
  8817   8851   			  goto error;
  8818   8852   		      if (!build_rgb_alpha
  8819         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  8820         -			   bg_blue))
         8853  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         8854  +			   bg_green, bg_blue))
  8821   8855   			  goto error;
  8822   8856   		      free (rgba);
  8823   8857   		      rgba = NULL;
  8824   8858   		      if (transparent)
  8825   8859   			{
  8826   8860   			    if (!get_payload_from_gray_rgba_transparent
  8827   8861   				(width, height, rgb, alpha,
................................................................................
  8847   8881   						      mask, palette, no_data,
  8848   8882   						      rgba);
  8849   8883   		      buffer = NULL;
  8850   8884   		      mask = NULL;
  8851   8885   		      if (!ret)
  8852   8886   			  goto error;
  8853   8887   		      if (!build_rgb_alpha
  8854         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  8855         -			   bg_blue))
         8888  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         8889  +			   bg_green, bg_blue))
  8856   8890   			  goto error;
  8857   8891   		      free (rgba);
  8858   8892   		      rgba = NULL;
  8859   8893   		      if (transparent)
  8860   8894   			{
  8861   8895   			    if (!get_payload_from_rgb_rgba_transparent
  8862   8896   				(width, height, rgb, alpha,
................................................................................
  8881   8915   			  get_rgba_from_grayscale_mask (width, height, buffer,
  8882   8916   							mask, no_data, rgba);
  8883   8917   		      buffer = NULL;
  8884   8918   		      mask = NULL;
  8885   8919   		      if (!ret)
  8886   8920   			  goto error;
  8887   8921   		      if (!build_rgb_alpha
  8888         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  8889         -			   bg_blue))
         8922  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         8923  +			   bg_green, bg_blue))
  8890   8924   			  goto error;
  8891   8925   		      free (rgba);
  8892   8926   		      rgba = NULL;
  8893   8927   		      if (transparent)
  8894   8928   			{
  8895   8929   			    if (!get_payload_from_gray_rgba_transparent
  8896   8930   				(width, height, rgb, alpha,
................................................................................
  8916   8950   						       sample_type, buffer,
  8917   8951   						       mask, no_data, rgba);
  8918   8952   		      buffer = NULL;
  8919   8953   		      mask = NULL;
  8920   8954   		      if (!ret)
  8921   8955   			  goto error;
  8922   8956   		      if (!build_rgb_alpha
  8923         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  8924         -			   bg_blue))
         8957  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         8958  +			   bg_green, bg_blue))
  8925   8959   			  goto error;
  8926   8960   		      free (rgba);
  8927   8961   		      rgba = NULL;
  8928   8962   		      if (transparent)
  8929   8963   			{
  8930   8964   			    if (!get_payload_from_gray_rgba_transparent
  8931   8965   				(width, height, rgb, alpha,
................................................................................
  8945   8979   			}
  8946   8980   		      sqlite3_result_blob (context, image, image_size, free);
  8947   8981   		      break;
  8948   8982   		  case RL2_PIXEL_RGB:
  8949   8983   		      if (sample_type == RL2_SAMPLE_UINT16)
  8950   8984   			{
  8951   8985   			    ret =
  8952         -				get_rgba_from_multiband16 (width, height, 0, 1,
  8953         -							   2, 3,
         8986  +				get_rgba_from_multiband16 (width, height, 0,
         8987  +							   1, 2, 3,
  8954   8988   							   (unsigned short *)
  8955   8989   							   buffer, mask,
  8956   8990   							   no_data, rgba);
  8957   8991   			}
  8958   8992   		      else
  8959   8993   			{
  8960   8994   			    ret =
................................................................................
  8962   8996   							mask, no_data, rgba);
  8963   8997   			}
  8964   8998   		      buffer = NULL;
  8965   8999   		      mask = NULL;
  8966   9000   		      if (!ret)
  8967   9001   			  goto error;
  8968   9002   		      if (!build_rgb_alpha
  8969         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  8970         -			   bg_blue))
         9003  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         9004  +			   bg_green, bg_blue))
  8971   9005   			  goto error;
  8972   9006   		      free (rgba);
  8973   9007   		      rgba = NULL;
  8974   9008   		      if (transparent)
  8975   9009   			{
  8976   9010   			    if (!get_payload_from_rgb_rgba_transparent
  8977   9011   				(width, height, rgb, alpha,
................................................................................
  8990   9024   				goto error;
  8991   9025   			}
  8992   9026   		      sqlite3_result_blob (context, image, image_size, free);
  8993   9027   		      break;
  8994   9028   		  case RL2_PIXEL_MULTIBAND:
  8995   9029   		      ret =
  8996   9030   			  get_rgba_from_multiband_mask (width, height,
  8997         -							sample_type, num_bands,
  8998         -							buffer, mask, no_data,
  8999         -							rgba);
         9031  +							sample_type,
         9032  +							num_bands, buffer,
         9033  +							mask, no_data, rgba);
  9000   9034   		      buffer = NULL;
  9001   9035   		      mask = NULL;
  9002   9036   		      if (!ret)
  9003   9037   			  goto error;
  9004   9038   		      if (!build_rgb_alpha
  9005         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  9006         -			   bg_blue))
         9039  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         9040  +			   bg_green, bg_blue))
  9007   9041   			  goto error;
  9008   9042   		      free (rgba);
  9009   9043   		      rgba = NULL;
  9010   9044   		      if (transparent)
  9011   9045   			{
  9012   9046   			    if (!get_payload_from_gray_rgba_transparent
  9013   9047   				(width, height, rgb, alpha,
................................................................................
  9238   9272   						    num_bands, buffer, mask,
  9239   9273   						    no_data, rgba);
  9240   9274   		      buffer = NULL;
  9241   9275   		      mask = NULL;
  9242   9276   		      if (!ret)
  9243   9277   			  goto error;
  9244   9278   		      if (!build_rgb_alpha
  9245         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  9246         -			   bg_blue))
         9279  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         9280  +			   bg_green, bg_blue))
  9247   9281   			  goto error;
  9248   9282   		      free (rgba);
  9249   9283   		      rgba = NULL;
  9250   9284   		      if (transparent)
  9251   9285   			{
  9252   9286   			    if (!get_payload_from_rgb_rgba_transparent
  9253   9287   				(width, height, rgb, alpha,
................................................................................
  9268   9302   		      sqlite3_result_blob (context, image, image_size, free);
  9269   9303   		      break;
  9270   9304   		  case RL2_SAMPLE_UINT16:
  9271   9305   		      ret =
  9272   9306   			  get_rgba_from_multiband16 (width, height, red_band,
  9273   9307   						     green_band, blue_band,
  9274   9308   						     num_bands,
  9275         -						     (unsigned short *) buffer,
  9276         -						     mask, no_data, rgba);
         9309  +						     (unsigned short *)
         9310  +						     buffer, mask, no_data,
         9311  +						     rgba);
  9277   9312   		      if (!build_rgb_alpha
  9278         -			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
  9279         -			   bg_blue))
         9313  +			  (width, height, rgba, &rgb, &alpha, bg_red,
         9314  +			   bg_green, bg_blue))
  9280   9315   			  goto error;
  9281   9316   		      free (rgba);
  9282   9317   		      rgba = NULL;
  9283   9318   		      if (transparent)
  9284   9319   			{
  9285   9320   			    if (!get_payload_from_rgb_rgba_transparent
  9286   9321   				(width, height, rgb, alpha,
................................................................................
  9661   9696   	  double ext_x = (double) width * horz_res;
  9662   9697   	  double ext_y = (double) height * vert_res;
  9663   9698   	  minx = pt_x - ext_x / 2.0;
  9664   9699   	  maxx = minx + ext_x;
  9665   9700   	  miny = pt_y - ext_y / 2.0;
  9666   9701   	  maxy = miny + ext_y;
  9667   9702         }
  9668         -    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
  9669         -	     != RL2_OK)
         9703  +    else if (rl2_parse_bbox
         9704  +	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
  9670   9705   	goto error;
  9671   9706   
  9672   9707   /* attempting to load the Coverage definitions from the DBMS */
  9673   9708       coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
  9674   9709       if (coverage == NULL)
  9675   9710   	goto error;
  9676   9711       if (by_section)
  9677   9712         {
  9678   9713   	  /* only a single Section */
  9679   9714   	  ret =
  9680   9715   	      rl2_export_section_raw_pixels_from_dbms (sqlite, max_threads,
  9681   9716   						       coverage, section_id,
  9682         -						       horz_res, vert_res, minx,
  9683         -						       miny, maxx, maxy, width,
  9684         -						       height, big_endian,
  9685         -						       &xblob, &xblob_sz);
         9717  +						       horz_res, vert_res,
         9718  +						       minx, miny, maxx, maxy,
         9719  +						       width, height,
         9720  +						       big_endian, &xblob,
         9721  +						       &xblob_sz);
  9686   9722         }
  9687   9723       else
  9688   9724         {
  9689   9725   	  /* whole Coverage */
  9690   9726   	  ret =
  9691   9727   	      rl2_export_raw_pixels_from_dbms (sqlite, max_threads, coverage,
  9692   9728   					       horz_res, vert_res, minx, miny,
................................................................................
  9878   9914       if (rl2_parse_bbox_srid
  9879   9915   	(sqlite, blob, blob_sz, &srid, &minx, &miny, &maxx, &maxy) != RL2_OK)
  9880   9916         {
  9881   9917   	  errcode = -1;
  9882   9918   	  goto error;
  9883   9919         }
  9884   9920   
  9885         -    if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands)
  9886         -	!= RL2_OK)
         9921  +    if (rl2_get_coverage_type
         9922  +	(coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK)
  9887   9923         {
  9888   9924   	  errcode = -1;
  9889   9925   	  goto error;
  9890   9926         }
  9891   9927       if (rl2_get_coverage_srid (coverage, &cov_srid) != RL2_OK)
  9892   9928         {
  9893   9929   	  errcode = -1;
................................................................................
  9947   9983       no_data = NULL;
  9948   9984       if (raster == NULL)
  9949   9985         {
  9950   9986   	  errcode = -1;
  9951   9987   	  goto error;
  9952   9988         }
  9953   9989   /* georeferencing the raster */
  9954         -    if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy) !=
  9955         -	RL2_OK)
         9990  +    if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy)
         9991  +	!= RL2_OK)
  9956   9992         {
  9957   9993   	  errcode = -1;
  9958   9994   	  goto error;
  9959   9995         }
  9960   9996   
  9961   9997   /* attempting to load the Raster into the DBMS */
  9962   9998       if (transaction)
................................................................................
  9967  10003   	    {
  9968  10004   		rl2_destroy_coverage (coverage);
  9969  10005   		sqlite3_result_int (context, -1);
  9970  10006   		return;
  9971  10007   	    }
  9972  10008         }
  9973  10009       ret =
  9974         -	rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage, sctn_name,
  9975         -				       raster, pyramidize);
        10010  +	rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage,
        10011  +				       sctn_name, raster, pyramidize);
  9976  10012       rl2_destroy_coverage (coverage);
  9977  10013       rl2_destroy_raster (raster);
  9978  10014       if (ret != RL2_OK)
  9979  10015         {
  9980  10016   	  if (transaction)
  9981  10017   	    {
  9982  10018   		/* invalidating the pending transaction */
................................................................................
 10137  10173   			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
 10138  10174       sqlite3_create_function (db, "DropRasterCoverage", 2,
 10139  10175   			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
 10140  10176       sqlite3_create_function (db, "RL2_DropRasterCoverage", 2,
 10141  10177   			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
 10142  10178       sqlite3_create_function (db, "SetRasterCoverageInfos", 3,
 10143  10179   			     SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0);
 10144         -    sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3,
 10145         -			     SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0);
        10180  +    sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3, SQLITE_UTF8,
        10181  +			     0, fnct_SetRasterCoverageInfos, 0, 0);
 10146  10182       sqlite3_create_function (db, "SetRasterCoverageDefaultBands", 5,
 10147         -			     SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands,
 10148         -			     0, 0);
        10183  +			     SQLITE_UTF8, 0,
        10184  +			     fnct_SetRasterCoverageDefaultBands, 0, 0);
 10149  10185       sqlite3_create_function (db, "RL2_SetRasterCoverageDefaultBands", 5,
 10150         -			     SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands,
 10151         -			     0, 0);
        10186  +			     SQLITE_UTF8, 0,
        10187  +			     fnct_SetRasterCoverageDefaultBands, 0, 0);
 10152  10188       sqlite3_create_function (db, "EnableRasterCoverageAutoNDVI", 2,
 10153         -			     SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI,
 10154         -			     0, 0);
        10189  +			     SQLITE_UTF8, 0,
        10190  +			     fnct_EnableRasterCoverageAutoNDVI, 0, 0);
 10155  10191       sqlite3_create_function (db, "RL2_EnableRasterCoverageAutoNDVI", 2,
 10156         -			     SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI,
 10157         -			     0, 0);
        10192  +			     SQLITE_UTF8, 0,
        10193  +			     fnct_EnableRasterCoverageAutoNDVI, 0, 0);
 10158  10194       sqlite3_create_function (db, "IsRasterCoverageAutoNdviEnabled", 1,
 10159  10195   			     SQLITE_UTF8, 0,
 10160  10196   			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
 10161  10197       sqlite3_create_function (db, "RL2_IsRasterCoverageAutoNdviEnabled", 1,
 10162  10198   			     SQLITE_UTF8, 0,
 10163  10199   			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
 10164  10200       sqlite3_create_function (db, "GetPaletteNumEntries", 1,
................................................................................
 10286  10322   			     fnct_IsFontItalic, 0, 0);
 10287  10323       sqlite3_create_function (db, "RL2_IsFontItalic", 1,
 10288  10324   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10289  10325   			     fnct_IsFontItalic, 0, 0);
 10290  10326       sqlite3_create_function (db, "GetRasterStatistics_NoDataPixelsCount", 1,
 10291  10327   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10292  10328   			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
 10293         -    sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount", 1,
 10294         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10329  +    sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount",
        10330  +			     1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10295  10331   			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
 10296  10332       sqlite3_create_function (db, "GetRasterStatistics_ValidPixelsCount", 1,
 10297  10333   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10298  10334   			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
 10299         -    sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount", 1,
 10300         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10335  +    sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount",
        10336  +			     1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10301  10337   			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
 10302  10338       sqlite3_create_function (db, "GetRasterStatistics_SampleType", 1,
 10303  10339   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10304  10340   			     fnct_GetRasterStatistics_SampleType, 0, 0);
 10305  10341       sqlite3_create_function (db, "RL2_GetRasterStatistics_SampleType", 1,
 10306  10342   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
 10307  10343   			     fnct_GetRasterStatistics_SampleType, 0, 0);
................................................................................
 10368  10404   			     fnct_Pyramidize, 0, 0);
 10369  10405       sqlite3_create_function (db, "Pyramidize", 4, SQLITE_UTF8, priv_data,
 10370  10406   			     fnct_Pyramidize, 0, 0);
 10371  10407       sqlite3_create_function (db, "RL2_Pyramidize", 4, SQLITE_UTF8, priv_data,
 10372  10408   			     fnct_Pyramidize, 0, 0);
 10373  10409       sqlite3_create_function (db, "PyramidizeMonolithic", 1, SQLITE_UTF8, 0,
 10374  10410   			     fnct_PyramidizeMonolithic, 0, 0);
 10375         -    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8, 0,
 10376         -			     fnct_PyramidizeMonolithic, 0, 0);
        10411  +    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8,
        10412  +			     0, fnct_PyramidizeMonolithic, 0, 0);
 10377  10413       sqlite3_create_function (db, "PyramidizeMonolithic", 2, SQLITE_UTF8, 0,
 10378  10414   			     fnct_PyramidizeMonolithic, 0, 0);
 10379         -    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8, 0,
 10380         -			     fnct_PyramidizeMonolithic, 0, 0);
        10415  +    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8,
        10416  +			     0, fnct_PyramidizeMonolithic, 0, 0);
 10381  10417       sqlite3_create_function (db, "PyramidizeMonolithic", 3, SQLITE_UTF8, 0,
 10382  10418   			     fnct_PyramidizeMonolithic, 0, 0);
 10383         -    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8, 0,
 10384         -			     fnct_PyramidizeMonolithic, 0, 0);
        10419  +    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8,
        10420  +			     0, fnct_PyramidizeMonolithic, 0, 0);
 10385  10421       sqlite3_create_function (db, "DePyramidize", 1, SQLITE_UTF8, 0,
 10386  10422   			     fnct_DePyramidize, 0, 0);
 10387  10423       sqlite3_create_function (db, "RL2_DePyramidize", 1, SQLITE_UTF8, 0,
 10388  10424   			     fnct_DePyramidize, 0, 0);
 10389  10425       sqlite3_create_function (db, "DePyramidize", 2, SQLITE_UTF8, 0,
 10390  10426   			     fnct_DePyramidize, 0, 0);
 10391  10427       sqlite3_create_function (db, "RL2_DePyramidize", 2, SQLITE_UTF8, 0,
................................................................................
 10439  10475       sqlite3_create_function (db, "GetMapImageFromRaster", 11,
 10440  10476   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10441  10477   			     fnct_GetMapImageFromRaster, 0, 0);
 10442  10478       sqlite3_create_function (db, "RL2_GetMapImageFromRaster", 11,
 10443  10479   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10444  10480   			     fnct_GetMapImageFromRaster, 0, 0);
 10445  10481       sqlite3_create_function (db, "GetMapImageFromVector", 4,
 10446         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10482  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10447  10483   			     fnct_GetMapImageFromVector, 0, 0);
 10448  10484       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 4,
 10449         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10485  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10450  10486   			     fnct_GetMapImageFromVector, 0, 0);
 10451  10487       sqlite3_create_function (db, "GetMapImageFromVector", 5,
 10452         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10488  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10453  10489   			     fnct_GetMapImageFromVector, 0, 0);
 10454  10490       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 5,
 10455         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10491  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10456  10492   			     fnct_GetMapImageFromVector, 0, 0);
 10457  10493       sqlite3_create_function (db, "GetMapImageFromVector", 6,
 10458         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10494  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10459  10495   			     fnct_GetMapImageFromVector, 0, 0);
 10460  10496       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 6,
 10461         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10497  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10462  10498   			     fnct_GetMapImageFromVector, 0, 0);
 10463  10499       sqlite3_create_function (db, "GetMapImageFromVector", 7,
 10464         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10500  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10465  10501   			     fnct_GetMapImageFromVector, 0, 0);
 10466  10502       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 7,
 10467         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10503  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10468  10504   			     fnct_GetMapImageFromVector, 0, 0);
 10469  10505       sqlite3_create_function (db, "GetMapImageFromVector", 8,
 10470         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10506  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10471  10507   			     fnct_GetMapImageFromVector, 0, 0);
 10472  10508       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 8,
 10473         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10509  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10474  10510   			     fnct_GetMapImageFromVector, 0, 0);
 10475  10511       sqlite3_create_function (db, "GetMapImageFromVector", 9,
 10476         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10512  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10477  10513   			     fnct_GetMapImageFromVector, 0, 0);
 10478  10514       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 9,
 10479         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10515  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10480  10516   			     fnct_GetMapImageFromVector, 0, 0);
 10481  10517       sqlite3_create_function (db, "GetMapImageFromVector", 10,
 10482         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10518  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10483  10519   			     fnct_GetMapImageFromVector, 0, 0);
 10484  10520       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 10,
 10485         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10521  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10486  10522   			     fnct_GetMapImageFromVector, 0, 0);
 10487  10523       sqlite3_create_function (db, "GetMapImageFromVector", 11,
 10488         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10524  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10489  10525   			     fnct_GetMapImageFromVector, 0, 0);
 10490  10526       sqlite3_create_function (db, "RL2_GetMapImageFromVector", 11,
 10491         -			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
        10527  +			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10492  10528   			     fnct_GetMapImageFromVector, 0, 0);
 10493  10529       sqlite3_create_function (db, "GetTileImage", 2,
 10494  10530   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10495  10531   			     fnct_GetTileImage, 0, 0);
 10496  10532       sqlite3_create_function (db, "RL2_GetTileImage", 2,
 10497  10533   			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
 10498  10534   			     fnct_GetTileImage, 0, 0);
................................................................................
 10635  10671   				   fnct_LoadFontFromFile, 0, 0);
 10636  10672   	  sqlite3_create_function (db, "RL2_LoadFontFromFile", 1, SQLITE_UTF8,
 10637  10673   				   0, fnct_LoadFontFromFile, 0, 0);
 10638  10674   	  sqlite3_create_function (db, "ExportFontToFile", 2, SQLITE_UTF8, 0,
 10639  10675   				   fnct_ExportFontToFile, 0, 0);
 10640  10676   	  sqlite3_create_function (db, "RL2_ExportFontToFile", 2, SQLITE_UTF8,
 10641  10677   				   0, fnct_ExportFontToFile, 0, 0);
 10642         -	  sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8, priv_data,
 10643         -				   fnct_LoadRaster, 0, 0);
 10644         -	  sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8, priv_data,
 10645         -				   fnct_LoadRaster, 0, 0);
 10646         -	  sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8, priv_data,
 10647         -				   fnct_LoadRaster, 0, 0);
 10648         -	  sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8, priv_data,
 10649         -				   fnct_LoadRaster, 0, 0);
 10650         -	  sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8, priv_data,
 10651         -				   fnct_LoadRaster, 0, 0);
        10678  +	  sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8,
        10679  +				   priv_data, fnct_LoadRaster, 0, 0);
        10680  +	  sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8,
        10681  +				   priv_data, fnct_LoadRaster, 0, 0);
        10682  +	  sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8,
        10683  +				   priv_data, fnct_LoadRaster, 0, 0);
        10684  +	  sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8,
        10685  +				   priv_data, fnct_LoadRaster, 0, 0);
        10686  +	  sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8,
        10687  +				   priv_data, fnct_LoadRaster, 0, 0);
 10652  10688   	  sqlite3_create_function (db, "RL2_LoadRaster", 2, SQLITE_UTF8,
 10653  10689   				   priv_data, fnct_LoadRaster, 0, 0);
 10654  10690   	  sqlite3_create_function (db, "RL2_LoadRaster", 3, SQLITE_UTF8,
 10655  10691   				   priv_data, fnct_LoadRaster, 0, 0);
 10656  10692   	  sqlite3_create_function (db, "RL2_LoadRaster", 4, SQLITE_UTF8,
 10657  10693   				   priv_data, fnct_LoadRaster, 0, 0);
 10658  10694   	  sqlite3_create_function (db, "RL2_LoadRaster", 5, SQLITE_UTF8,
................................................................................
 10667  10703   				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10668  10704   	  sqlite3_create_function (db, "LoadRastersFromDir", 5, SQLITE_UTF8,
 10669  10705   				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10670  10706   	  sqlite3_create_function (db, "LoadRastersFromDir", 6, SQLITE_UTF8,
 10671  10707   				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10672  10708   	  sqlite3_create_function (db, "LoadRastersFromDir", 7, SQLITE_UTF8,
 10673  10709   				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10674         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2, SQLITE_UTF8,
 10675         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10676         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3, SQLITE_UTF8,
 10677         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10678         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4, SQLITE_UTF8,
 10679         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10680         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5, SQLITE_UTF8,
 10681         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10682         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6, SQLITE_UTF8,
 10683         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
 10684         -	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7, SQLITE_UTF8,
 10685         -				   priv_data, fnct_LoadRastersFromDir, 0, 0);
        10710  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2,
        10711  +				   SQLITE_UTF8, priv_data,
        10712  +				   fnct_LoadRastersFromDir, 0, 0);
        10713  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3,
        10714  +				   SQLITE_UTF8, priv_data,
        10715  +				   fnct_LoadRastersFromDir, 0, 0);
        10716  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4,
        10717  +				   SQLITE_UTF8, priv_data,
        10718  +				   fnct_LoadRastersFromDir, 0, 0);
        10719  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5,
        10720  +				   SQLITE_UTF8, priv_data,
        10721  +				   fnct_LoadRastersFromDir, 0, 0);
        10722  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6,
        10723  +				   SQLITE_UTF8, priv_data,
        10724  +				   fnct_LoadRastersFromDir, 0, 0);
        10725  +	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7,
        10726  +				   SQLITE_UTF8, priv_data,
        10727  +				   fnct_LoadRastersFromDir, 0, 0);
 10686  10728   	  sqlite3_create_function (db, "LoadRasterFromWMS", 9, SQLITE_UTF8,
 10687  10729   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10688         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9, SQLITE_UTF8,
 10689         -				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
        10730  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9,
        10731  +				   SQLITE_UTF8, priv_data,
        10732  +				   fnct_LoadRasterFromWMS, 0, 0);
 10690  10733   	  sqlite3_create_function (db, "LoadRasterFromWMS", 10, SQLITE_UTF8,
 10691  10734   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10692         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10, SQLITE_UTF8,
 10693         -				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
        10735  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10,
        10736  +				   SQLITE_UTF8, priv_data,
        10737  +				   fnct_LoadRasterFromWMS, 0, 0);
 10694  10738   	  sqlite3_create_function (db, "LoadRasterFromWMS", 11, SQLITE_UTF8,
 10695  10739   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10696         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11, SQLITE_UTF8,
 10697         -				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
        10740  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11,
        10741  +				   SQLITE_UTF8, priv_data,
        10742  +				   fnct_LoadRasterFromWMS, 0, 0);
 10698  10743   	  sqlite3_create_function (db, "LoadRasterFromWMS", 12, SQLITE_UTF8,
 10699  10744   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10700         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12, SQLITE_UTF8,
 10701         -				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
        10745  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12,
        10746  +				   SQLITE_UTF8, priv_data,
        10747  +				   fnct_LoadRasterFromWMS, 0, 0);
 10702  10748   	  sqlite3_create_function (db, "LoadRasterFromWMS", 13, SQLITE_UTF8,
 10703  10749   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10704         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13, SQLITE_UTF8,
 10705         -				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
        10750  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13,
        10751  +				   SQLITE_UTF8, priv_data,
        10752  +				   fnct_LoadRasterFromWMS, 0, 0);
 10706  10753   	  sqlite3_create_function (db, "LoadRasterFromWMS", 14, SQLITE_UTF8,
 10707  10754   				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
 10708         -	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14, SQLITE_UTF8,
 10709         -				   0, fnct_LoadRasterFromWMS, 0, 0);
        10755  +	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14,
        10756  +				   SQLITE_UTF8, 0, fnct_LoadRasterFromWMS, 0,
        10757  +				   0);
 10710  10758   	  sqlite3_create_function (db, "WriteGeoTiff", 6, SQLITE_UTF8,
 10711  10759   				   priv_data, fnct_WriteGeoTiff, 0, 0);
 10712  10760   	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 6, SQLITE_UTF8,
 10713  10761   				   priv_data, fnct_WriteGeoTiff, 0, 0);
 10714  10762   	  sqlite3_create_function (db, "WriteGeoTiff", 7, SQLITE_UTF8,
 10715  10763   				   priv_data, fnct_WriteGeoTiff, 0, 0);
 10716  10764   	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 7, SQLITE_UTF8,
................................................................................
 10813  10861   				   priv_data, fnct_WriteSectionTiff, 0, 0);
 10814  10862   	  sqlite3_create_function (db, "WriteSectionTiff", 9, SQLITE_UTF8,
 10815  10863   				   priv_data, fnct_WriteSectionTiff, 0, 0);
 10816  10864   	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 9, SQLITE_UTF8,
 10817  10865   				   priv_data, fnct_WriteSectionTiff, 0, 0);
 10818  10866   	  sqlite3_create_function (db, "WriteSectionTiff", 10, SQLITE_UTF8,
 10819  10867   				   priv_data, fnct_WriteSectionTiff, 0, 0);
 10820         -	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 10, SQLITE_UTF8,
 10821         -				   priv_data, fnct_WriteSectionTiff, 0, 0);
        10868  +	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 10,
        10869  +				   SQLITE_UTF8, priv_data,
        10870  +				   fnct_WriteSectionTiff, 0, 0);
 10822  10871   	  sqlite3_create_function (db, "WriteJpegJgw", 6, SQLITE_UTF8,
 10823  10872   				   priv_data, fnct_WriteJpegJgw, 0, 0);
 10824  10873   	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 6, SQLITE_UTF8,
 10825  10874   				   priv_data, fnct_WriteJpegJgw, 0, 0);
 10826  10875   	  sqlite3_create_function (db, "WriteJpegJgw", 7, SQLITE_UTF8,
 10827  10876   				   priv_data, fnct_WriteJpegJgw, 0, 0);
 10828  10877   	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 7, SQLITE_UTF8,
................................................................................
 10866  10915   				   priv_data, fnct_WriteSectionJpeg, 0, 0);
 10867  10916   	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 8, SQLITE_UTF8,
 10868  10917   				   priv_data, fnct_WriteSectionJpeg, 0, 0);
 10869  10918   	  sqlite3_create_function (db, "WriteSectionJpeg", 9, SQLITE_UTF8,
 10870  10919   				   priv_data, fnct_WriteSectionJpeg, 0, 0);
 10871  10920   	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 9, SQLITE_UTF8,
 10872  10921   				   priv_data, fnct_WriteSectionJpeg, 0, 0);
 10873         -	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9, SQLITE_UTF8,
 10874         -				   priv_data, fnct_WriteTripleBandGeoTiff, 0,
 10875         -				   0);
        10922  +	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9,
        10923  +				   SQLITE_UTF8, priv_data,
        10924  +				   fnct_WriteTripleBandGeoTiff, 0, 0);
 10876  10925   	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 9,
 10877  10926   				   SQLITE_UTF8, priv_data,
 10878  10927   				   fnct_WriteTripleBandGeoTiff, 0, 0);
 10879  10928   	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 10,
 10880  10929   				   SQLITE_UTF8, priv_data,
 10881  10930   				   fnct_WriteTripleBandGeoTiff, 0, 0);
 10882  10931   	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 10,
................................................................................
 10899  10948   				   fnct_WriteTripleBandGeoTiff, 0, 0);
 10900  10949   	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 13,
 10901  10950   				   SQLITE_UTF8, priv_data,
 10902  10951   				   fnct_WriteTripleBandGeoTiff, 0, 0);
 10903  10952   	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 10,
 10904  10953   				   SQLITE_UTF8, 0,
 10905  10954   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10906         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 10,
 10907         -				   SQLITE_UTF8, priv_data,
        10955  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
        10956  +				   10, SQLITE_UTF8, priv_data,
 10908  10957   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10909  10958   	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 11,
 10910  10959   				   SQLITE_UTF8, priv_data,
 10911  10960   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10912         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 11,
 10913         -				   SQLITE_UTF8, priv_data,
        10961  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
        10962  +				   11, SQLITE_UTF8, priv_data,
 10914  10963   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10915  10964   	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 12,
 10916  10965   				   SQLITE_UTF8, priv_data,
 10917  10966   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10918         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 12,
 10919         -				   SQLITE_UTF8, priv_data,
        10967  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
        10968  +				   12, SQLITE_UTF8, priv_data,
 10920  10969   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10921  10970   	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 13,
 10922  10971   				   SQLITE_UTF8, priv_data,
 10923  10972   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10924         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 13,
 10925         -				   SQLITE_UTF8, priv_data,
        10973  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
        10974  +				   13, SQLITE_UTF8, priv_data,
 10926  10975   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10927  10976   	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 14,
 10928  10977   				   SQLITE_UTF8, priv_data,
 10929  10978   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10930         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 14,
 10931         -				   SQLITE_UTF8, priv_data,
        10979  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
        10980  +				   14, SQLITE_UTF8, priv_data,
 10932  10981   				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
 10933  10982   	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 7, SQLITE_UTF8,
 10934  10983   				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
 10935  10984   	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 7,
 10936  10985   				   SQLITE_UTF8, priv_data,
 10937  10986   				   fnct_WriteMonoBandGeoTiff, 0, 0);
 10938  10987   	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 8, SQLITE_UTF8,
................................................................................
 10941  10990   				   SQLITE_UTF8, priv_data,
 10942  10991   				   fnct_WriteMonoBandGeoTiff, 0, 0);
 10943  10992   	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 9, SQLITE_UTF8,
 10944  10993   				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
 10945  10994   	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 9,
 10946  10995   				   SQLITE_UTF8, priv_data,
 10947  10996   				   fnct_WriteMonoBandGeoTiff, 0, 0);
 10948         -	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10, SQLITE_UTF8,
 10949         -				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
        10997  +	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10,
        10998  +				   SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff,
        10999  +				   0, 0);
 10950  11000   	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 10,
 10951  11001   				   SQLITE_UTF8, priv_data,
 10952  11002   				   fnct_WriteMonoBandGeoTiff, 0, 0);
 10953         -	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11, SQLITE_UTF8,
 10954         -				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
        11003  +	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11,
        11004  +				   SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff,
        11005  +				   0, 0);
 10955  11006   	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 11,
 10956  11007   				   SQLITE_UTF8, priv_data,
 10957  11008   				   fnct_WriteMonoBandGeoTiff, 0, 0);
 10958  11009   	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 8,
 10959  11010   				   SQLITE_UTF8, priv_data,
 10960  11011   				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
 10961  11012   	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 8,
................................................................................
 10981  11032   				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
 10982  11033   	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 12,
 10983  11034   				   SQLITE_UTF8, priv_data,
 10984  11035   				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
 10985  11036   	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 12,
 10986  11037   				   SQLITE_UTF8, priv_data,
 10987  11038   				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
 10988         -	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9, SQLITE_UTF8,
 10989         -				   priv_data, fnct_WriteTripleBandTiffTfw, 0,
 10990         -				   0);
        11039  +	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9,
        11040  +				   SQLITE_UTF8, priv_data,
        11041  +				   fnct_WriteTripleBandTiffTfw, 0, 0);
 10991  11042   	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 9,
 10992  11043   				   SQLITE_UTF8, priv_data,
 10993  11044   				   fnct_WriteTripleBandTiffTfw, 0, 0);
 10994  11045   	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 10,
 10995  11046   				   SQLITE_UTF8, priv_data,
 10996  11047   				   fnct_WriteTripleBandTiffTfw, 0, 0);
 10997  11048   	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 10,
................................................................................
 11008  11059   				   fnct_WriteTripleBandTiffTfw, 0, 0);
 11009  11060   	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 12,
 11010  11061   				   SQLITE_UTF8, priv_data,
 11011  11062   				   fnct_WriteTripleBandTiffTfw, 0, 0);
 11012  11063   	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 10,
 11013  11064   				   SQLITE_UTF8, priv_data,
 11014  11065   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11015         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 10,
 11016         -				   SQLITE_UTF8, priv_data,
        11066  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
        11067  +				   10, SQLITE_UTF8, priv_data,
 11017  11068   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11018  11069   	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 11,
 11019  11070   				   SQLITE_UTF8, priv_data,
 11020  11071   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11021         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 11,
 11022         -				   SQLITE_UTF8, priv_data,
        11072  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
        11073  +				   11, SQLITE_UTF8, priv_data,
 11023  11074   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11024  11075   	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 12,
 11025  11076   				   SQLITE_UTF8, priv_data,
 11026  11077   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11027         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 12,
 11028         -				   SQLITE_UTF8, priv_data,
        11078  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
        11079  +				   12, SQLITE_UTF8, priv_data,
 11029  11080   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11030  11081   	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 13,
 11031  11082   				   SQLITE_UTF8, priv_data,
 11032  11083   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11033         -	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 13,
 11034         -				   SQLITE_UTF8, priv_data,
        11084  +	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
        11085  +				   13, SQLITE_UTF8, priv_data,
 11035  11086   				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
 11036  11087   	  sqlite3_create_function (db, "WriteSectionMonoBandTiffTfw", 8,
 11037  11088   				   SQLITE_UTF8, priv_data,
 11038  11089   				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
 11039  11090   	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiffTfw", 8,
 11040  11091   				   SQLITE_UTF8, priv_data,
 11041  11092   				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
................................................................................
 11068  11119   				   SQLITE_UTF8, priv_data,
 11069  11120   				   fnct_WriteMonoBandTiffTfw, 0, 0);
 11070  11121   	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 9, SQLITE_UTF8,
 11071  11122   				   priv_data, fnct_WriteMonoBandTiffTfw, 0, 0);
 11072  11123   	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 9,
 11073  11124   				   SQLITE_UTF8, priv_data,
 11074  11125   				   fnct_WriteMonoBandTiffTfw, 0, 0);
 11075         -	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10, SQLITE_UTF8,
 11076         -				   priv_data, fnct_WriteMonoBandTiffTfw, 0, 0);
        11126  +	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10,
        11127  +				   SQLITE_UTF8, priv_data,
        11128  +				   fnct_WriteMonoBandTiffTfw, 0, 0);
 11077  11129   	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 10,
 11078  11130   				   SQLITE_UTF8, priv_data,
 11079  11131   				   fnct_WriteMonoBandTiffTfw, 0, 0);
 11080         -	  sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8, 0,
 11081         -				   fnct_WriteTripleBandTiff, 0, 0);
        11132  +	  sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8,
        11133  +				   0, fnct_WriteTripleBandTiff, 0, 0);
 11082  11134   	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 9,
 11083  11135   				   SQLITE_UTF8, priv_data,
 11084  11136   				   fnct_WriteTripleBandTiff, 0, 0);
 11085  11137   	  sqlite3_create_function (db, "WriteTripleBandTiff", 10, SQLITE_UTF8,
 11086  11138   				   0, fnct_WriteTripleBandTiff, 0, 0);
 11087  11139   	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 10,
 11088  11140   				   SQLITE_UTF8, priv_data,
................................................................................
 11119  11171   				   SQLITE_UTF8, priv_data,
 11120  11172   				   fnct_WriteSectionTripleBandTiff, 0, 0);
 11121  11173   	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiff", 13,
 11122  11174   				   SQLITE_UTF8, priv_data,
 11123  11175   				   fnct_WriteSectionTripleBandTiff, 0, 0);
 11124  11176   	  sqlite3_create_function (db, "WriteMonoBandTiff", 7, SQLITE_UTF8, 0,
 11125  11177   				   fnct_WriteMonoBandTiff, 0, 0);
 11126         -	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7, SQLITE_UTF8,
 11127         -				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
        11178  +	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7,
        11179  +				   SQLITE_UTF8, priv_data,
        11180  +				   fnct_WriteMonoBandTiff, 0, 0);
 11128  11181   	  sqlite3_create_function (db, "WriteMonoBandTiff", 8, SQLITE_UTF8, 0,
 11129  11182   				   fnct_WriteMonoBandTiff, 0, 0);
 11130         -	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8, SQLITE_UTF8,
 11131         -				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
        11183  +	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8,
        11184  +				   SQLITE_UTF8, priv_data,
        11185  +				   fnct_WriteMonoBandTiff, 0, 0);
 11132  11186   	  sqlite3_create_function (db, "WriteMonoBandTiff", 9, SQLITE_UTF8,
 11133  11187   				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
 11134         -	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9, SQLITE_UTF8,
 11135         -				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
        11188  +	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9,
        11189  +				   SQLITE_UTF8, priv_data,
        11190  +				   fnct_WriteMonoBandTiff, 0, 0);
 11136  11191   	  sqlite3_create_function (db, "WriteMonoBandTiff", 10, SQLITE_UTF8,
 11137  11192   				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
 11138         -	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10, SQLITE_UTF8,
 11139         -				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
        11193  +	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10,
        11194  +				   SQLITE_UTF8, priv_data,
        11195  +				   fnct_WriteMonoBandTiff, 0, 0);
 11140  11196   	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 8,
 11141  11197   				   SQLITE_UTF8, priv_data,
 11142  11198   				   fnct_WriteSectionMonoBandTiff, 0, 0);
 11143  11199   	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiff", 8,
 11144  11200   				   SQLITE_UTF8, priv_data,
 11145  11201   				   fnct_WriteSectionMonoBandTiff, 0, 0);
 11146  11202   	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 9,
................................................................................
 11169  11225   				   priv_data, fnct_WriteAsciiGrid, 0, 0);
 11170  11226   	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 7, SQLITE_UTF8,
 11171  11227   				   priv_data, fnct_WriteAsciiGrid, 0, 0);
 11172  11228   	  sqlite3_create_function (db, "WriteAsciiGrid", 8, SQLITE_UTF8,
 11173  11229   				   priv_data, fnct_WriteAsciiGrid, 0, 0);
 11174  11230   	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 8, SQLITE_UTF8,
 11175  11231   				   priv_data, fnct_WriteAsciiGrid, 0, 0);
 11176         -	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 7, SQLITE_UTF8,
 11177         -				   priv_data, fnct_WriteSectionAsciiGrid, 0, 0);
        11232  +	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 7,
        11233  +				   SQLITE_UTF8, priv_data,
        11234  +				   fnct_WriteSectionAsciiGrid, 0, 0);
 11178  11235   	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 7,
 11179  11236   				   SQLITE_UTF8, priv_data,
 11180  11237   				   fnct_WriteSectionAsciiGrid, 0, 0);
 11181         -	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 8, SQLITE_UTF8,
 11182         -				   0, fnct_WriteSectionAsciiGrid, 0, 0);
        11238  +	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 8,
        11239  +				   SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid,
        11240  +				   0, 0);
 11183  11241   	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 8,
 11184  11242   				   SQLITE_UTF8, priv_data,
 11185  11243   				   fnct_WriteSectionAsciiGrid, 0, 0);
 11186         -	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 9, SQLITE_UTF8,
 11187         -				   0, fnct_WriteSectionAsciiGrid, 0, 0);
        11244  +	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 9,
        11245  +				   SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid,
        11246  +				   0, 0);
 11188  11247   	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 9,
 11189  11248   				   SQLITE_UTF8, priv_data,
 11190  11249   				   fnct_WriteSectionAsciiGrid, 0, 0);
 11191  11250   	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 8, SQLITE_UTF8,
 11192  11251   				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
 11193         -	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8, SQLITE_UTF8,
 11194         -				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
        11252  +	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8,
        11253  +				   SQLITE_UTF8, priv_data,
        11254  +				   fnct_WriteNdviAsciiGrid, 0, 0);
 11195  11255   	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 9, SQLITE_UTF8,
 11196  11256   				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
 11197         -	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9, SQLITE_UTF8,
 11198         -				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
        11257  +	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9,
        11258  +				   SQLITE_UTF8, priv_data,
        11259  +				   fnct_WriteNdviAsciiGrid, 0, 0);
 11199  11260   	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 10, SQLITE_UTF8,
 11200  11261   				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
 11201  11262   	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 10,
 11202  11263   				   SQLITE_UTF8, priv_data,
 11203  11264   				   fnct_WriteNdviAsciiGrid, 0, 0);
 11204  11265   	  sqlite3_create_function (db, "WriteSectionNdviAsciiGrid", 9,
 11205  11266   				   SQLITE_UTF8, priv_data,

Changes to src/rl2sqlaux.c.

    81     81       int ret;
    82     82       const char *sample;
    83     83       int bands;
    84     84       unsigned char xsample_type = RL2_SAMPLE_UNKNOWN;
    85     85       unsigned char xnum_bands = RL2_BANDS_UNKNOWN;
    86     86   
    87     87       sql =
    88         -	sqlite3_mprintf ("SELECT sample_type, num_bands FROM raster_coverages "
    89         -			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
           88  +	sqlite3_mprintf
           89  +	("SELECT sample_type, num_bands FROM raster_coverages "
           90  +	 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    90     91       ret = sqlite3_get_table (sqlite, sql, &results, &rows, &columns, NULL);
    91     92       sqlite3_free (sql);
    92     93       if (ret != SQLITE_OK)
    93     94   	return 0;
    94     95       if (rows < 1)
    95     96   	;
    96     97       else
................................................................................
   734    735     error:
   735    736       if (stmt != NULL)
   736    737   	sqlite3_finalize (stmt);
   737    738       return RL2_ERROR;
   738    739   }
   739    740   
   740    741   static int
   741         -do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd, int blob_odd_sz,
   742         -		    unsigned char *blob_even, int blob_even_sz,
   743         -		    sqlite3_int64 section_id, int srid, double res_x,
   744         -		    double res_y, unsigned int tile_w, unsigned int tile_h,
   745         -		    double miny, double maxx, double tile_minx,
   746         -		    double tile_miny, double tile_maxx, double tile_maxy,
   747         -		    rl2PalettePtr aux_palette, rl2PixelPtr no_data,
   748         -		    sqlite3_stmt * stmt_tils, sqlite3_stmt * stmt_data,
          742  +do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd,
          743  +		    int blob_odd_sz, unsigned char *blob_even,
          744  +		    int blob_even_sz, sqlite3_int64 section_id, int srid,
          745  +		    double res_x, double res_y, unsigned int tile_w,
          746  +		    unsigned int tile_h, double miny, double maxx,
          747  +		    double tile_minx, double tile_miny, double tile_maxx,
          748  +		    double tile_maxy, rl2PalettePtr aux_palette,
          749  +		    rl2PixelPtr no_data, sqlite3_stmt * stmt_tils,
          750  +		    sqlite3_stmt * stmt_data,
   749    751   		    rl2RasterStatisticsPtr section_stats)
   750    752   {
   751    753   /* INSERTing the tile */
   752    754       int ret;
   753    755       sqlite3_int64 tile_id;
   754    756       rl2RasterStatisticsPtr stats = NULL;
   755    757   
................................................................................
   999   1001   }
  1000   1002   
  1001   1003   RL2_PRIVATE int
  1002   1004   rl2_do_insert_section (sqlite3 * handle, const char *src_path,
  1003   1005   		       const char *section, int srid, unsigned int width,
  1004   1006   		       unsigned int height, double minx, double miny,
  1005   1007   		       double maxx, double maxy, char *xml_summary,
  1006         -		       int section_paths, int section_md5, int section_summary,
  1007         -		       sqlite3_stmt * stmt_sect, sqlite3_int64 * id)
         1008  +		       int section_paths, int section_md5,
         1009  +		       int section_summary, sqlite3_stmt * stmt_sect,
         1010  +		       sqlite3_int64 * id)
  1008   1011   {
  1009   1012   /* INSERTing the section */
  1010   1013       int ret;
  1011   1014       unsigned char *blob;
  1012   1015       int blob_size;
  1013   1016       sqlite3_int64 section_id;
  1014   1017   
................................................................................
  1051   1054         {
  1052   1055   	  sqlite3_bind_null (stmt_sect, 4);
  1053   1056   	  if (xml_summary != NULL)
  1054   1057   	      free (xml_summary);
  1055   1058         }
  1056   1059       sqlite3_bind_int (stmt_sect, 5, width);
  1057   1060       sqlite3_bind_int (stmt_sect, 6, height);
  1058         -    if (rl2_build_bbox (handle, srid, minx, miny, maxx, maxy, &blob, &blob_size)
  1059         -	!= RL2_OK)
         1061  +    if (rl2_build_bbox
         1062  +	(handle, srid, minx, miny, maxx, maxy, &blob, &blob_size) != RL2_OK)
  1060   1063   	goto error;
  1061   1064       sqlite3_bind_blob (stmt_sect, 7, blob, blob_size, free);
  1062   1065       ret = sqlite3_step (stmt_sect);
  1063   1066       if (ret == SQLITE_DONE || ret == SQLITE_ROW)
  1064   1067   	section_id = sqlite3_last_insert_rowid (handle);
  1065   1068       else
  1066   1069         {
................................................................................
  1213   1216       int blob_odd_sz;
  1214   1217       unsigned char *blob_even;
  1215   1218       int blob_even_sz;
  1216   1219       rl2RasterPtr raster = NULL;
  1217   1220       double base_res_x;
  1218   1221       double base_res_y;
  1219   1222   
  1220         -    if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y) !=
  1221         -	RL2_OK)
         1223  +    if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y)
         1224  +	!= RL2_OK)
  1222   1225   	goto error;
  1223   1226       if (*first)
  1224   1227         {
  1225   1228   	  /* INSERTing the section */
  1226   1229   	  *first = 0;
  1227   1230   	  if (!rl2_do_insert_section
  1228   1231   	      (ptr->sqlite, "WMS Service", ptr->sect_name, ptr->srid,
  1229   1232   	       ptr->width, ptr->height, ptr->minx, ptr->miny, ptr->maxx,
  1230         -	       ptr->maxy, ptr->xml_summary, ptr->sectionPaths, ptr->sectionMD5,
  1231         -	       ptr->sectionSummary, ptr->stmt_sect, section_id))
         1233  +	       ptr->maxy, ptr->xml_summary, ptr->sectionPaths,
         1234  +	       ptr->sectionMD5, ptr->sectionSummary, ptr->stmt_sect,
         1235  +	       section_id))
  1232   1236   	      goto error;
  1233   1237   	  *section_stats =
  1234   1238   	      rl2_create_raster_statistics (ptr->sample_type, ptr->num_bands);
  1235   1239   	  if (*section_stats == NULL)
  1236   1240   	      goto error;
  1237   1241   	  /* INSERTing the base-levels */
  1238   1242   	  if (ptr->mixedResolutions)
................................................................................
  1271   1275       /* INSERTing the tile */
  1272   1276       tile_minx = ptr->x;
  1273   1277       tile_maxx = tile_minx + ptr->tilew;
  1274   1278       tile_maxy = ptr->y;
  1275   1279       tile_miny = tile_maxy - ptr->tileh;
  1276   1280       if (!do_insert_wms_tile
  1277   1281   	(ptr->sqlite, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
  1278         -	 *section_id, ptr->srid, ptr->horz_res, ptr->vert_res, ptr->tile_width,
  1279         -	 ptr->tile_height, ptr->miny, ptr->maxx, tile_minx, tile_miny,
  1280         -	 tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils,
         1282  +	 *section_id, ptr->srid, ptr->horz_res, ptr->vert_res,
         1283  +	 ptr->tile_width, ptr->tile_height, ptr->miny, ptr->maxx, tile_minx,
         1284  +	 tile_miny, tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils,
  1281   1285   	 ptr->stmt_data, *section_stats))
  1282   1286   	goto error;
  1283   1287       blob_odd = NULL;
  1284   1288       blob_even = NULL;
  1285   1289       rl2_destroy_raster (raster);
  1286   1290       free (ptr->rgba_tile);
  1287   1291       ptr->rgba_tile = NULL;
................................................................................
  1401   1405   	  xxcoverage = rl2_double_quoted_sql (xcoverage);
  1402   1406   	  sqlite3_free (xcoverage);
  1403   1407   	  sql =
  1404   1408   	      sqlite3_mprintf
  1405   1409   	      ("SELECT pyramid_level, x_resolution_1_8, y_resolution_1_8, "
  1406   1410   	       "x_resolution_1_4, y_resolution_1_4, x_resolution_1_2, y_resolution_1_2, "
  1407   1411   	       "x_resolution_1_1, y_resolution_1_1 FROM \"%s\" "
  1408         -	       "WHERE section_id = %s ORDER BY pyramid_level DESC", xxcoverage,
  1409         -	       sctn);
         1412  +	       "WHERE section_id = %s ORDER BY pyramid_level DESC",
         1413  +	       xxcoverage, sctn);
  1410   1414         }
  1411   1415       else
  1412   1416         {
  1413   1417   	  /* ordinary Coverage */
  1414   1418   	  xcoverage = sqlite3_mprintf ("%s_levels", coverage);
  1415   1419   	  xxcoverage = rl2_double_quoted_sql (xcoverage);
  1416   1420   	  sqlite3_free (xcoverage);
................................................................................
  1612   1616   	    }
  1613   1617         }
  1614   1618       return rgba;
  1615   1619   }
  1616   1620   
  1617   1621   RL2_PRIVATE int
  1618   1622   get_payload_from_monochrome_opaque (unsigned int width, unsigned int height,
  1619         -				    sqlite3 * handle, double minx, double miny,
  1620         -				    double maxx, double maxy, int srid,
  1621         -				    unsigned char *pixels, unsigned char format,
  1622         -				    int quality, unsigned char **image,
  1623         -				    int *image_sz)
         1623  +				    sqlite3 * handle, double minx,
         1624  +				    double miny, double maxx, double maxy,
         1625  +				    int srid, unsigned char *pixels,
         1626  +				    unsigned char format, int quality,
         1627  +				    unsigned char **image, int *image_sz)
  1624   1628   {
  1625   1629   /* input: Monochrome    output: Grayscale */
  1626   1630       int ret;
  1627   1631       unsigned char *p_in;
  1628   1632       unsigned char *p_out;
  1629   1633       unsigned char *gray = NULL;
  1630   1634       unsigned int row;
................................................................................
  1660   1664   	      goto error;
  1661   1665         }
  1662   1666       else if (format == RL2_OUTPUT_FORMAT_TIFF)
  1663   1667         {
  1664   1668   	  if (srid > 0)
  1665   1669   	    {
  1666   1670   		if (rl2_gray_to_geotiff
  1667         -		    (width, height, handle, minx, miny, maxx, maxy, srid, gray,
  1668         -		     image, image_sz) != RL2_OK)
         1671  +		    (width, height, handle, minx, miny, maxx, maxy, srid,
         1672  +		     gray, image, image_sz) != RL2_OK)
  1669   1673   		    goto error;
  1670   1674   	    }
  1671   1675   	  else
  1672   1676   	    {
  1673   1677   		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
  1674   1678   		    RL2_OK)
  1675   1679   		    goto error;
................................................................................
  1829   1833   		    goto error;
  1830   1834   	    }
  1831   1835   	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
  1832   1836   	    {
  1833   1837   		if (srid > 0)
  1834   1838   		  {
  1835   1839   		      if (rl2_rgb_to_geotiff
  1836         -			  (width, height, handle, minx, miny, maxx, maxy, srid,
  1837         -			   rgb, image, image_sz) != RL2_OK)
         1840  +			  (width, height, handle, minx, miny, maxx, maxy,
         1841  +			   srid, rgb, image, image_sz) != RL2_OK)
  1838   1842   			  goto error;
  1839   1843   		  }
  1840   1844   		else
  1841   1845   		  {
  1842         -		      if (rl2_rgb_to_tiff (width, height, rgb, image, image_sz)
  1843         -			  != RL2_OK)
         1846  +		      if (rl2_rgb_to_tiff
         1847  +			  (width, height, rgb, image, image_sz) != RL2_OK)
  1844   1848   			  goto error;
  1845   1849   		  }
  1846   1850   	    }
  1847   1851   	  else if (format == RL2_OUTPUT_FORMAT_PDF)
  1848   1852   	    {
  1849   1853   		rgba = rgb_to_rgba (width, height, rgb);
  1850   1854   		if (rgba == NULL)
................................................................................
  1892   1896   		    goto error;
  1893   1897   	    }
  1894   1898   	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
  1895   1899   	    {
  1896   1900   		if (srid > 0)
  1897   1901   		  {
  1898   1902   		      if (rl2_gray_to_geotiff
  1899         -			  (width, height, handle, minx, miny, maxx, maxy, srid,
  1900         -			   gray, image, image_sz) != RL2_OK)
         1903  +			  (width, height, handle, minx, miny, maxx, maxy,
         1904  +			   srid, gray, image, image_sz) != RL2_OK)
  1901   1905   			  goto error;
  1902   1906   		  }
  1903   1907   		else
  1904   1908   		  {
  1905   1909   		      if (rl2_gray_to_tiff
  1906   1910   			  (width, height, gray, image, image_sz) != RL2_OK)
  1907   1911   			  goto error;
................................................................................
  2070   2074       return 0;
  2071   2075   }
  2072   2076   
  2073   2077   RL2_PRIVATE int
  2074   2078   get_payload_from_grayscale_opaque (unsigned int width, unsigned int height,
  2075   2079   				   sqlite3 * handle, double minx, double miny,
  2076   2080   				   double maxx, double maxy, int srid,
  2077         -				   unsigned char *pixels, unsigned char format,
  2078         -				   int quality, unsigned char **image,
  2079         -				   int *image_sz)
         2081  +				   unsigned char *pixels,
         2082  +				   unsigned char format, int quality,
         2083  +				   unsigned char **image, int *image_sz)
  2080   2084   {
  2081   2085   /* input: Grayscale    output: Grayscale */
  2082   2086       int ret;
  2083   2087       unsigned char *rgba = NULL;
  2084   2088   
  2085   2089       if (format == RL2_OUTPUT_FORMAT_JPEG)
  2086   2090         {
  2087         -	  if (rl2_gray_to_jpeg (width, height, pixels, quality, image, image_sz)
  2088         -	      != RL2_OK)
         2091  +	  if (rl2_gray_to_jpeg
         2092  +	      (width, height, pixels, quality, image, image_sz) != RL2_OK)
  2089   2093   	      goto error;
  2090   2094         }
  2091   2095       else if (format == RL2_OUTPUT_FORMAT_PNG)
  2092   2096         {
  2093   2097   	  if (rl2_gray_to_png (width, height, pixels, image, image_sz) !=
  2094   2098   	      RL2_OK)
  2095   2099   	      goto error;
................................................................................
  2101   2105   		if (rl2_gray_to_geotiff
  2102   2106   		    (width, height, handle, minx, miny, maxx, maxy, srid,
  2103   2107   		     pixels, image, image_sz) != RL2_OK)
  2104   2108   		    goto error;
  2105   2109   	    }
  2106   2110   	  else
  2107   2111   	    {
  2108         -		if (rl2_gray_to_tiff (width, height, pixels, image, image_sz) !=
  2109         -		    RL2_OK)
         2112  +		if (rl2_gray_to_tiff (width, height, pixels, image, image_sz)
         2113  +		    != RL2_OK)
  2110   2114   		    goto error;
  2111   2115   	    }
  2112   2116         }
  2113   2117       else if (format == RL2_OUTPUT_FORMAT_PDF)
  2114   2118         {
  2115   2119   	  rgba = gray_to_rgba (width, height, pixels);
  2116   2120   	  if (rgba == NULL)
................................................................................
  2192   2196   {
  2193   2197   /* input: RGB    output: RGB */
  2194   2198       int ret;
  2195   2199       unsigned char *rgba = NULL;
  2196   2200   
  2197   2201       if (format == RL2_OUTPUT_FORMAT_JPEG)
  2198   2202         {
  2199         -	  if (rl2_rgb_to_jpeg (width, height, pixels, quality, image, image_sz)
  2200         -	      != RL2_OK)
         2203  +	  if (rl2_rgb_to_jpeg
         2204  +	      (width, height, pixels, quality, image, image_sz) != RL2_OK)
  2201   2205   	      goto error;
  2202   2206         }
  2203   2207       else if (format == RL2_OUTPUT_FORMAT_PNG)
  2204   2208         {
  2205   2209   	  if (rl2_rgb_to_png (width, height, pixels, image, image_sz) != RL2_OK)
  2206   2210   	      goto error;
  2207   2211         }
................................................................................
  2212   2216   		if (rl2_rgb_to_geotiff
  2213   2217   		    (width, height, handle, minx, miny, maxx, maxy, srid,
  2214   2218   		     pixels, image, image_sz) != RL2_OK)
  2215   2219   		    goto error;
  2216   2220   	    }
  2217   2221   	  else
  2218   2222   	    {
  2219         -		if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz) !=
  2220         -		    RL2_OK)
         2223  +		if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz)
         2224  +		    != RL2_OK)
  2221   2225   		    goto error;
  2222   2226   	    }
  2223   2227         }
  2224   2228       else if (format == RL2_OUTPUT_FORMAT_PDF)
  2225   2229         {
  2226   2230   	  rgba = rgb_to_rgba (width, height, pixels);
  2227   2231   	  if (rgba == NULL)
................................................................................
  2244   2248   }
  2245   2249   
  2246   2250   RL2_PRIVATE int
  2247   2251   get_payload_from_rgb_transparent (unsigned int width, unsigned int height,
  2248   2252   				  unsigned char *pixels, unsigned char format,
  2249   2253   				  int quality, unsigned char **image,
  2250   2254   				  int *image_sz, unsigned char bg_red,
  2251         -				  unsigned char bg_green, unsigned char bg_blue,
  2252         -				  double opacity)
         2255  +				  unsigned char bg_green,
         2256  +				  unsigned char bg_blue, double opacity)
  2253   2257   {
  2254   2258   /* input: RGB    output: RGB */
  2255   2259       unsigned char *p_in;
  2256   2260       unsigned char *p_msk;
  2257   2261       unsigned char *mask = NULL;
  2258   2262       unsigned int row;
  2259   2263       unsigned int col;
................................................................................
  2521   2525   				 unsigned char *pixels, unsigned char *rgba)
  2522   2526   {
  2523   2527   /* input: Monochrome    output: Grayscale */
  2524   2528       unsigned char *p_in;
  2525   2529       unsigned char *p_out;
  2526   2530       unsigned int row;
  2527   2531       unsigned int col;
         2532  +
  2528   2533       p_in = pixels;
  2529   2534       p_out = rgba;
  2530   2535       for (row = 0; row < height; row++)
  2531   2536         {
  2532   2537   	  for (col = 0; col < width; col++)
  2533   2538   	    {
  2534         -		if (*p_in++ == 1)
         2539  +		if (*p_in++ == 0)
  2535   2540   		  {
  2536   2541   		      *p_out++ = 0;	/* Black */
  2537   2542   		      *p_out++ = 0;
  2538   2543   		      *p_out++ = 0;
  2539   2544   		      *p_out++ = 255;	/* alpha */
  2540   2545   		  }
  2541   2546   		else
................................................................................
  2565   2570   
  2566   2571       p_in = pixels;
  2567   2572       p_out = rgba;
  2568   2573       for (row = 0; row < height; row++)
  2569   2574         {
  2570   2575   	  for (col = 0; col < width; col++)
  2571   2576   	    {
  2572         -		if (*p_in++ == 1)
         2577  +		if (*p_in++ == 0)
  2573   2578   		  {
  2574   2579   		      *p_out++ = 0;	/* Black */
  2575   2580   		      *p_out++ = 0;
  2576   2581   		      *p_out++ = 0;
  2577   2582   		      *p_out++ = 255;	/* alpha */
  2578   2583   		  }
  2579   2584   		else
................................................................................
  2768   2773     error:
  2769   2774       free (pixels);
  2770   2775       return 0;
  2771   2776   }
  2772   2777   
  2773   2778   RL2_PRIVATE int
  2774   2779   get_rgba_from_palette_transparent (unsigned int width, unsigned int height,
  2775         -				   unsigned char *pixels, rl2PalettePtr palette,
  2776         -				   unsigned char *rgba, unsigned char bg_red,
         2780  +				   unsigned char *pixels,
         2781  +				   rl2PalettePtr palette, unsigned char *rgba,
         2782  +				   unsigned char bg_red,
  2777   2783   				   unsigned char bg_green,
  2778   2784   				   unsigned char bg_blue)
  2779   2785   {
  2780   2786   /* input: Palette    output: Grayscale or RGB */
  2781   2787       rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
  2782   2788       unsigned char *p_in;
  2783   2789       unsigned char *p_out;
................................................................................
  2925   2931       free (pixels);
  2926   2932       return 1;
  2927   2933   }
  2928   2934   
  2929   2935   RL2_PRIVATE int
  2930   2936   get_rgba_from_grayscale_transparent (unsigned int width,
  2931   2937   				     unsigned int height,
  2932         -				     unsigned char *pixels, unsigned char *rgba,
  2933         -				     unsigned char bg_gray)
         2938  +				     unsigned char *pixels,
         2939  +				     unsigned char *rgba, unsigned char bg_gray)
  2934   2940   {
  2935   2941   /* input: Grayscale    output: Grayscale */
  2936   2942       unsigned char *p_in;
  2937   2943       unsigned char *p_out;
  2938   2944       unsigned int row;
  2939   2945       unsigned int col;
  2940   2946   
................................................................................
  3888   3894       if (mask != NULL)
  3889   3895   	free (mask);
  3890   3896       return 1;
  3891   3897   }
  3892   3898   
  3893   3899   RL2_PRIVATE int
  3894   3900   rgba_from_double (unsigned int width, unsigned int height,
  3895         -		  double *pixels, unsigned char *mask, rl2PrivPixelPtr no_data,
  3896         -		  unsigned char *rgba)
         3901  +		  double *pixels, unsigned char *mask,
         3902  +		  rl2PrivPixelPtr no_data, unsigned char *rgba)
  3897   3903   {
  3898   3904   /* input: DataGrid DOUBLE   output: Grayscale */
  3899   3905       double *p_in;
  3900   3906       unsigned char *p_out;
  3901   3907       unsigned char *p_msk;
  3902   3908       unsigned int row;
  3903   3909       unsigned int col;
................................................................................
  4059   4065         case RL2_SAMPLE_INT16:
  4060   4066   	  ret =
  4061   4067   	      rgba_from_int16 (width, height, (short *) pixels, mask, no_data,
  4062   4068   			       rgba);
  4063   4069   	  break;
  4064   4070         case RL2_SAMPLE_UINT16:
  4065   4071   	  ret =
  4066         -	      rgba_from_uint16 (width, height, (unsigned short *) pixels, mask,
  4067         -				no_data, rgba);
         4072  +	      rgba_from_uint16 (width, height, (unsigned short *) pixels,
         4073  +				mask, no_data, rgba);
  4068   4074   	  break;
  4069   4075         case RL2_SAMPLE_INT32:
  4070   4076   	  ret =
  4071   4077   	      rgba_from_int32 (width, height, (int *) pixels, mask, no_data,
  4072   4078   			       rgba);
  4073   4079   	  break;
  4074   4080         case RL2_SAMPLE_UINT32:
................................................................................
  4079   4085         case RL2_SAMPLE_FLOAT:
  4080   4086   	  ret =
  4081   4087   	      rgba_from_float (width, height, (float *) pixels, mask, no_data,
  4082   4088   			       rgba);
  4083   4089   	  break;
  4084   4090         case RL2_SAMPLE_DOUBLE:
  4085   4091   	  ret =
  4086         -	      rgba_from_double (width, height, (double *) pixels, mask, no_data,
  4087         -				rgba);
         4092  +	      rgba_from_double (width, height, (double *) pixels, mask,
         4093  +				no_data, rgba);
  4088   4094   	  break;
  4089   4095         };
  4090   4096       return ret;
  4091   4097   }
  4092   4098   
  4093   4099   RL2_PRIVATE int
  4094   4100   rgba_from_multi_uint8 (unsigned int width, unsigned int height,
................................................................................
  4305   4311   	      rgba_from_multi_uint8 (width, height, num_bands,
  4306   4312   				     (unsigned char *) pixels, mask, no_data,
  4307   4313   				     rgba);
  4308   4314   	  break;
  4309   4315         case RL2_SAMPLE_UINT16:
  4310   4316   	  ret =
  4311   4317   	      rgba_from_multi_uint16 (width, height, num_bands,
  4312         -				      (unsigned short *) pixels, mask, no_data,
  4313         -				      rgba);
         4318  +				      (unsigned short *) pixels, mask,
         4319  +				      no_data, rgba);
  4314   4320   	  break;
  4315   4321         };
  4316   4322       return ret;
  4317   4323   }
  4318   4324   
  4319   4325   RL2_PRIVATE int
  4320   4326   get_payload_from_gray_rgba_opaque (unsigned int width, unsigned int height,
................................................................................
  4357   4363   	      goto error;
  4358   4364         }
  4359   4365       else if (format == RL2_OUTPUT_FORMAT_TIFF)
  4360   4366         {
  4361   4367   	  if (srid > 0)
  4362   4368   	    {
  4363   4369   		if (rl2_gray_to_geotiff
  4364         -		    (width, height, handle, minx, miny, maxx, maxy, srid, gray,
  4365         -		     image, image_sz) != RL2_OK)
         4370  +		    (width, height, handle, minx, miny, maxx, maxy, srid,
         4371  +		     gray, image, image_sz) != RL2_OK)
  4366   4372   		    goto error;
  4367   4373   	    }
  4368   4374   	  else
  4369   4375   	    {
  4370   4376   		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
  4371   4377   		    RL2_OK)
  4372   4378   		    goto error;
................................................................................
  4464   4470   {
  4465   4471   /* RGB, Opaque */
  4466   4472       int ret;
  4467   4473       unsigned char *rgba = NULL;
  4468   4474   
  4469   4475       if (format == RL2_OUTPUT_FORMAT_JPEG)
  4470   4476         {
  4471         -	  if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz) !=
  4472         -	      RL2_OK)
         4477  +	  if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz)
         4478  +	      != RL2_OK)
  4473   4479   	      goto error;
  4474   4480         }
  4475   4481       else if (format == RL2_OUTPUT_FORMAT_PNG)
  4476   4482         {
  4477   4483   	  if (rl2_rgb_to_png (width, height, rgb, image, image_sz) != RL2_OK)
  4478   4484   	      goto error;
  4479   4485         }
................................................................................
  4511   4517   	free (rgba);
  4512   4518       return 0;
  4513   4519   }
  4514   4520   
  4515   4521   RL2_PRIVATE int
  4516   4522   get_payload_from_rgb_rgba_transparent (unsigned int width,
  4517   4523   				       unsigned int height,
  4518         -				       unsigned char *rgb, unsigned char *alpha,
         4524  +				       unsigned char *rgb,
         4525  +				       unsigned char *alpha,
  4519   4526   				       unsigned char format, int quality,
  4520   4527   				       unsigned char **image, int *image_sz,
  4521   4528   				       double opacity, int half_transparency)
  4522   4529   {
  4523   4530   /* RGB, Transparent */
  4524   4531       int ret;
  4525   4532       unsigned char *p_msk;

Changes to src/rl2svg.c.

   227    227   		pattern =
   228    228   		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
   229    229   						 grad->y2);
   230    230   		svg_apply_gradient_transformations (pattern, grad);
   231    231   		stop = grad->first_stop;
   232    232   		while (stop)
   233    233   		  {
   234         -		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
   235         -							 stop->red, stop->green,
          234  +		      cairo_pattern_add_color_stop_rgba (pattern,
          235  +							 stop->offset,
          236  +							 stop->red,
          237  +							 stop->green,
   236    238   							 stop->blue,
   237    239   							 stop->opacity *
   238    240   							 style->opacity);
   239    241   		      stop = stop->next;
   240    242   		  }
   241    243   		cairo_set_source (cairo, pattern);
   242    244   		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
   257    259   		pattern =
   258    260   		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
   259    261   						 grad->fx, grad->fy, grad->r);
   260    262   		svg_apply_gradient_transformations (pattern, grad);
   261    263   		stop = grad->first_stop;
   262    264   		while (stop)
   263    265   		  {
   264         -		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
   265         -							 stop->red, stop->green,
          266  +		      cairo_pattern_add_color_stop_rgba (pattern,
          267  +							 stop->offset,
          268  +							 stop->red,
          269  +							 stop->green,
   266    270   							 stop->blue,
   267    271   							 stop->opacity *
   268    272   							 style->opacity);
   269    273   		      stop = stop->next;
   270    274   		  }
   271    275   		cairo_set_source (cairo, pattern);
   272    276   		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
   288    292   			   style->stroke_opacity * style->opacity);
   289    293       cairo_set_line_cap (cairo, style->stroke_linecap);
   290    294       cairo_set_line_join (cairo, style->stroke_linejoin);
   291    295       cairo_set_miter_limit (cairo, style->stroke_miterlimit);
   292    296       if (style->stroke_dashitems == 0 || style->stroke_dasharray == NULL)
   293    297   	cairo_set_dash (cairo, lengths, 0, 0.0);
   294    298       else
   295         -	cairo_set_dash (cairo, style->stroke_dasharray, style->stroke_dashitems,
   296         -			style->stroke_dashoffset);
          299  +	cairo_set_dash (cairo, style->stroke_dasharray,
          300  +			style->stroke_dashitems, style->stroke_dashoffset);
   297    301   }
   298    302   
   299    303   static void
   300    304   svg_set_brush (cairo_t * cairo, rl2PrivSvgStylePtr style)
   301    305   {
   302    306   /* setting up a Brush for Cairo */
   303    307       cairo_pattern_t *pattern;
................................................................................
   310    314   		pattern =
   311    315   		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
   312    316   						 grad->y2);
   313    317   		svg_apply_gradient_transformations (pattern, grad);
   314    318   		stop = grad->first_stop;
   315    319   		while (stop)
   316    320   		  {
   317         -		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
   318         -							 stop->red, stop->green,
          321  +		      cairo_pattern_add_color_stop_rgba (pattern,
          322  +							 stop->offset,
          323  +							 stop->red,
          324  +							 stop->green,
   319    325   							 stop->blue,
   320    326   							 stop->opacity *
   321    327   							 style->opacity);
   322    328   		      stop = stop->next;
   323    329   		  }
   324    330   		cairo_set_source (cairo, pattern);
   325    331   		cairo_pattern_destroy (pattern);
................................................................................
   330    336   		pattern =
   331    337   		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
   332    338   						 grad->fx, grad->fy, grad->r);
   333    339   		svg_apply_gradient_transformations (pattern, grad);
   334    340   		stop = grad->first_stop;
   335    341   		while (stop)
   336    342   		  {
   337         -		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
   338         -							 stop->red, stop->green,
          343  +		      cairo_pattern_add_color_stop_rgba (pattern,
          344  +							 stop->offset,
          345  +							 stop->red,
          346  +							 stop->green,
   339    347   							 stop->blue,
   340    348   							 stop->opacity *
   341    349   							 style->opacity);
   342    350   		      stop = stop->next;
   343    351   		  }
   344    352   		cairo_set_source (cairo, pattern);
   345    353   		cairo_pattern_destroy (pattern);
................................................................................
   846    854   		bezier = item->data;
   847    855   		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
   848    856   				bezier->y2, bezier->x, bezier->y);
   849    857   		break;
   850    858   	    case RL2_SVG_CURVE_4:
   851    859   		bezier = item->data;
   852    860   		cairo_get_current_point (cairo, &x0, &y0);
   853         -		cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
          861  +		cairo_curve_to (cairo,
          862  +				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
   854    863   				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
   855         -				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2,
   856         -				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2,
   857         -				bezier->y1, bezier->y2);
          864  +				2.0 / 3.0 * bezier->x1 +
          865  +				1.0 / 3.0 * bezier->x2,
          866  +				2.0 / 3.0 * bezier->y1 +
          867  +				1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2);
   858    868   		break;
   859    869   	    case RL2_SVG_ELLIPT_ARC:
   860    870   		arc = item->data;
   861    871   		cairo_get_current_point (cairo, &x0, &y0);
   862    872   		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
   863    873   				  &radii_ratio, &angle1, &angle2);
   864    874   		cairo_save (cairo);
................................................................................
   943    953   		bezier = item->data;
   944    954   		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
   945    955   				bezier->y2, bezier->x, bezier->y);
   946    956   		break;
   947    957   	    case RL2_SVG_CURVE_4:
   948    958   		bezier = item->data;
   949    959   		cairo_get_current_point (cairo, &x0, &y0);
   950         -		cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
          960  +		cairo_curve_to (cairo,
          961  +				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
   951    962   				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
   952         -				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2,
   953         -				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2,
   954         -				bezier->y1, bezier->y2);
          963  +				2.0 / 3.0 * bezier->x1 +
          964  +				1.0 / 3.0 * bezier->x2,
          965  +				2.0 / 3.0 * bezier->y1 +
          966  +				1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2);
   955    967   		break;
   956    968   	    case RL2_SVG_ELLIPT_ARC:
   957    969   		arc = item->data;
   958    970   		cairo_get_current_point (cairo, &x0, &y0);
   959    971   		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
   960    972   				  &radii_ratio, &angle1, &angle2);
   961    973   		cairo_save (cairo);

Changes to src/rl2symbaux.c.

   782    782   
   783    783   static int
   784    784   eval_filter (rl2PrivStyleRulePtr rule, rl2VariantArrayPtr variant)
   785    785   {
   786    786   /* evaluating a Rule Filter */
   787    787       int i;
   788    788       rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;
   789         -    if (rule == NULL || var == NULL)
   790         -	return 1;
          789  +    if (rule->column_name == NULL)
          790  +	return 1;		/* there is no comparison: surely true */
          791  +    if (var == NULL)
          792  +	return 0;
   791    793       for (i = 0; i < var->count; i++)
   792    794         {
   793    795   	  rl2PrivVariantValuePtr val = *(var->array + i);
   794    796   	  if (val == NULL)
   795    797   	      return 0;
   796         -	  if (rule->column_name == NULL || val->column_name == NULL)
          798  +	  if (val->column_name == NULL)
   797    799   	      return 0;
   798    800   	  if (strcasecmp (rule->column_name, val->column_name) != 0)
   799    801   	      continue;
   800    802   	  switch (rule->comparison_op)
   801    803   	    {
   802    804   	    case RL2_COMPARISON_EQ:
   803    805   		return eval_filter_eq (rule, val);
................................................................................
   824    826         }
   825    827       return 0;
   826    828   }
   827    829   
   828    830   RL2_DECLARE rl2VectorSymbolizerPtr
   829    831   rl2_get_symbolizer_from_feature_type_style (rl2FeatureTypeStylePtr style,
   830    832   					    double scale,
   831         -					    rl2VariantArrayPtr variant, int *scale_forbidden)
          833  +					    rl2VariantArrayPtr variant,
          834  +					    int *scale_forbidden)
   832    835   {
   833    836   /* return the VectorSymbolizer matching a given scale/filter from a FeatureTypeStyle */
   834    837       rl2PrivVectorSymbolizerPtr symbolizer = NULL;
   835    838       rl2PrivStyleRulePtr pR;
   836    839       rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
   837    840       *scale_forbidden = 0;
   838    841       if (stl == NULL)
................................................................................
   845    848   	      ;
   846    849   	  else
   847    850   	    {
   848    851   		/* skipping any invalid rule */
   849    852   		pR = pR->next;
   850    853   		continue;
   851    854   	    }
          855  +
   852    856   	  if (eval_filter (pR, variant))
   853    857   	    {
          858  +		*scale_forbidden = 0;
   854    859   		if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
   855    860   		  {
   856    861   		      if (scale >= pR->min_scale && scale < pR->max_scale)
   857    862   			  symbolizer = pR->style;
   858    863   		  }
   859    864   		else if (pR->min_scale != DBL_MAX)
   860    865   		  {
................................................................................
   864    869   		else if (pR->max_scale != DBL_MAX)
   865    870   		  {
   866    871   		      if (scale < pR->max_scale)
   867    872   			  symbolizer = pR->style;
   868    873   		  }
   869    874   		else
   870    875   		    symbolizer = pR->style;
   871         -		    if (symbolizer == NULL)
          876  +		if (symbolizer == NULL)
   872    877   		    *scale_forbidden = 1;
   873         -		return (rl2VectorSymbolizerPtr) symbolizer;
          878  +		else
          879  +		    return (rl2VectorSymbolizerPtr) symbolizer;
   874    880   	    }
   875    881   	  pR = pR->next;
   876    882         }
   877    883       if (stl->else_rule != NULL)
   878    884         {
   879    885   	  /* applyhing the ELSE rule */
          886  +	  *scale_forbidden = 0;
   880    887   	  pR = stl->else_rule;
   881    888   	  if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
   882    889   	    {
   883    890   		if (scale >= pR->min_scale && scale < pR->max_scale)
   884    891   		    symbolizer = pR->style;
   885    892   	    }
   886    893   	  else if (pR->min_scale != DBL_MAX)
................................................................................
   891    898   	  else if (pR->max_scale != DBL_MAX)
   892    899   	    {
   893    900   		if (scale < pR->max_scale)
   894    901   		    symbolizer = pR->style;
   895    902   	    }
   896    903   	  else
   897    904   	      symbolizer = pR->style;
   898         -		    if (symbolizer == NULL)
   899         -		    *scale_forbidden = 1;
          905  +	  if (symbolizer == NULL)
          906  +	      *scale_forbidden = 1;
   900    907         }
   901    908       return (rl2VectorSymbolizerPtr) symbolizer;
   902    909   }
   903    910   
   904    911   RL2_DECLARE int
   905    912   rl2_is_visible_style (rl2FeatureTypeStylePtr style, double scale)
   906    913   {
................................................................................
   907    914   /* test visibility at a given scale/filter from a FeatureTypeStyle */
   908    915       int count = 0;
   909    916       int visible;
   910    917       rl2PrivStyleRulePtr pR;
   911    918       rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
   912    919       if (stl == NULL)
   913    920   	return 0;
          921  +    if (stl->first_rule == NULL)
          922  +      {
          923  +	  /* there are no rules: unconditional visibility */
          924  +	  return 1;
          925  +      }
   914    926   
   915    927       pR = stl->first_rule;
   916    928       while (pR != NULL)
   917    929         {
   918    930   	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
   919    931   	      ;
   920    932   	  else
................................................................................
  1102   1114   	    {
  1103   1115   		/* Interpolate Color Map */
  1104   1116   		*selected = 1;
  1105   1117   		*categorize = 0;
  1106   1118   		*interpolate = 1;
  1107   1119   		return RL2_OK;
  1108   1120   	    }
  1109         -	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||
  1110         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
  1111         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
         1121  +	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
         1122  +	      || stl->contrastEnhancement ==
         1123  +	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
         1124  +	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
  1112   1125   	    {
  1113   1126   		/* Contrast Enhancement */
  1114   1127   		*selected = 1;
  1115   1128   		*categorize = 0;
  1116   1129   		*interpolate = 0;
  1117   1130   		return RL2_OK;
  1118   1131   	    }
................................................................................
  1171   1184   {
  1172   1185   /* return if the RasterSymbolizer has a TripleBand selection */
  1173   1186       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1174   1187       if (stl == NULL)
  1175   1188   	return RL2_ERROR;
  1176   1189       if (stl->bandSelection == NULL)
  1177   1190         {
  1178         -	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||
  1179         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
  1180         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
         1191  +	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
         1192  +	      || stl->contrastEnhancement ==
         1193  +	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
         1194  +	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
  1181   1195   	    {
  1182   1196   		/* Contrast Enhancement */
  1183   1197   		*selected = 1;
  1184   1198   		return RL2_OK;
  1185   1199   	    }
  1186   1200         }
  1187   1201       if (stl->bandSelection == NULL)
................................................................................
  1201   1215   {
  1202   1216   /* return the RasterSymbolizer TripleBand selection */
  1203   1217       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1204   1218       if (stl == NULL)
  1205   1219   	return RL2_ERROR;
  1206   1220       if (stl->bandSelection == NULL)
  1207   1221         {
  1208         -	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||
  1209         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
  1210         -	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
         1222  +	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
         1223  +	      || stl->contrastEnhancement ==
         1224  +	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
         1225  +	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
  1211   1226   	    {
  1212   1227   		/* Contrast Enhancement */
  1213   1228   		*red_band = 0;
  1214   1229   		*green_band = 1;
  1215   1230   		*blue_band = 2;
  1216   1231   		return RL2_OK;
  1217   1232   	    }
................................................................................
  1242   1257   	return RL2_ERROR;
  1243   1258       *contrast_enhancement = stl->contrastEnhancement;
  1244   1259       *gamma_value = stl->gammaValue;
  1245   1260       return RL2_OK;
  1246   1261   }
  1247   1262   
  1248   1263   RL2_DECLARE int
  1249         -rl2_get_raster_symbolizer_red_band_contrast_enhancement (rl2RasterSymbolizerPtr
  1250         -							 style,
  1251         -							 unsigned char
  1252         -							 *contrast_enhancement,
  1253         -							 double *gamma_value)
         1264  +    rl2_get_raster_symbolizer_red_band_contrast_enhancement
         1265  +    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
         1266  +     double *gamma_value)
  1254   1267   {
  1255   1268   /* return the RasterSymbolizer RedBand ContrastEnhancement */
  1256   1269       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1257   1270       if (stl == NULL)
  1258   1271   	return RL2_ERROR;
  1259   1272       if (stl->bandSelection == NULL)
  1260   1273   	return RL2_ERROR;
................................................................................
  1284   1297   	  *gamma_value = stl->bandSelection->greenGamma;
  1285   1298   	  return RL2_OK;
  1286   1299         }
  1287   1300       return RL2_ERROR;
  1288   1301   }
  1289   1302   
  1290   1303   RL2_DECLARE int
  1291         -rl2_get_raster_symbolizer_blue_band_contrast_enhancement (rl2RasterSymbolizerPtr
  1292         -							  style,
  1293         -							  unsigned char
  1294         -							  *contrast_enhancement,
  1295         -							  double *gamma_value)
         1304  +    rl2_get_raster_symbolizer_blue_band_contrast_enhancement
         1305  +    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
         1306  +     double *gamma_value)
  1296   1307   {
  1297   1308   /* return the RasterSymbolizer BlueBand ContrastEnhancement */
  1298   1309       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1299   1310       if (stl == NULL)
  1300   1311   	return RL2_ERROR;
  1301   1312       if (stl->bandSelection == NULL)
  1302   1313   	return RL2_ERROR;
................................................................................
  1306   1317   	  *gamma_value = stl->bandSelection->blueGamma;
  1307   1318   	  return RL2_OK;
  1308   1319         }
  1309   1320       return RL2_ERROR;
  1310   1321   }
  1311   1322   
  1312   1323   RL2_DECLARE int
  1313         -rl2_get_raster_symbolizer_gray_band_contrast_enhancement (rl2RasterSymbolizerPtr
  1314         -							  style,
  1315         -							  unsigned char
  1316         -							  *contrast_enhancement,
  1317         -							  double *gamma_value)
         1324  +    rl2_get_raster_symbolizer_gray_band_contrast_enhancement
         1325  +    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
         1326  +     double *gamma_value)
  1318   1327   {
  1319   1328   /* return the RasterSymbolizer GrayBand ContrastEnhancement */
  1320   1329       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1321   1330       if (stl == NULL)
  1322   1331   	return RL2_ERROR;
  1323   1332       if (stl->bandSelection == NULL)
  1324   1333   	return RL2_ERROR;
................................................................................
  1358   1367   	  *relief_factor = stl->reliefFactor;
  1359   1368   	  return RL2_OK;
  1360   1369         }
  1361   1370       return RL2_ERROR;
  1362   1371   }
  1363   1372   
  1364   1373   RL2_DECLARE int
  1365         -rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr style,
  1366         -						  int *interpolated)
         1374  +rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr
         1375  +						  style, int *interpolated)
  1367   1376   {
  1368   1377   /* return if the RasterSymbolizer has an Interpolated ColorMap */
  1369   1378       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1370   1379       if (stl == NULL)
  1371   1380   	return RL2_ERROR;
  1372   1381       if (stl->interpolate != NULL)
  1373   1382   	*interpolated = 1;
................................................................................
  1415   1424   	  *blue = stl->categorize->dfltBlue;
  1416   1425   	  return RL2_OK;
  1417   1426         }
  1418   1427       return RL2_ERROR;
  1419   1428   }
  1420   1429   
  1421   1430   RL2_DECLARE int
  1422         -rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr style,
  1423         -						   unsigned char *red,
         1431  +rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr
         1432  +						   style, unsigned char *red,
  1424   1433   						   unsigned char *green,
  1425   1434   						   unsigned char *blue)
  1426   1435   {
  1427   1436   /* return the RasterSymbolizer ColorMap Category base-color */
  1428   1437       rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
  1429   1438       if (stl == NULL)
  1430   1439   	return RL2_ERROR;
................................................................................
  1577   1586   /* creating a default Graphic object) */
  1578   1587       rl2PrivGraphicPtr graphic = malloc (sizeof (rl2PrivGraphic));
  1579   1588       graphic->first = NULL;
  1580   1589       graphic->last = NULL;
  1581   1590       graphic->opacity = 1.0;
  1582   1591       graphic->size = 10.0;
  1583   1592       graphic->rotation = 0.0;
  1584         -    graphic->anchor_point_x = 0.0;
  1585         -    graphic->anchor_point_y = 0.0;
         1593  +    graphic->anchor_point_x = 0.5;
         1594  +    graphic->anchor_point_y = 0.5;
  1586   1595       graphic->displacement_x = 0.0;
  1587   1596       graphic->displacement_y = 0.0;
  1588   1597       return graphic;
  1589   1598   }
  1590   1599   
  1591   1600   RL2_PRIVATE rl2PrivStrokePtr
  1592   1601   rl2_create_default_stroke ()
................................................................................
  1608   1617   }
  1609   1618   
  1610   1619   RL2_PRIVATE rl2PrivPointPlacementPtr
  1611   1620   rl2_create_default_point_placement ()
  1612   1621   {
  1613   1622   /* creating a default PointPlacement object */
  1614   1623       rl2PrivPointPlacementPtr place = malloc (sizeof (rl2PrivPointPlacement));
  1615         -    place->anchor_point_x = 0.0;
  1616         -    place->anchor_point_y = 0.0;
         1624  +    place->anchor_point_x = 0.5;
         1625  +    place->anchor_point_y = 0.5;
  1617   1626       place->displacement_x = 0.0;
  1618   1627       place->displacement_y = 0.0;
  1619   1628       place->rotation = 0.0;
  1620   1629       return place;
  1621   1630   }
  1622   1631   
  1623   1632   RL2_PRIVATE rl2PrivLinePlacementPtr
................................................................................
  2263   2272       if (sym->stroke->graphic->first->type != RL2_EXTERNAL_GRAPHIC)
  2264   2273   	return NULL;
  2265   2274       ext = (rl2PrivExternalGraphicPtr) (sym->stroke->graphic->first->item);
  2266   2275       return ext->xlink_href;
  2267   2276   }
  2268   2277   
  2269   2278   RL2_DECLARE int
  2270         -rl2_polygon_symbolizer_get_graphic_stroke_recode_count (rl2PolygonSymbolizerPtr
  2271         -							symbolizer, int *count)
         2279  +    rl2_polygon_symbolizer_get_graphic_stroke_recode_count
         2280  +    (rl2PolygonSymbolizerPtr symbolizer, int *count)
  2272   2281   {
  2273   2282   /* return how many ColorReplacement items are in a Graphic Stroke (PolygonSymbolizer) */
  2274   2283       rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
  2275   2284       if (sym == NULL)
  2276   2285   	return RL2_ERROR;
  2277   2286       *count = 0;
  2278   2287       if (sym->stroke != NULL)
................................................................................
  2301   2310   		  }
  2302   2311   	    }
  2303   2312         }
  2304   2313       return RL2_OK;
  2305   2314   }
  2306   2315   
  2307   2316   RL2_DECLARE int
  2308         -rl2_polygon_symbolizer_get_graphic_stroke_recode_color (rl2PolygonSymbolizerPtr
  2309         -							symbolizer, int index,
  2310         -							int *color_index,
  2311         -							unsigned char *red,
  2312         -							unsigned char *green,
  2313         -							unsigned char *blue)
         2317  +    rl2_polygon_symbolizer_get_graphic_stroke_recode_color
         2318  +    (rl2PolygonSymbolizerPtr symbolizer, int index, int *color_index,
         2319  +     unsigned char *red, unsigned char *green, unsigned char *blue)
  2314   2320   {
  2315   2321   /* return a ColorReplacement item from a Graphic Stroke (PolygonSymbolizer) */
  2316   2322       rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
  2317   2323       if (sym == NULL)
  2318   2324   	return RL2_ERROR;
  2319   2325       if (sym->stroke != NULL)
  2320   2326         {
................................................................................
  2395   2401       if (sym->stroke == NULL)
  2396   2402   	return RL2_ERROR;
  2397   2403       *width = sym->stroke->width;
  2398   2404       return RL2_OK;
  2399   2405   }
  2400   2406   
  2401   2407   RL2_DECLARE int
  2402         -rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr symbolizer,
  2403         -					    unsigned char *linejoin)
         2408  +rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr
         2409  +					    symbolizer, unsigned char *linejoin)
  2404   2410   {
  2405   2411   /* return the Polygon Symbolizer Stroke Linejoin mode */
  2406   2412       rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
  2407   2413       if (sym == NULL)
  2408   2414   	return RL2_ERROR;
  2409   2415       if (sym->stroke == NULL)
  2410   2416   	return RL2_ERROR;
................................................................................
  2437   2443       if (sym->stroke == NULL)
  2438   2444   	return RL2_ERROR;
  2439   2445       *count = sym->stroke->dash_count;
  2440   2446       return RL2_OK;
  2441   2447   }
  2442   2448   
  2443   2449   RL2_DECLARE int
  2444         -rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr symbolizer,
  2445         -					     int index, double *item)
         2450  +rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr
         2451  +					     symbolizer, int index,
         2452  +					     double *item)
  2446   2453   {
  2447   2454   /* return a Polygon Symbolizer Stroke Dash item */
  2448   2455       rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
  2449   2456       if (sym == NULL)
  2450   2457   	return RL2_ERROR;
  2451   2458       if (sym->stroke == NULL)
  2452   2459   	return RL2_ERROR;
................................................................................
  3111   3118         }
  3112   3119       return NULL;
  3113   3120   }
  3114   3121   
  3115   3122   RL2_DECLARE int
  3116   3123   rl2_point_symbolizer_get_graphic_recode_color (rl2PointSymbolizerPtr
  3117   3124   					       symbolizer, int index,
  3118         -					       int repl_index, int *color_index,
         3125  +					       int repl_index,
         3126  +					       int *color_index,
  3119   3127   					       unsigned char *red,
  3120   3128   					       unsigned char *green,
  3121   3129   					       unsigned char *blue)
  3122   3130   {
  3123   3131   /* return a ColorReplacement item from an External Graphic (PointSymbolizer) */
  3124   3132       int count = 0;
  3125   3133       rl2PrivExternalGraphicPtr ext;
................................................................................
  3188   3196   	  count++;
  3189   3197   	  item = item->next;
  3190   3198         }
  3191   3199       return RL2_ERROR;
  3192   3200   }
  3193   3201   
  3194   3202   RL2_DECLARE int
  3195         -rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr symbolizer,
  3196         -					       int index, unsigned char *type)
         3203  +rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr
         3204  +					       symbolizer, int index,
         3205  +					       unsigned char *type)
  3197   3206   {
  3198   3207   /* return the Point Symbolizer Mark WellKnownType */
  3199   3208       int count = 0;
  3200   3209       rl2PrivMarkPtr mark;
  3201   3210       rl2PrivGraphicItemPtr item;
  3202   3211       rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
  3203   3212       if (sym == NULL)
................................................................................
  3336   3345   	  count++;
  3337   3346   	  item = item->next;
  3338   3347         }
  3339   3348       return RL2_ERROR;
  3340   3349   }
  3341   3350   
  3342   3351   RL2_DECLARE int
  3343         -rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr symbolizer,
  3344         -					       int index,
         3352  +rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr
         3353  +					       symbolizer, int index,
  3345   3354   					       unsigned char *linejoin)
  3346   3355   {
  3347   3356   /* return the Point Symbolizer Mark Stroke Linejoin mode */
  3348   3357       int count = 0;
  3349   3358       rl2PrivMarkPtr mark;
  3350   3359       rl2PrivGraphicItemPtr item;
  3351   3360       rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
................................................................................
  3370   3379   	  count++;
  3371   3380   	  item = item->next;
  3372   3381         }
  3373   3382       return RL2_ERROR;
  3374   3383   }
  3375   3384   
  3376   3385   RL2_DECLARE int
  3377         -rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr symbolizer,
  3378         -					      int index, unsigned char *linecap)
         3386  +rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr
         3387  +					      symbolizer, int index,
         3388  +					      unsigned char *linecap)
  3379   3389   {
  3380   3390   /* return the Point Symbolizer Stroke Mark Linecap mode */
  3381   3391       int count = 0;
  3382   3392       rl2PrivMarkPtr mark;
  3383   3393       rl2PrivGraphicItemPtr item;
  3384   3394       rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
  3385   3395       if (sym == NULL)
................................................................................
  3511   3521   	  count++;
  3512   3522   	  itm = itm->next;
  3513   3523         }
  3514   3524       return RL2_ERROR;
  3515   3525   }
  3516   3526   
  3517   3527   RL2_DECLARE int
  3518         -rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer, int index,
  3519         -				    int *fill)
         3528  +rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer,
         3529  +				    int index, int *fill)
  3520   3530   {
  3521   3531   /* checks if a Point Symbolizer Mark has a Fill */
  3522   3532       int count = 0;
  3523   3533       rl2PrivMarkPtr mark;
  3524   3534       rl2PrivGraphicItemPtr item;
  3525   3535       rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
  3526   3536       if (sym == NULL)
................................................................................
  4194   4204       if (*(var->array + index) != NULL)
  4195   4205   	rl2_destroy_variant_value (*(var->array + index));
  4196   4206       *(var->array + index) = val;
  4197   4207       return RL2_OK;
  4198   4208   }
  4199   4209   
  4200   4210   RL2_DECLARE int
  4201         -rl2_set_variant_double (rl2VariantArrayPtr variant, int index, const char *name,
  4202         -			double value)
         4211  +rl2_set_variant_double (rl2VariantArrayPtr variant, int index,
         4212  +			const char *name, double value)
  4203   4213   {
  4204   4214   /* setting a DOUBLE VariantValue into a VariantArray object */
  4205   4215       rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;
  4206   4216       rl2PrivVariantValuePtr val;
  4207   4217       if (var == NULL)
  4208   4218   	return RL2_ERROR;
  4209   4219       if (index >= 0 && index < var->count)

Changes to src/rl2symbolizer.c.

   540    540   	  break;
   541    541         };
   542    542       *val = value;
   543    543       return 1;
   544    544   }
   545    545   
   546    546   static int
   547         -parse_sld_se_color (const char *color, unsigned char *red, unsigned char *green,
   548         -		    unsigned char *blue)
          547  +parse_sld_se_color (const char *color, unsigned char *red,
          548  +		    unsigned char *green, unsigned char *blue)
   549    549   {
   550    550   /* attempting to parse a #RRGGBB hexadecimal color */
   551    551       unsigned char r;
   552    552       unsigned char g;
   553    553       unsigned char b;
   554    554       if (strlen (color) != 7)
   555    555   	return 0;
................................................................................
   660    660   					    (color, &red, &green, &blue))
   661    661   					  {
   662    662   					      if (style->categorize->last ==
   663    663   						  NULL)
   664    664   						{
   665    665   						    style->categorize->baseRed =
   666    666   							red;
   667         -						    style->
   668         -							categorize->baseGreen =
   669         -							green;
          667  +						    style->categorize->baseGreen
          668  +							= green;
   670    669   						    style->
   671    670   							categorize->baseBlue =
   672    671   							blue;
   673    672   						}
   674    673   					      else
   675    674   						{
   676    675   						    style->categorize->
................................................................................
   976    975   					  {
   977    976   					      if (text->type == XML_TEXT_NODE)
   978    977   						{
   979    978   						    const char *value =
   980    979   							(const char
   981    980   							 *) (text->content);
   982    981   						    if (value != NULL)
   983         -							style->brightnessOnly =
   984         -							    atoi (value);
          982  +							style->brightnessOnly
          983  +							    = atoi (value);
   985    984   						}
   986    985   					      text = text->next;
   987    986   					  }
   988    987   				    }
   989    988   				  if (strcmp (xmode, "ReliefFactor") == 0)
   990    989   				    {
   991    990   					text = child->children;
................................................................................
  1056   1055   			    if (child->type == XML_ELEMENT_NODE)
  1057   1056   			      {
  1058   1057   				  name = (const char *) (child->name);
  1059   1058   				  if (strcmp (name, "RasterSymbolizer") == 0)
  1060   1059   				    {
  1061   1060   					rl2PrivStyleRulePtr rule =
  1062   1061   					    rl2_create_default_style_rule ();
  1063         -					rl2PrivRasterSymbolizerPtr symbolizer =
         1062  +					rl2PrivRasterSymbolizerPtr symbolizer
         1063  +					    =
  1064   1064   					    rl2_create_default_raster_symbolizer
  1065   1065   					    ();
  1066   1066   					if (symbolizer == NULL || rule == NULL)
  1067   1067   					  {
  1068   1068   					      if (symbolizer != NULL)
  1069   1069   						  rl2_destroy_raster_symbolizer
  1070   1070   						      (symbolizer);
................................................................................
  1372   1372   		      if (child->type == XML_TEXT_NODE
  1373   1373   			  && child->content != NULL)
  1374   1374   			{
  1375   1375   			    unsigned char red;
  1376   1376   			    unsigned char green;
  1377   1377   			    unsigned char blue;
  1378   1378   			    if (parse_sld_se_color
  1379         -				((const char *) (child->content), &red, &green,
  1380         -				 &blue))
         1379  +				((const char *) (child->content), &red,
         1380  +				 &green, &blue))
  1381   1381   			      {
  1382   1382   				  repl->red = red;
  1383   1383   				  repl->green = green;
  1384   1384   				  repl->blue = blue;
  1385   1385   			      }
  1386   1386   			    ok_value = 1;
  1387   1387   			}
................................................................................
  1546   1546   						   &blue))
  1547   1547   						{
  1548   1548   						    mark->stroke->red = red;
  1549   1549   						    mark->stroke->green = green;
  1550   1550   						    mark->stroke->blue = blue;
  1551   1551   						}
  1552   1552   					  }
  1553         -					if (strcmp (svg_name, "stroke-width") ==
  1554         -					    0)
         1553  +					if (strcmp (svg_name, "stroke-width")
         1554  +					    == 0)
  1555   1555   					    mark->stroke->width =
  1556   1556   						atof ((const char *) svg_value);
  1557         -					if (strcmp (svg_name, "stroke-linejoin")
  1558         -					    == 0)
         1557  +					if (strcmp
         1558  +					    (svg_name, "stroke-linejoin") == 0)
  1559   1559   					  {
  1560         -					      if (strcmp (svg_value, "mitre") ==
  1561         -						  0)
         1560  +					      if (strcmp (svg_value, "mitre")
         1561  +						  == 0)
  1562   1562   						  mark->stroke->linejoin =
  1563   1563   						      RL2_STROKE_LINEJOIN_MITRE;
  1564         -					      if (strcmp (svg_value, "round") ==
  1565         -						  0)
         1564  +					      if (strcmp (svg_value, "round")
         1565  +						  == 0)
  1566   1566   						  mark->stroke->linejoin =
  1567   1567   						      RL2_STROKE_LINEJOIN_ROUND;
  1568         -					      if (strcmp (svg_value, "bevel") ==
  1569         -						  0)
         1568  +					      if (strcmp (svg_value, "bevel")
         1569  +						  == 0)
  1570   1570   						  mark->stroke->linejoin =
  1571   1571   						      RL2_STROKE_LINEJOIN_BEVEL;
  1572   1572   					  }
  1573         -					if (strcmp (svg_name, "stroke-linecap")
  1574         -					    == 0)
         1573  +					if (strcmp
         1574  +					    (svg_name, "stroke-linecap") == 0)
  1575   1575   					  {
  1576         -					      if (strcmp (svg_value, "butt") ==
  1577         -						  0)
         1576  +					      if (strcmp (svg_value, "butt")
         1577  +						  == 0)
  1578   1578   						  mark->stroke->linecap =
  1579   1579   						      RL2_STROKE_LINECAP_BUTT;
  1580         -					      if (strcmp (svg_value, "round") ==
  1581         -						  0)
         1580  +					      if (strcmp (svg_value, "round")
         1581  +						  == 0)
  1582   1582   						  mark->stroke->linecap =
  1583   1583   						      RL2_STROKE_LINECAP_ROUND;
  1584   1584   					      if (strcmp (svg_value, "square")
  1585   1585   						  == 0)
  1586   1586   						  mark->stroke->linecap =
  1587   1587   						      RL2_STROKE_LINECAP_SQUARE;
  1588   1588   					  }
................................................................................
  1825   1825   						   &blue))
  1826   1826   						{
  1827   1827   						    sym->stroke->red = red;
  1828   1828   						    sym->stroke->green = green;
  1829   1829   						    sym->stroke->blue = blue;
  1830   1830   						}
  1831   1831   					  }
  1832         -					if (strcmp (svg_name, "stroke-opacity")
  1833         -					    == 0)
         1832  +					if (strcmp
         1833  +					    (svg_name, "stroke-opacity") == 0)
  1834   1834   					    sym->stroke->opacity =
  1835   1835   						atof ((const char *) svg_value);
  1836         -					if (strcmp (svg_name, "stroke-width") ==
  1837         -					    0)
         1836  +					if (strcmp (svg_name, "stroke-width")
         1837  +					    == 0)
  1838   1838   					    sym->stroke->width =
  1839   1839   						atof ((const char *) svg_value);
  1840         -					if (strcmp (svg_name, "stroke-linejoin")
  1841         -					    == 0)
         1840  +					if (strcmp
         1841  +					    (svg_name, "stroke-linejoin") == 0)
  1842   1842   					  {
  1843         -					      if (strcmp (svg_value, "mitre") ==
  1844         -						  0)
         1843  +					      if (strcmp (svg_value, "mitre")
         1844  +						  == 0)
  1845   1845   						  sym->stroke->linejoin =
  1846   1846   						      RL2_STROKE_LINEJOIN_MITRE;
  1847         -					      if (strcmp (svg_value, "round") ==
  1848         -						  0)
         1847  +					      if (strcmp (svg_value, "round")
         1848  +						  == 0)
  1849   1849   						  sym->stroke->linejoin =
  1850   1850   						      RL2_STROKE_LINEJOIN_ROUND;
  1851         -					      if (strcmp (svg_value, "bevel") ==
  1852         -						  0)
         1851  +					      if (strcmp (svg_value, "bevel")
         1852  +						  == 0)
  1853   1853   						  sym->stroke->linejoin =
  1854   1854   						      RL2_STROKE_LINEJOIN_BEVEL;
  1855   1855   					  }
  1856         -					if (strcmp (svg_name, "stroke-linecap")
  1857         -					    == 0)
         1856  +					if (strcmp
         1857  +					    (svg_name, "stroke-linecap") == 0)
  1858   1858   					  {
  1859         -					      if (strcmp (svg_value, "butt") ==
  1860         -						  0)
         1859  +					      if (strcmp (svg_value, "butt")
         1860  +						  == 0)
  1861   1861   						  sym->stroke->linecap =
  1862   1862   						      RL2_STROKE_LINECAP_BUTT;
  1863         -					      if (strcmp (svg_value, "round") ==
  1864         -						  0)
         1863  +					      if (strcmp (svg_value, "round")
         1864  +						  == 0)
  1865   1865   						  sym->stroke->linecap =
  1866   1866   						      RL2_STROKE_LINECAP_ROUND;
  1867   1867   					      if (strcmp (svg_value, "square")
  1868   1868   						  == 0)
  1869   1869   						  sym->stroke->linecap =
  1870   1870   						      RL2_STROKE_LINECAP_SQUARE;
  1871   1871   					  }
................................................................................
  2024   2024   						   &blue))
  2025   2025   						{
  2026   2026   						    sym->stroke->red = red;
  2027   2027   						    sym->stroke->green = green;
  2028   2028   						    sym->stroke->blue = blue;
  2029   2029   						}
  2030   2030   					  }
  2031         -					if (strcmp (svg_name, "stroke-opacity")
  2032         -					    == 0)
         2031  +					if (strcmp
         2032  +					    (svg_name, "stroke-opacity") == 0)
  2033   2033   					    sym->stroke->opacity =
  2034   2034   						atof ((const char *) svg_value);
  2035         -					if (strcmp (svg_name, "stroke-width") ==
  2036         -					    0)
         2035  +					if (strcmp (svg_name, "stroke-width")
         2036  +					    == 0)
  2037   2037   					    sym->stroke->width =
  2038   2038   						atof ((const char *) svg_value);
  2039         -					if (strcmp (svg_name, "stroke-linejoin")
  2040         -					    == 0)
         2039  +					if (strcmp
         2040  +					    (svg_name, "stroke-linejoin") == 0)
  2041   2041   					  {
  2042         -					      if (strcmp (svg_value, "mitre") ==
  2043         -						  0)
         2042  +					      if (strcmp (svg_value, "mitre")
         2043  +						  == 0)
  2044   2044   						  sym->stroke->linejoin =
  2045   2045   						      RL2_STROKE_LINEJOIN_MITRE;
  2046         -					      if (strcmp (svg_value, "round") ==
  2047         -						  0)
         2046  +					      if (strcmp (svg_value, "round")
         2047  +						  == 0)
  2048   2048   						  sym->stroke->linejoin =
  2049   2049   						      RL2_STROKE_LINEJOIN_ROUND;
  2050         -					      if (strcmp (svg_value, "bevel") ==
  2051         -						  0)
         2050  +					      if (strcmp (svg_value, "bevel")
         2051  +						  == 0)
  2052   2052   						  sym->stroke->linejoin =
  2053   2053   						      RL2_STROKE_LINEJOIN_BEVEL;
  2054   2054   					  }
  2055         -					if (strcmp (svg_name, "stroke-linecap")
  2056         -					    == 0)
         2055  +					if (strcmp
         2056  +					    (svg_name, "stroke-linecap") == 0)
  2057   2057   					  {
  2058         -					      if (strcmp (svg_value, "butt") ==
  2059         -						  0)
         2058  +					      if (strcmp (svg_value, "butt")
         2059  +						  == 0)
  2060   2060   						  sym->stroke->linecap =
  2061   2061   						      RL2_STROKE_LINECAP_BUTT;
  2062         -					      if (strcmp (svg_value, "round") ==
  2063         -						  0)
         2062  +					      if (strcmp (svg_value, "round")
         2063  +						  == 0)
  2064   2064   						  sym->stroke->linecap =
  2065   2065   						      RL2_STROKE_LINECAP_ROUND;
  2066   2066   					      if (strcmp (svg_value, "square")
  2067   2067   						  == 0)
  2068   2068   						  sym->stroke->linecap =
  2069   2069   						      RL2_STROKE_LINECAP_SQUARE;
  2070   2070   					  }
................................................................................
  2166   2166   						   &blue))
  2167   2167   						{
  2168   2168   						    sym->fill->red = red;
  2169   2169   						    sym->fill->green = green;
  2170   2170   						    sym->fill->blue = blue;
  2171   2171   						}
  2172   2172   					  }
  2173         -					if (strcmp (svg_name, "fill-opacity") ==
  2174         -					    0)
         2173  +					if (strcmp (svg_name, "fill-opacity")
         2174  +					    == 0)
  2175   2175   					    sym->fill->opacity =
  2176   2176   						atof (svg_value);
  2177   2177   				    }
  2178   2178   			      }
  2179   2179   			    child = child->next;
  2180   2180   			}
  2181   2181   		  }
................................................................................
  2617   2617   					const char *svg_value;
  2618   2618   					if (!svg_parameter_name
  2619   2619   					    (child, &svg_name, &svg_value))
  2620   2620   					  {
  2621   2621   					      child = child->next;
  2622   2622   					      continue;
  2623   2623   					  }
  2624         -					if (strcmp (svg_name, "font-family") ==
  2625         -					    0)
         2624  +					if (strcmp (svg_name, "font-family")
         2625  +					    == 0)
  2626   2626   					  {
  2627   2627   					      if (sym->font_families_count <
  2628   2628   						  RL2_MAX_FONT_FAMILIES)
  2629   2629   						{
  2630   2630   						    int idx =
  2631   2631   							sym->font_families_count++;
  2632   2632   						    int len =
................................................................................
  2650   2650   						  sym->font_style =
  2651   2651   						      RL2_FONT_STYLE_ITALIC;
  2652   2652   					      if (strcasecmp
  2653   2653   						  (svg_value, "oblique") == 0)
  2654   2654   						  sym->font_style =
  2655   2655   						      RL2_FONT_STYLE_OBLIQUE;
  2656   2656   					  }
  2657         -					if (strcmp (svg_name, "font-weight") ==
  2658         -					    0)
         2657  +					if (strcmp (svg_name, "font-weight")
         2658  +					    == 0)
  2659   2659   					  {
  2660   2660   					      if (strcasecmp
  2661   2661   						  (svg_value, "normal") == 0)
  2662   2662   						  sym->font_weight =
  2663   2663   						      RL2_FONT_WEIGHT_NORMAL;
  2664         -					      if (strcasecmp (svg_value, "bold")
  2665         -						  == 0)
         2664  +					      if (strcasecmp
         2665  +						  (svg_value, "bold") == 0)
  2666   2666   						  sym->font_weight =
  2667   2667   						      RL2_FONT_WEIGHT_BOLD;
  2668   2668   					  }
  2669   2669   					if (strcmp (svg_name, "font-size") == 0)
  2670   2670   					    sym->font_size = atof (svg_value);
  2671   2671   				    }
  2672   2672   			      }
................................................................................
  3016   3016         {
  3017   3017   	  if (node->type == XML_ELEMENT_NODE)
  3018   3018   	    {
  3019   3019   		const char *name = (const char *) (node->name);
  3020   3020   		if (strcmp (name, "LabelPlacement") == 0)
  3021   3021   		  {
  3022   3022   		      xmlNodePtr child = node->children;
  3023         -		      if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT
         3023  +		      if (sym->label_placement_type ==
         3024  +			  RL2_LABEL_PLACEMENT_POINT
  3024   3025   			  && sym->label_placement != NULL)
  3025   3026   			  rl2_destroy_point_placement ((rl2PrivPointPlacementPtr) (sym->label_placement));
  3026         -		      if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE
         3027  +		      if (sym->label_placement_type ==
         3028  +			  RL2_LABEL_PLACEMENT_LINE
  3027   3029   			  && sym->label_placement != NULL)
  3028   3030   			  rl2_destroy_line_placement ((rl2PrivLinePlacementPtr)
  3029   3031   						      (sym->label_placement));
  3030   3032   		      sym->label_placement_type = RL2_LABEL_PLACEMENT_UNKNOWN;
  3031   3033   		      sym->label_placement = NULL;
  3032   3034   		      while (child)
  3033   3035   			{
................................................................................
  3993   3995       rl2PrivTextSymbolizerPtr text;
  3994   3996   
  3995   3997       pR = style->first_rule;
  3996   3998       while (pR != NULL)
  3997   3999         {
  3998   4000   	  /* counting max column names */
  3999   4001   	  if (pR->column_name != NULL)
         4002  +	      count++;
         4003  +	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
  4000   4004   	    {
  4001         -		count++;
  4002         -		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4005  +		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
         4006  +		item = pV->first;
         4007  +		while (item != NULL)
  4003   4008   		  {
  4004         -		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
  4005         -		      item = pV->first;
  4006         -		      while (item != NULL)
         4009  +		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
         4010  +			  && item->symbolizer != NULL)
  4007   4011   			{
  4008         -			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
  4009         -				&& item->symbolizer != NULL)
  4010         -			      {
  4011         -				  text =
  4012         -				      (rl2PrivTextSymbolizerPtr)
  4013         -				      (item->symbolizer);
  4014         -				  if (text->label != NULL)
  4015         -				      count++;
  4016         -			      }
  4017         -			    item = item->next;
         4012  +			    text =
         4013  +				(rl2PrivTextSymbolizerPtr) (item->symbolizer);
         4014  +			    if (text->label != NULL)
         4015  +				count++;
  4018   4016   			}
         4017  +		      item = item->next;
  4019   4018   		  }
  4020   4019   	    }
  4021   4020   	  pR = pR->next;
  4022   4021         }
  4023   4022       pR = style->else_rule;
  4024   4023       if (pR != NULL)
  4025   4024         {
  4026   4025   	  if (pR->column_name != NULL)
         4026  +	      count++;
         4027  +	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
  4027   4028   	    {
  4028         -		count++;
  4029         -		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4029  +		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
         4030  +		item = pV->first;
         4031  +		while (item != NULL)
  4030   4032   		  {
  4031         -		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
  4032         -		      item = pV->first;
  4033         -		      while (item != NULL)
         4033  +		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
         4034  +			  && item->symbolizer != NULL)
  4034   4035   			{
  4035         -			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
  4036         -				&& item->symbolizer != NULL)
  4037         -			      {
  4038         -				  text =
  4039         -				      (rl2PrivTextSymbolizerPtr)
  4040         -				      (item->symbolizer);
  4041         -				  if (text->label != NULL)
  4042         -				      count++;
  4043         -			      }
  4044         -			    item = item->next;
         4036  +			    text =
         4037  +				(rl2PrivTextSymbolizerPtr) (item->symbolizer);
         4038  +			    if (text->label != NULL)
         4039  +				count++;
  4045   4040   			}
         4041  +		      item = item->next;
  4046   4042   		  }
  4047   4043   	    }
  4048   4044         }
  4049   4045       if (count == 0)
  4050   4046   	return;
  4051   4047   
  4052   4048       strings = malloc (sizeof (char *) * count);
................................................................................
  4059   4055   	  if (pR->column_name != NULL)
  4060   4056   	    {
  4061   4057   		len = strlen (pR->column_name);
  4062   4058   		*(strings + i) = malloc (len + 1);
  4063   4059   		strcpy (*(strings + i), pR->column_name);
  4064   4060   		*(dupl + i) = 'N';
  4065   4061   		i++;
  4066         -		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4062  +	    }
         4063  +	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4064  +	    {
         4065  +		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
         4066  +		item = pV->first;
         4067  +		while (item != NULL)
  4067   4068   		  {
  4068         -		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
  4069         -		      item = pV->first;
  4070         -		      while (item != NULL)
         4069  +		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
         4070  +			  && item->symbolizer != NULL)
  4071   4071   			{
  4072         -			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
  4073         -				&& item->symbolizer != NULL)
         4072  +			    text =
         4073  +				(rl2PrivTextSymbolizerPtr) (item->symbolizer);
         4074  +			    if (text->label != NULL)
  4074   4075   			      {
  4075         -				  text =
  4076         -				      (rl2PrivTextSymbolizerPtr)
  4077         -				      (item->symbolizer);
  4078         -				  if (text->label != NULL)
  4079         -				    {
  4080         -					len = strlen (text->label);
  4081         -					*(strings + i) = malloc (len + 1);
  4082         -					strcpy (*(strings + i), text->label);
  4083         -					*(dupl + i) = 'N';
  4084         -					i++;
  4085         -				    }
         4076  +				  len = strlen (text->label);
         4077  +				  *(strings + i) = malloc (len + 1);
         4078  +				  strcpy (*(strings + i), text->label);
         4079  +				  *(dupl + i) = 'N';
         4080  +				  i++;
  4086   4081   			      }
  4087         -			    item = item->next;
  4088   4082   			}
         4083  +		      item = item->next;
  4089   4084   		  }
  4090   4085   	    }
  4091   4086   	  pR = pR->next;
  4092   4087         }
  4093   4088       pR = style->else_rule;
  4094   4089       if (pR != NULL)
  4095   4090         {
................................................................................
  4096   4091   	  if (pR->column_name != NULL)
  4097   4092   	    {
  4098   4093   		len = strlen (pR->column_name);
  4099   4094   		*(strings + i) = malloc (len + 1);
  4100   4095   		strcpy (*(strings + i), pR->column_name);
  4101   4096   		*(dupl + i) = 'N';
  4102   4097   		i++;
  4103         -		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4098  +	    }
         4099  +	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
         4100  +	    {
         4101  +		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
         4102  +		item = pV->first;
         4103  +		while (item != NULL)
  4104   4104   		  {
  4105         -		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
  4106         -		      item = pV->first;
  4107         -		      while (item != NULL)
         4105  +		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
         4106  +			  && item->symbolizer != NULL)
  4108   4107   			{
  4109         -			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
  4110         -				&& item->symbolizer != NULL)
         4108  +			    text =
         4109  +				(rl2PrivTextSymbolizerPtr) (item->symbolizer);
         4110  +			    if (text->label != NULL)
  4111   4111   			      {
  4112         -				  text =
  4113         -				      (rl2PrivTextSymbolizerPtr)
  4114         -				      (item->symbolizer);
  4115         -				  if (text->label != NULL)
  4116         -				    {
  4117         -					len = strlen (text->label);
  4118         -					*(strings + i) = malloc (len + 1);
  4119         -					strcpy (*(strings + i), text->label);
  4120         -					*(dupl + i) = 'N';
  4121         -					i++;
  4122         -				    }
         4112  +				  len = strlen (text->label);
         4113  +				  *(strings + i) = malloc (len + 1);
         4114  +				  strcpy (*(strings + i), text->label);
         4115  +				  *(dupl + i) = 'N';
         4116  +				  i++;
  4123   4117   			      }
  4124         -			    item = item->next;
  4125   4118   			}
         4119  +		      item = item->next;
  4126   4120   		  }
  4127   4121   	    }
  4128   4122         }
  4129   4123   
  4130   4124       for (i = 0; i < count; i++)
  4131   4125         {
  4132   4126   	  /* identifying all duplicates */
................................................................................
  4434   4428   	  lyr->raster_stats = NULL;
  4435   4429         }
  4436   4430       return ptr;
  4437   4431   }
  4438   4432   
  4439   4433   static int
  4440   4434   rl2_group_renderer_set_raster (rl2PrivGroupRendererPtr group, int index,
  4441         -			       const char *layer_name, rl2CoveragePtr coverage,
         4435  +			       const char *layer_name,
         4436  +			       rl2CoveragePtr coverage,
  4442   4437   			       sqlite3_int64 style_id,
  4443   4438   			       rl2RasterSymbolizerPtr symbolizer,
  4444   4439   			       rl2RasterStatisticsPtr stats)
  4445   4440   {
  4446   4441   /* setting up one of the Layers within the Group */
  4447   4442       int len;
  4448   4443       rl2PrivGroupRendererLayerPtr lyr;

Changes to src/rl2tiff.c.

   547    547       uint32 height = 0;
   548    548       double cx;
   549    549       double cy;
   550    550       GTIFDefn definition;
   551    551       char *pString;
   552    552       int len;
   553    553       int basic = 0;
          554  +    short pixel_mode = RasterPixelIsArea;
   554    555       TIFF *in = (TIFF *) 0;
   555    556       GTIF *gtif = (GTIF *) 0;
   556    557   
   557    558   /* suppressing TIFF messages */
   558    559       TIFFSetErrorHandler (NULL);
   559    560       TIFFSetWarningHandler (NULL);
   560    561   
................................................................................
   640    641       origin->maxX = cx;
   641    642   
   642    643   /* computing the pixel resolution */
   643    644       origin->hResolution = (origin->maxX - origin->minX) / (double) width;
   644    645       origin->vResolution = (origin->maxY - origin->minY) / (double) height;
   645    646       origin->isGeoReferenced = 1;
   646    647       origin->isGeoTiff = 1;
          648  +
          649  +/* retrieving GTRasterTypeGeoKey */
          650  +    if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1))
          651  +	pixel_mode = RasterPixelIsArea;
          652  +    if (pixel_mode == RasterPixelIsPoint)
          653  +      {
          654  +	  /* adjusting the BBOX */
          655  +	  origin->minX -= origin->hResolution / 2.0;
          656  +	  origin->minY -= origin->vResolution / 2.0;
          657  +	  origin->maxX += origin->hResolution / 2.0;
          658  +	  origin->maxY += origin->vResolution / 2.0;
          659  +
          660  +      }
   647    661   
   648    662     error:
   649    663       if (basic && origin->isGeoTiff == 0)
   650    664   	recover_incomplete_geotiff (origin, in, width, height, force_srid);
   651    665       if (in != (TIFF *) 0)
   652    666   	XTIFFClose (in);
   653    667       if (gtif != (GTIF *) 0)
................................................................................
  1415   1429         {
  1416   1430   	  /* attempting to recover badly formatted TIFFs */
  1417   1431   	  origin->planarConfig = PLANARCONFIG_CONTIG;
  1418   1432         }
  1419   1433       else
  1420   1434   	origin->planarConfig = value16;
  1421   1435   
  1422         -    if (origin->bitsPerSample == 16 && origin->sampleFormat == SAMPLEFORMAT_UINT
         1436  +    if (origin->bitsPerSample == 16
         1437  +	&& origin->sampleFormat == SAMPLEFORMAT_UINT
  1423   1438   	&& origin->planarConfig == PLANARCONFIG_SEPARATE)
  1424   1439   	;
  1425   1440       else if (origin->bitsPerSample == 8
  1426   1441   	     && origin->sampleFormat == SAMPLEFORMAT_UINT
  1427   1442   	     && origin->planarConfig == PLANARCONFIG_SEPARATE)
  1428   1443   	;
  1429   1444       else if (origin->planarConfig != PLANARCONFIG_CONTIG)
................................................................................
  2169   2184       if (coverage->mixedResolutions)
  2170   2185         {
  2171   2186   	  /* accepting any resolution */
  2172   2187         }
  2173   2188       else if (coverage->strictResolution)
  2174   2189         {
  2175   2190   	  /* enforcing Strict Resolution check */
  2176         -	  if (hResolution != coverage->hResolution)
         2191  +	  double x_diff = fabs (coverage->hResolution - hResolution);
         2192  +	  double y_diff = fabs (coverage->vResolution - vResolution);
         2193  +	  double x_lim = coverage->hResolution / 1000000.0;
         2194  +	  double y_lim = coverage->vResolution / 1000000.0;
         2195  +	  if (x_diff > x_lim)
  2177   2196   	    {
  2178   2197   		if (verbose)
  2179   2198   		    fprintf (stderr,
  2180   2199   			     "Mismatching Horizontal Resolution (Strict) !!!\n");
  2181   2200   		return RL2_FALSE;
  2182   2201   	    }
  2183         -	  if (vResolution != coverage->vResolution)
         2202  +	  if (y_diff > y_lim)
  2184   2203   	    {
  2185   2204   		if (verbose)
  2186   2205   		    fprintf (stderr,
  2187   2206   			     "Mismatching Vertical Resolution (Strict) !!!\n");
  2188   2207   		return RL2_FALSE;
  2189   2208   	    }
  2190   2209         }
................................................................................
  2732   2751   		if (tiff_max_x < startCol)
  2733   2752   		    skip = 1;
  2734   2753   		if (skip)
  2735   2754   		  {
  2736   2755   		      /* skipping any not required tile */
  2737   2756   		      continue;
  2738   2757   		  }
  2739         -		if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0) <
  2740         -		    0)
         2758  +		if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0)
         2759  +		    < 0)
  2741   2760   		    goto error;
  2742   2761   		if (convert != RL2_CONVERT_NO)
  2743   2762   		  {
  2744   2763   		      /* applying some format conversion */
  2745   2764   		      copy_convert_tile (origin, tiff_tile, pixels, startRow,
  2746   2765   					 startCol, width, height, tile_y,
  2747   2766   					 tile_x, convert);
................................................................................
  2762   2781   			      {
  2763   2782   			      case RL2_SAMPLE_INT8:
  2764   2783   				  p_in_8 = (char *) tiff_tile;
  2765   2784   				  p_in_8 += y * origin->tileWidth;
  2766   2785   				  p_in_8 += x;
  2767   2786   				  p_out_8 = (char *) pixels;
  2768   2787   				  p_out_8 +=
  2769         -				      ((dest_y - startRow) * width) + (dest_x -
  2770         -								       startCol);
         2788  +				      ((dest_y - startRow) * width) +
         2789  +				      (dest_x - startCol);
  2771   2790   				  break;
  2772   2791   			      case RL2_SAMPLE_UINT8:
  2773   2792   				  p_in_u8 = (unsigned char *) tiff_tile;
  2774   2793   				  p_in_u8 += y * origin->tileWidth * num_bands;
  2775   2794   				  p_in_u8 += x * num_bands;
  2776   2795   				  p_out_u8 = (unsigned char *) pixels;
  2777   2796   				  p_out_u8 +=
................................................................................
  2781   2800   				  break;
  2782   2801   			      case RL2_SAMPLE_INT16:
  2783   2802   				  p_in_16 = (short *) tiff_tile;
  2784   2803   				  p_in_16 += y * origin->tileWidth;
  2785   2804   				  p_in_16 += x;
  2786   2805   				  p_out_16 = (short *) pixels;
  2787   2806   				  p_out_16 +=
  2788         -				      ((dest_y - startRow) * width) + (dest_x -
  2789         -								       startCol);
         2807  +				      ((dest_y - startRow) * width) +
         2808  +				      (dest_x - startCol);
  2790   2809   				  break;
  2791   2810   			      case RL2_SAMPLE_UINT16:
  2792   2811   				  p_in_u16 = (unsigned short *) tiff_tile;
  2793   2812   				  p_in_u16 += y * origin->tileWidth * num_bands;
  2794   2813   				  p_in_u16 += x * num_bands;
  2795   2814   				  p_out_u16 = (unsigned short *) pixels;
  2796   2815   				  p_out_u16 +=
................................................................................
  2800   2819   				  break;
  2801   2820   			      case RL2_SAMPLE_INT32:
  2802   2821   				  p_in_32 = (int *) tiff_tile;
  2803   2822   				  p_in_32 += y * origin->tileWidth;
  2804   2823   				  p_in_32 += x;
  2805   2824   				  p_out_32 = (int *) pixels;
  2806   2825   				  p_out_32 +=
  2807         -				      ((dest_y - startRow) * width) + (dest_x -
  2808         -								       startCol);
         2826  +				      ((dest_y - startRow) * width) +
         2827  +				      (dest_x - startCol);
  2809   2828   				  break;
  2810   2829   			      case RL2_SAMPLE_UINT32:
  2811   2830   				  p_in_u32 = (unsigned int *) tiff_tile;
  2812   2831   				  p_in_u32 += y * origin->tileWidth;
  2813   2832   				  p_in_u32 += x;
  2814   2833   				  p_out_u32 = (unsigned int *) pixels;
  2815   2834   				  p_out_u32 +=
  2816         -				      ((dest_y - startRow) * width) + (dest_x -
  2817         -								       startCol);
         2835  +				      ((dest_y - startRow) * width) +
         2836  +				      (dest_x - startCol);
  2818   2837   				  break;
  2819   2838   			      case RL2_SAMPLE_FLOAT:
  2820   2839   				  p_in_flt = (float *) tiff_tile;
  2821   2840   				  p_in_flt += y * origin->tileWidth;
  2822   2841   				  p_in_flt += x;
  2823   2842   				  p_out_flt = (float *) pixels;
  2824   2843   				  p_out_flt +=
  2825         -				      ((dest_y - startRow) * width) + (dest_x -
  2826         -								       startCol);
         2844  +				      ((dest_y - startRow) * width) +
         2845  +				      (dest_x - startCol);
  2827   2846   				  break;
  2828   2847   			      case RL2_SAMPLE_DOUBLE:
  2829   2848   				  p_in_dbl = (double *) tiff_tile;
  2830   2849   				  p_in_dbl += y * origin->tileWidth;
  2831   2850   				  p_in_dbl += x;
  2832   2851   				  p_out_dbl = (double *) pixels;
  2833   2852   				  p_out_dbl +=
  2834         -				      ((dest_y - startRow) * width) + (dest_x -
  2835         -								       startCol);
         2853  +				      ((dest_y - startRow) * width) +
         2854  +				      (dest_x - startCol);
  2836   2855   				  break;
  2837   2856   			      };
  2838   2857   			    for (bnd = 0; bnd < num_bands; bnd++)
  2839   2858   			      {
  2840   2859   				  switch (sample_type)
  2841   2860   				    {
  2842   2861   				    case RL2_SAMPLE_INT8:
................................................................................
  3372   3391         }
  3373   3392   
  3374   3393       for (y = 0; y < height; y++)
  3375   3394         {
  3376   3395   	  /* scanning scanlines by row */
  3377   3396   	  line_no = y + startRow;
  3378   3397   	  if (line_no >= origin->height)
  3379         -	    {
  3380         -		switch (sample_type)
  3381         -		  {
  3382         -		  case RL2_SAMPLE_INT8:
  3383         -		      p_out_8 = (char *) pixels;
  3384         -		      for (x = 0; x < width; x++)
  3385         -			  *p_out_8++ = 0;
  3386         -		      break;
  3387         -		  case RL2_SAMPLE_UINT8:
  3388         -		      p_out_u8 = (unsigned char *) pixels;
  3389         -		      for (x = 0; x < width * num_bands; x++)
  3390         -			  *p_out_u8++ = 0;
  3391         -		      break;
  3392         -		  case RL2_SAMPLE_INT16:
  3393         -		      p_out_16 = (short *) pixels;
  3394         -		      for (x = 0; x < width; x++)
  3395         -			  *p_out_16++ = 0;
  3396         -		      break;
  3397         -		  case RL2_SAMPLE_UINT16:
  3398         -		      p_out_u16 = (unsigned short *) pixels;
  3399         -		      for (x = 0; x < width * num_bands; x++)
  3400         -			  *p_out_u16++ = 0;
  3401         -		      break;
  3402         -		  case RL2_SAMPLE_INT32:
  3403         -		      p_out_32 = (int *) pixels;
  3404         -		      for (x = 0; x < width; x++)
  3405         -			  *p_out_32++ = 0;
  3406         -		      break;
  3407         -		  case RL2_SAMPLE_UINT32:
  3408         -		      p_out_u32 = (unsigned int *) pixels;
  3409         -		      for (x = 0; x < width; x++)
  3410         -			  *p_out_u32++ = 0;
  3411         -		      break;
  3412         -		  case RL2_SAMPLE_FLOAT:
  3413         -		      p_out_flt = (float *) pixels;
  3414         -		      for (x = 0; x < width; x++)
  3415         -			  *p_out_flt++ = 0;
  3416         -		      break;
  3417         -		  case RL2_SAMPLE_DOUBLE:
  3418         -		      p_out_dbl = (double *) pixels;
  3419         -		      for (x = 0; x < width; x++)
  3420         -			  *p_out_dbl++ = 0;
  3421         -		      break;
  3422         -		  default:
  3423         -		      goto error;
  3424         -		  };
  3425         -		continue;
  3426         -	    }
         3398  +	      continue;
  3427   3399   	  if (TIFFReadScanline (in, tiff_scanline, line_no, 0) < 0)
  3428   3400   	      goto error;
  3429   3401   	  if (convert != RL2_CONVERT_NO)
  3430   3402   	    {
  3431   3403   		/* applying some format conversion */
  3432   3404   		copy_convert_scanline (origin, tiff_scanline, pixels, y,
  3433   3405   				       startCol, width, convert);
................................................................................
  3641   3613   					p_in_u16 = (unsigned short *) tiff_tile;
  3642   3614   					p_in_u16 += y * origin->tileWidth;
  3643   3615   					p_in_u16 += x;
  3644   3616   					p_out_u16 = (unsigned short *) pixels;
  3645   3617   					p_out_u16 +=
  3646   3618   					    ((dest_y -
  3647   3619   					      startRow) * width * num_bands) +
  3648         -					    ((dest_x - startCol) * num_bands) +
  3649         -					    band;
         3620  +					    ((dest_x -
         3621  +					      startCol) * num_bands) + band;
  3650   3622   					*p_out_u16 = *p_in_u16;
  3651   3623   				    }
  3652   3624   				  if (sample_type == RL2_SAMPLE_UINT8)
  3653   3625   				    {
  3654   3626   					p_in_u8 = (unsigned char *) tiff_tile;
  3655   3627   					p_in_u8 += y * origin->tileWidth;
  3656   3628   					p_in_u8 += x;
  3657   3629   					p_out_u8 = (unsigned char *) pixels;
  3658   3630   					p_out_u8 +=
  3659   3631   					    ((dest_y -
  3660   3632   					      startRow) * width * num_bands) +
  3661         -					    ((dest_x - startCol) * num_bands) +
  3662         -					    band;
         3633  +					    ((dest_x -
         3634  +					      startCol) * num_bands) + band;
  3663   3635   					*p_out_u8 = *p_in_u8;
  3664   3636   				    }
  3665   3637   			      }
  3666   3638   			}
  3667   3639   		  }
  3668   3640   	    }
  3669   3641         }
................................................................................
  3673   3645     error:
  3674   3646       if (tiff_tile != NULL)
  3675   3647   	free (tiff_tile);
  3676   3648       return RL2_ERROR;
  3677   3649   }
  3678   3650   
  3679   3651   static int
  3680         -read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin, unsigned short width,
  3681         -			     unsigned short height, unsigned char sample_type,
         3652  +read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin,
         3653  +			     unsigned short width, unsigned short height,
         3654  +			     unsigned char sample_type,
  3682   3655   			     unsigned char num_bands, unsigned int startRow,
  3683   3656   			     unsigned int startCol, void *pixels)
  3684   3657   {
  3685   3658   /* reading TIFF raw strips - separate planes */
  3686   3659       uint32 line_no;
  3687   3660       uint32 x;
  3688   3661       uint32 y;
................................................................................
  4172   4145   	      goto error;
  4173   4146         }
  4174   4147       else
  4175   4148         {
  4176   4149   	  /* contiguous planar configuration */
  4177   4150   	  if (origin->bitsPerSample <= 8
  4178   4151   	      && origin->sampleFormat == SAMPLEFORMAT_UINT
  4179         -	      && (origin->samplesPerPixel == 1 || origin->samplesPerPixel == 3)
         4152  +	      && (origin->samplesPerPixel == 1
         4153  +		  || origin->samplesPerPixel == 3)
  4180   4154   	      && (pixel_type == RL2_PIXEL_MONOCHROME
  4181   4155   		  || pixel_type == RL2_PIXEL_PALETTE
  4182   4156   		  || pixel_type == RL2_PIXEL_GRAYSCALE
  4183   4157   		  || pixel_type == RL2_PIXEL_RGB))
  4184   4158   	    {
  4185   4159   		/* using the TIFF RGBA methods */
  4186   4160   		if (origin->isTiled)
................................................................................
  4202   4176   		if (origin->isTiled)
  4203   4177   		    ret =
  4204   4178   			read_raw_tiles (origin, width, height, sample_type,
  4205   4179   					num_bands, startRow, startCol,
  4206   4180   					bufPixels);
  4207   4181   		else
  4208   4182   		    ret =
  4209         -			read_raw_scanlines (origin, width, height, sample_type,
  4210         -					    num_bands, startRow, startCol,
  4211         -					    bufPixels);
         4183  +			read_raw_scanlines (origin, width, height,
         4184  +					    sample_type, num_bands, startRow,
         4185  +					    startCol, bufPixels);
  4212   4186   		if (ret != RL2_OK)
  4213   4187   		    goto error;
  4214   4188   	    }
  4215   4189         }
  4216   4190   
  4217   4191       *pixels = bufPixels;
  4218   4192       *pixels_sz = bufPixelsSz;
................................................................................
  4382   4356   		  }
  4383   4357   	    }
  4384   4358         }
  4385   4359   
  4386   4360   /* attempting to create the tile */
  4387   4361       if (read_from_tiff
  4388   4362   	(origin, coverage->tileWidth, coverage->tileHeight,
  4389         -	 coverage->sampleType, coverage->pixelType, coverage->nBands, startRow,
  4390         -	 startCol, &pixels, &pixels_sz, palette) != RL2_OK)
         4363  +	 coverage->sampleType, coverage->pixelType, coverage->nBands,
         4364  +	 startRow, startCol, &pixels, &pixels_sz, palette) != RL2_OK)
  4391   4365   	goto error;
  4392   4366       if (startCol + coverage->tileWidth > origin->width)
  4393   4367   	unused_width = (startCol + coverage->tileWidth) - origin->width;
  4394   4368       if (startRow + coverage->tileHeight > origin->height)
  4395   4369   	unused_height = (startRow + coverage->tileHeight) - origin->height;
  4396   4370       if (unused_width || unused_height)
  4397   4371         {
................................................................................
  5078   5052     error:
  5079   5053       return 0;
  5080   5054   }
  5081   5055   
  5082   5056   RL2_DECLARE rl2TiffDestinationPtr
  5083   5057   rl2_create_tiff_destination (const char *path, unsigned int width,
  5084   5058   			     unsigned int height, unsigned char sample_type,
  5085         -			     unsigned char pixel_type, unsigned char num_bands,
  5086         -			     rl2PalettePtr plt, unsigned char tiff_compression,
  5087         -			     int tiled, unsigned int tile_size)
         5059  +			     unsigned char pixel_type,
         5060  +			     unsigned char num_bands, rl2PalettePtr plt,
         5061  +			     unsigned char tiff_compression, int tiled,
         5062  +			     unsigned int tile_size)
  5088   5063   {
  5089   5064   /* attempting to create a file-based TIFF destination (no georeferencing) */
  5090   5065       rl2PrivTiffDestinationPtr destination = NULL;
  5091   5066       if (!check_color_model
  5092   5067   	(sample_type, pixel_type, num_bands, plt, tiff_compression))
  5093   5068         {
  5094   5069   	  fprintf (stderr, "RL2-TIFF writer: unsupported pixel format\n");
................................................................................
  5760   5735         }
  5761   5736       if (TIFFWriteScanline (tiff->out, tiff->tiffBuffer, row, 0) < 0)
  5762   5737   	return 0;
  5763   5738       return 1;
  5764   5739   }
  5765   5740   
  5766   5741   static int
  5767         -tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster,
  5768         -		       unsigned int row)
         5742  +tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff,
         5743  +		       rl2PrivRasterPtr raster, unsigned int row)
  5769   5744   {
  5770   5745   /* writing a TIFF Grayscale scanline */
  5771   5746       unsigned int x;
  5772   5747       unsigned char *p_in = raster->rasterBuffer;
  5773   5748       unsigned char *p_out = tiff->tiffBuffer;
  5774   5749   
  5775   5750       for (x = 0; x < raster->width; x++)
................................................................................
  6163   6138   	      0)
  6164   6139   	      return 0;
  6165   6140         }
  6166   6141       return 1;
  6167   6142   }
  6168   6143   
  6169   6144   static int
  6170         -tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster,
  6171         -			unsigned int row, unsigned int col)
         6145  +tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff,
         6146  +			rl2PrivRasterPtr raster, unsigned int row,
         6147  +			unsigned int col)
  6172   6148   {
  6173   6149   /* writing a TIFF RGB tile - UINT8 */
  6174   6150       unsigned int y;
  6175   6151       unsigned int x;
  6176   6152       unsigned char *p_in = raster->rasterBuffer;
  6177   6153       unsigned char *p_out = tiff->tiffBuffer;
  6178   6154   
................................................................................
  6539   6515   	     && rst->nBands == destination->samplesPerPixel
  6540   6516   	     && destination->tileWidth == rst->width
  6541   6517   	     && destination->tileHeight == rst->height)
  6542   6518   	ret =
  6543   6519   	    tiff_write_tile_multiband16 (destination, rst, startRow, startCol);
  6544   6520       else if (destination->sampleFormat == SAMPLEFORMAT_UINT
  6545   6521   	     && destination->samplesPerPixel == 1
  6546         -	     && destination->photometric < 2 && destination->bitsPerSample == 8
         6522  +	     && destination->photometric < 2
         6523  +	     && destination->bitsPerSample == 8
  6547   6524   	     && rst->sampleType == RL2_SAMPLE_UINT8
  6548   6525   	     && rst->pixelType == RL2_PIXEL_GRAYSCALE && rst->nBands == 1
  6549   6526   	     && destination->tileWidth == rst->width
  6550   6527   	     && destination->tileHeight == rst->height)
  6551   6528   	ret = tiff_write_tile_gray (destination, rst, startRow, startCol);
  6552   6529       else if (destination->sampleFormat == SAMPLEFORMAT_UINT
  6553   6530   	     && destination->samplesPerPixel == 1
................................................................................
  6658   6635   	return RL2_ERROR;
  6659   6636       if (destination->tfw_path == NULL)
  6660   6637   	return RL2_ERROR;
  6661   6638   
  6662   6639       tfw = fopen (destination->tfw_path, "w");
  6663   6640       if (tfw == NULL)
  6664   6641         {
  6665         -	  fprintf (stderr, "RL2-TIFF writer: unable to open Worldfile \"%s\"\n",
         6642  +	  fprintf (stderr,
         6643  +		   "RL2-TIFF writer: unable to open Worldfile \"%s\"\n",
  6666   6644   		   destination->tfw_path);
  6667   6645   	  return RL2_ERROR;
  6668   6646         }
  6669   6647       fprintf (tfw, "        %1.16f\n", destination->hResolution);
  6670   6648       fprintf (tfw, "        0.0\n");
  6671   6649       fprintf (tfw, "        0.0\n");
  6672   6650       fprintf (tfw, "        -%1.16f\n", destination->vResolution);
................................................................................
  6975   6953       TIFFClose (in);
  6976   6954       if (tiff_buffer != NULL)
  6977   6955   	free (tiff_buffer);
  6978   6956       return RL2_ERROR;
  6979   6957   }
  6980   6958   
  6981   6959   static int
  6982         -rgb_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width,
  6983         -		 unsigned short height)
         6960  +rgb_tiff_common (TIFF * out, const unsigned char *buffer,
         6961  +		 unsigned short width, unsigned short height)
  6984   6962   {
  6985   6963   /* common implementation of RGB TIFF export */
  6986   6964       tsize_t buf_size;
  6987   6965       void *tiff_buffer = NULL;
  6988   6966       int y;
  6989   6967       int x;
  6990   6968       const unsigned char *p_in;
................................................................................
  7258   7236       return 0;
  7259   7237   }
  7260   7238   
  7261   7239   static int
  7262   7240   output_palette_tiff (const unsigned char *buffer,
  7263   7241   		     unsigned short width,
  7264   7242   		     unsigned short height, unsigned char *red,
  7265         -		     unsigned char *green, unsigned char *blue, int max_palette,
  7266         -		     unsigned char **blob, int *blob_size)
         7243  +		     unsigned char *green, unsigned char *blue,
         7244  +		     int max_palette, unsigned char **blob, int *blob_size)
  7267   7245   {
  7268   7246   /* generating a PALETTE TIFF - actual work */
  7269   7247       struct memfile clientdata;
  7270   7248       TIFF *out = (TIFF *) 0;
  7271   7249   
  7272   7250   /* suppressing TIFF warnings */
  7273   7251       TIFFSetWarningHandler (NULL);
................................................................................
  7507   7485   	       tiff_size))
  7508   7486   	      return RL2_ERROR;
  7509   7487         }
  7510   7488       return RL2_OK;
  7511   7489   }
  7512   7490   
  7513   7491   static int
  7514         -gray_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width,
  7515         -		  unsigned short height)
         7492  +gray_tiff_common (TIFF * out, const unsigned char *buffer,
         7493  +		  unsigned short width, unsigned short height)
  7516   7494   {
  7517   7495   /* common implementation of Grayscale TIFF export */
  7518   7496       tsize_t buf_size;
  7519   7497       void *tiff_buffer = NULL;
  7520   7498       int y;
  7521   7499       int x;
  7522   7500       const unsigned char *p_in;
................................................................................
  7987   7965   	xml =
  7988   7966   	    sqlite3_mprintf ("%s<Compression>%u</Compression>", prev,
  7989   7967   			     org->compression);
  7990   7968       sqlite3_free (prev);
  7991   7969       prev = xml;
  7992   7970       if (org->sampleFormat == SAMPLEFORMAT_UINT)
  7993   7971   	xml =
  7994         -	    sqlite3_mprintf ("%s<SampleFormat>unsigned integer</SampleFormat>",
  7995         -			     prev);
         7972  +	    sqlite3_mprintf
         7973  +	    ("%s<SampleFormat>unsigned integer</SampleFormat>", prev);
  7996   7974       else if (org->sampleFormat == SAMPLEFORMAT_INT)
  7997   7975   	xml =
  7998   7976   	    sqlite3_mprintf ("%s<SampleFormat>signed integer</SampleFormat>",
  7999   7977   			     prev);
  8000   7978       else if (org->sampleFormat == SAMPLEFORMAT_IEEEFP)
  8001   7979   	xml =
  8002   7980   	    sqlite3_mprintf ("%s<SampleFormat>floating point</SampleFormat>",
................................................................................
  8082   8060   	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
  8083   8061   	  sqlite3_free (prev);
  8084   8062   	  prev = xml;
  8085   8063   	  xml = sqlite3_mprintf ("%s<Extent>", prev);
  8086   8064   	  sqlite3_free (prev);
  8087   8065   	  prev = xml;
  8088   8066   	  xml =
  8089         -	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
  8090         -			       prev, org->maxX - org->minX);
         8067  +	      sqlite3_mprintf
         8068  +	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
         8069  +	       org->maxX - org->minX);
  8091   8070   	  sqlite3_free (prev);
  8092   8071   	  prev = xml;
  8093   8072   	  xml =
  8094   8073   	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
  8095   8074   			       prev, org->maxY - org->minY);
  8096   8075   	  sqlite3_free (prev);
  8097   8076   	  prev = xml;

Changes to src/rl2webp.c.

   154    154   	  else
   155    155   	      return RL2_ERROR;
   156    156         }
   157    157       return RL2_OK;
   158    158   }
   159    159   
   160    160   static void
   161         -copy_pixels (unsigned char *out, const unsigned char *in, int width, int height,
   162         -	     int num_bands)
          161  +copy_pixels (unsigned char *out, const unsigned char *in, int width,
          162  +	     int height, int num_bands)
   163    163   {
   164    164   /* copying pixels */
   165    165       int x;
   166    166       int y;
   167    167       int ib;
   168    168       const unsigned char *p_in = in;
   169    169       unsigned char *p_out = out;
................................................................................
   293    293   	RL2_ERROR)
   294    294   	return RL2_ERROR;
   295    295       if (quality > 100)
   296    296   	quality = 100;
   297    297       if (quality < 0)
   298    298   	quality = 75;
   299    299       size =
   300         -	WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4, quality,
   301         -			&output);
          300  +	WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4,
          301  +			quality, &output);
   302    302       free (rgba);
   303    303       if (size == 0)
   304    304   	return RL2_ERROR;
   305    305       *webp = output;
   306    306       *webp_size = size;
   307    307       return RL2_OK;
   308    308   }

Changes to src/rl2wms.c.

   534    534       while (pI != NULL)
   535    535         {
   536    536   	  /* populating the array */
   537    537   	  *(cache->SortedByUrl + pos) = pI;
   538    538   	  pos++;
   539    539   	  pI = pI->Next;
   540    540         }
   541         -    qsort (cache->SortedByUrl, cache->NumCachedItems, sizeof (wmsCachedItemPtr),
   542         -	   compare_url);
          541  +    qsort (cache->SortedByUrl, cache->NumCachedItems,
          542  +	   sizeof (wmsCachedItemPtr), compare_url);
   543    543   }
   544    544   
   545    545   static void
   546    546   wmsCacheSqueeze (wmsCachePtr cache, int limit)
   547    547   {
   548    548   /* squeezing the WMS Cache */
   549    549       int i;
................................................................................
   592    592   	cache->LastCapab->Next = ptr;
   593    593       cache->LastCapab = ptr;
   594    594       cache->TotalDownload += (double) size;
   595    595   }
   596    596   
   597    597   
   598    598   static void
   599         -wmsAddCachedItem (wmsCachePtr cache, const char *url, const unsigned char *item,
   600         -		  int size, const char *image_format)
          599  +wmsAddCachedItem (wmsCachePtr cache, const char *url,
          600  +		  const unsigned char *item, int size, const char *image_format)
   601    601   {
   602    602   /* adding a new WMS Cached Item */
   603    603       wmsCachedItemPtr ptr;
   604    604       if (cache == NULL)
   605    605   	return;
   606    606       if (cache->CurrentSize + size > cache->MaxSize)
   607    607   	wmsCacheSqueeze (cache, cache->MaxSize - size);
................................................................................
  1099   1099   	ptr->first = arg;
  1100   1100       if (ptr->last != NULL)
  1101   1101   	ptr->last->next = arg;
  1102   1102       ptr->last = arg;
  1103   1103   }
  1104   1104   
  1105   1105   static void
  1106         -parse_pattern_bbox (const char *value, double *minx, double *miny, double *maxx,
  1107         -		    double *maxy)
         1106  +parse_pattern_bbox (const char *value, double *minx, double *miny,
         1107  +		    double *maxx, double *maxy)
  1108   1108   {
  1109   1109   /* parsing a BBOX arg [minx,miny,maxx,maxy] */
  1110   1110       int step = 0;
  1111   1111       const char *p_start = value;
  1112   1112       const char *p_end = value;
  1113   1113       *minx = DBL_MAX;
  1114   1114       *miny = DBL_MAX;
................................................................................
  2027   2027   		outbuf.WriteOffset -= 2;
  2028   2028   		continue;
  2029   2029   	    }
  2030   2030   	  if (cdata)
  2031   2031   	    {
  2032   2032   		/* masking XML special characters */
  2033   2033   		if (*(p_in + i) == '<')
  2034         -		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&lt;",
  2035         -					4);
         2034  +		    wmsMemBufferAppend (&outbuf,
         2035  +					(const unsigned char *) "&lt;", 4);
  2036   2036   		else if (*(p_in + i) == '>')
  2037         -		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&gt;",
  2038         -					4);
         2037  +		    wmsMemBufferAppend (&outbuf,
         2038  +					(const unsigned char *) "&gt;", 4);
  2039   2039   		else if (*(p_in + i) == '&')
  2040   2040   		    wmsMemBufferAppend (&outbuf,
  2041   2041   					(const unsigned char *) "&amp;", 5);
  2042   2042   		else if (*(p_in + i) == '>')
  2043   2043   		    wmsMemBufferAppend (&outbuf,
  2044   2044   					(const unsigned char *) "&quot;", 6);
  2045   2045   		else
................................................................................
  2119   2119   		outbuf.WriteOffset -= 2;
  2120   2120   		continue;
  2121   2121   	    }
  2122   2122   	  if (cdata)
  2123   2123   	    {
  2124   2124   		/* masking XML special characters */
  2125   2125   		if (*(p_in + i) == '<')
  2126         -		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&lt;",
  2127         -					4);
         2126  +		    wmsMemBufferAppend (&outbuf,
         2127  +					(const unsigned char *) "&lt;", 4);
  2128   2128   		else if (*(p_in + i) == '>')
  2129         -		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&gt;",
  2130         -					4);
         2129  +		    wmsMemBufferAppend (&outbuf,
         2130  +					(const unsigned char *) "&gt;", 4);
  2131   2131   		else if (*(p_in + i) == '&')
  2132   2132   		    wmsMemBufferAppend (&outbuf,
  2133   2133   					(const unsigned char *) "&amp;", 5);
  2134   2134   		else if (*(p_in + i) == '>')
  2135   2135   		    wmsMemBufferAppend (&outbuf,
  2136   2136   					(const unsigned char *) "&quot;", 6);
  2137   2137   		else
................................................................................
  2705   2705   		      if (child_node != NULL)
  2706   2706   			{
  2707   2707   			    if (child_node->type == XML_TEXT_NODE)
  2708   2708   				*contact_organization =
  2709   2709   				    (const char *) (child_node->content);
  2710   2710   			}
  2711   2711   		  }
  2712         -		if (strcmp ((const char *) (cur_node->name), "ContactPerson") ==
  2713         -		    0)
         2712  +		if (strcmp ((const char *) (cur_node->name), "ContactPerson")
         2713  +		    == 0)
  2714   2714   		  {
  2715   2715   		      child_node = cur_node->children;
  2716   2716   		      if (child_node != NULL)
  2717   2717   			{
  2718   2718   			    if (child_node->type == XML_TEXT_NODE)
  2719   2719   				*contact_person =
  2720   2720   				    (const char *) (child_node->content);
................................................................................
  2752   2752   		      child_node = cur_node->children;
  2753   2753   		      if (child_node != NULL)
  2754   2754   			{
  2755   2755   			    if (child_node->type == XML_TEXT_NODE)
  2756   2756   				*city = (const char *) (child_node->content);
  2757   2757   			}
  2758   2758   		  }
  2759         -		if (strcmp ((const char *) (cur_node->name), "StateOrProvince")
  2760         -		    == 0)
         2759  +		if (strcmp
         2760  +		    ((const char *) (cur_node->name), "StateOrProvince") == 0)
  2761   2761   		  {
  2762   2762   		      child_node = cur_node->children;
  2763   2763   		      if (child_node != NULL)
  2764   2764   			{
  2765   2765   			    if (child_node->type == XML_TEXT_NODE)
  2766   2766   				*state_province =
  2767   2767   				    (const char *) (child_node->content);
................................................................................
  2805   2805       xmlNodePtr cur_node = NULL;
  2806   2806       xmlNodePtr child_node = NULL;
  2807   2807   
  2808   2808       for (cur_node = node; cur_node; cur_node = cur_node->next)
  2809   2809         {
  2810   2810   	  if (cur_node->type == XML_ELEMENT_NODE)
  2811   2811   	    {
  2812         -		if (strcmp ((const char *) (cur_node->name), "ContactPosition")
  2813         -		    == 0)
         2812  +		if (strcmp
         2813  +		    ((const char *) (cur_node->name), "ContactPosition") == 0)
  2814   2814   		  {
  2815   2815   		      child_node = cur_node->children;
  2816   2816   		      if (child_node != NULL)
  2817   2817   			{
  2818   2818   			    if (child_node->type == XML_TEXT_NODE)
  2819   2819   				*contact_position =
  2820   2820   				    (const char *) (child_node->content);
................................................................................
  2934   2934   		    ((const char *) (cur_node->name),
  2935   2935   		     "ContactInformation") == 0)
  2936   2936   		    parse_wms_contact_information (cur_node->children,
  2937   2937   						   &contact_person,
  2938   2938   						   &contact_organization,
  2939   2939   						   &contact_position,
  2940   2940   						   &postal_address, &city,
  2941         -						   &state_province, &post_code,
  2942         -						   &country, &voice_telephone,
         2941  +						   &state_province,
         2942  +						   &post_code, &country,
         2943  +						   &voice_telephone,
  2943   2944   						   &fax_telephone,
  2944   2945   						   &email_address);
  2945   2946   		if (strcmp ((const char *) (cur_node->name), "Fees") == 0)
  2946   2947   		  {
  2947   2948   		      child_node = cur_node->children;
  2948   2949   		      if (child_node != NULL)
  2949   2950   			{
................................................................................
  3245   3246   						    cap->GetMapURLGet = NULL;
  3246   3247   						}
  3247   3248   					      p = (const char
  3248   3249   						   *) (text->content);
  3249   3250   					      len = strlen (p);
  3250   3251   					      cap->GetTileServiceURLGet =
  3251   3252   						  malloc (len + 1);
  3252         -					      strcpy (cap->GetTileServiceURLGet,
  3253         -						      p);
         3253  +					      strcpy
         3254  +						  (cap->GetTileServiceURLGet,
         3255  +						   p);
  3254   3256   					  }
  3255   3257   				    }
  3256   3258   			      }
  3257   3259   			    attr = attr->next;
  3258   3260   			}
  3259   3261   		  }
  3260   3262   	    }
................................................................................
  3284   3286   				  if (strcmp
  3285   3287   				      ((const char *) (attr->name),
  3286   3288   				       "href") == 0)
  3287   3289   				    {
  3288   3290   					xmlNodePtr text = attr->children;
  3289   3291   					if (text->type == XML_TEXT_NODE)
  3290   3292   					  {
  3291         -					      if (cap->GetTileServiceURLPost !=
  3292         -						  NULL)
         3293  +					      if (cap->GetTileServiceURLPost
         3294  +						  != NULL)
  3293   3295   						{
  3294   3296   						    free (cap->
  3295   3297   							  GetTileServiceURLPost);
  3296   3298   						    cap->GetTileServiceURLPost =
  3297   3299   							NULL;
  3298   3300   						}
  3299   3301   					      p = (const char
................................................................................
  3349   3351   							NULL;
  3350   3352   						}
  3351   3353   					      p = (const char
  3352   3354   						   *) (text->content);
  3353   3355   					      len = strlen (p);
  3354   3356   					      cap->GetFeatureInfoURLGet =
  3355   3357   						  malloc (len + 1);
  3356         -					      strcpy (cap->GetFeatureInfoURLGet,
  3357         -						      p);
         3358  +					      strcpy
         3359  +						  (cap->GetFeatureInfoURLGet,
         3360  +						   p);
  3358   3361   					  }
  3359   3362   				    }
  3360   3363   			      }
  3361   3364   			    attr = attr->next;
  3362   3365   			}
  3363   3366   		  }
  3364   3367   	    }
................................................................................
  3388   3391   				  if (strcmp
  3389   3392   				      ((const char *) (attr->name),
  3390   3393   				       "href") == 0)
  3391   3394   				    {
  3392   3395   					xmlNodePtr text = attr->children;
  3393   3396   					if (text->type == XML_TEXT_NODE)
  3394   3397   					  {
  3395         -					      if (cap->GetFeatureInfoURLPost !=
  3396         -						  NULL)
         3398  +					      if (cap->GetFeatureInfoURLPost
         3399  +						  != NULL)
  3397   3400   						{
  3398   3401   						    free (cap->GetFeatureInfoURLPost);
  3399   3402   						    cap->GetFeatureInfoURLPost =
  3400   3403   							NULL;
  3401   3404   						}
  3402   3405   					      p = (const char
  3403   3406   						   *) (text->content);
................................................................................
  3582   3585   					    ok = 1;
  3583   3586   					if (strcmp
  3584   3587   					    (format,
  3585   3588   					     "application/vnd.ogc.gml") == 0)
  3586   3589   					    ok = 1;
  3587   3590   					if (strcmp
  3588   3591   					    (format,
  3589         -					     "application/vnd.ogc.gml/3.1.1") ==
  3590         -					    0)
         3592  +					     "application/vnd.ogc.gml/3.1.1")
         3593  +					    == 0)
  3591   3594   					    ok = 1;
  3592   3595   					if (ok)
  3593   3596   					  {
  3594   3597   					      int len = strlen (format);
  3595   3598   					      cap->GmlMimeType =
  3596   3599   						  malloc (len + 1);
  3597   3600   					      strcpy (cap->GmlMimeType, format);
................................................................................
  4377   4380   
  4378   4381       for (; cur_node; cur_node = cur_node->next)
  4379   4382         {
  4380   4383   	  if (cur_node->type == XML_ELEMENT_NODE)
  4381   4384   	    {
  4382   4385   		if (strcmp ((const char *) (cur_node->name), "Service") == 0)
  4383   4386   		    parse_tile_service_info (cur_node, cap);
  4384         -		if (strcmp ((const char *) (cur_node->name), "TiledPatterns") ==
  4385         -		    0)
         4387  +		if (strcmp ((const char *) (cur_node->name), "TiledPatterns")
         4388  +		    == 0)
  4386   4389   		    parse_tiled_patterns (cur_node, cap);
  4387   4390   	    }
  4388   4391         }
  4389   4392   }
  4390   4393   
  4391   4394   static void
  4392   4395   parse_wms_get_tile_service (wmsCapabilitiesPtr capabilities, const char *buf)
................................................................................
  4759   4762       else
  4760   4763   	return;
  4761   4764   
  4762   4765       for (; cur_node; cur_node = cur_node->next)
  4763   4766         {
  4764   4767   	  if (cur_node->type == XML_ELEMENT_NODE)
  4765   4768   	    {
  4766         -		if (strcmp ((const char *) (cur_node->name), "featureMember") ==
  4767         -		    0)
         4769  +		if (strcmp ((const char *) (cur_node->name), "featureMember")
         4770  +		    == 0)
  4768   4771   		    parse_wms_feature_member (cur_node->children, coll);
  4769   4772   	    }
  4770   4773         }
  4771   4774   }
  4772   4775   
  4773   4776   static wmsFeatureCollectionPtr
  4774   4777   parse_wms_feature_collection (const char *buf)
................................................................................
  4829   4832   	    }
  4830   4833         }
  4831   4834   
  4832   4835       return coll;
  4833   4836   }
  4834   4837   
  4835   4838   static int
  4836         -query_TileService (rl2WmsCachePtr cache_handle, wmsCapabilitiesPtr capabilities,
  4837         -		   const char *proxy)
         4839  +query_TileService (rl2WmsCachePtr cache_handle,
         4840  +		   wmsCapabilitiesPtr capabilities, const char *proxy)
  4838   4841   {
  4839   4842   /* attempting to get and parse a WMS GetTileService request */
  4840   4843       CURL *curl = NULL;
  4841   4844       CURLcode res;
  4842   4845       wmsMemBuffer headerBuf;
  4843   4846       wmsMemBuffer bodyBuf;
  4844   4847       int http_status;
................................................................................
  6945   6948   	  attr = attr->next;
  6946   6949         }
  6947   6950       return NULL;
  6948   6951   }
  6949   6952   
  6950   6953   RL2_DECLARE int
  6951   6954   get_wms_feature_attribute_blob_geometry (rl2WmsFeatureMemberPtr handle,
  6952         -					 int index, const unsigned char **blob,
         6955  +					 int index,
         6956  +					 const unsigned char **blob,
  6953   6957   					 int *blob_size)
  6954   6958   {
  6955   6959   /* attempting to get the Nth FeatureAttribute (Geometry) from some WMS-FeatureMember object */
  6956   6960       int count = 0;
  6957   6961       wmsFeatureAttributePtr attr;
  6958   6962       wmsFeatureMemberPtr ptr = (wmsFeatureMemberPtr) handle;
  6959   6963       if (ptr == NULL)
................................................................................
  7063   7067   	  /* "?" marker not declared */
  7064   7068   	  if (swap_xy)
  7065   7069   	      request =
  7066   7070   		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
  7067   7071   				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7068   7072   				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
  7069   7073   				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
  7070         -				   version, layer, crs_prefix, crs, miny, minx,
  7071         -				   maxy, maxx, width, height, style, format,
  7072         -				   (opaque == 0) ? "TRUE" : "FALSE");
         7074  +				   version, layer, crs_prefix, crs, miny,
         7075  +				   minx, maxy, maxx, width, height, style,
         7076  +				   format, (opaque == 0) ? "TRUE" : "FALSE");
  7073   7077   	  else
  7074   7078   	      request =
  7075   7079   		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
  7076   7080   				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7077   7081   				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
  7078   7082   				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
  7079         -				   version, layer, crs_prefix, crs, minx, miny,
  7080         -				   maxx, maxy, width, height, style, format,
  7081         -				   (opaque == 0) ? "TRUE" : "FALSE");
         7083  +				   version, layer, crs_prefix, crs, minx,
         7084  +				   miny, maxx, maxy, width, height, style,
         7085  +				   format, (opaque == 0) ? "TRUE" : "FALSE");
  7082   7086         }
  7083   7087       else
  7084   7088         {
  7085   7089   	  /* "?" marker already defined */
  7086   7090   	  if (swap_xy)
  7087   7091   	      request =
  7088   7092   		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
  7089   7093   				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7090   7094   				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
  7091   7095   				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
  7092         -				   version, layer, crs_prefix, crs, miny, minx,
  7093         -				   maxy, maxx, width, height, style, format,
  7094         -				   (opaque == 0) ? "TRUE" : "FALSE");
         7096  +				   version, layer, crs_prefix, crs, miny,
         7097  +				   minx, maxy, maxx, width, height, style,
         7098  +				   format, (opaque == 0) ? "TRUE" : "FALSE");
  7095   7099   	  else
  7096   7100   	      request =
  7097   7101   		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
  7098   7102   				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7099   7103   				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
  7100   7104   				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
  7101         -				   version, layer, crs_prefix, crs, minx, miny,
  7102         -				   maxx, maxy, width, height, style, format,
  7103         -				   (opaque == 0) ? "TRUE" : "FALSE");
         7105  +				   version, layer, crs_prefix, crs, minx,
         7106  +				   miny, maxx, maxy, width, height, style,
         7107  +				   format, (opaque == 0) ? "TRUE" : "FALSE");
  7104   7108         }
         7109  +    fprintf (stderr, "\n%s\n", request);
  7105   7110   
  7106   7111       if (cache != NULL)
  7107   7112         {
  7108   7113   	  /* checks if it's already stored into the WMS Cache */
  7109   7114   	  wmsCachedItemPtr cachedItem = getWmsCachedItem (cache, request);
  7110   7115   	  if (cachedItem != NULL)
  7111   7116   	    {
................................................................................
  7271   7276   		    double maxx, double maxy, int width, int height,
  7272   7277   		    const char *style, const char *format, int opaque,
  7273   7278   		    int from_cache, char **err_msg)
  7274   7279   {
  7275   7280   /* attempting to execute a WMS GepMap request [method POST] */
  7276   7281   
  7277   7282   /* not yet implemented: just a stupid placeholder always returning NULL */
  7278         -    if (cache_handle == NULL || url == NULL || proxy == NULL || version == NULL
  7279         -	|| layer == NULL || crs == NULL)
         7283  +    if (cache_handle == NULL || url == NULL || proxy == NULL
         7284  +	|| version == NULL || layer == NULL || crs == NULL)
  7280   7285   	return NULL;
  7281         -    if (minx == miny || maxx == maxy || width == height || opaque == from_cache
  7282         -	|| width == swap_xy)
         7286  +    if (minx == miny || maxx == maxy || width == height
         7287  +	|| opaque == from_cache || width == swap_xy)
  7283   7288   	return NULL;
  7284   7289       if (style == NULL || format == NULL || err_msg == NULL)
  7285   7290   	return NULL;
  7286   7291       return NULL;
  7287   7292   }
  7288   7293   
  7289   7294   RL2_DECLARE unsigned char *
................................................................................
  7529   7534         {
  7530   7535   	  if (swap_xy)
  7531   7536   	      request =
  7532   7537   		  sqlite3_mprintf
  7533   7538   		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
  7534   7539   		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7535   7540   		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
  7536         -		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
  7537         -		   crs, miny, minx, maxy, maxx, width, height, mouse_x,
  7538         -		   mouse_y, format);
         7541  +		   "&FEATURE_COUNT=50", url, version, layer, layer,
         7542  +		   crs_prefix, crs, miny, minx, maxy, maxx, width, height,
         7543  +		   mouse_x, mouse_y, format);
  7539   7544   	  else
  7540   7545   	      request =
  7541   7546   		  sqlite3_mprintf
  7542   7547   		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
  7543   7548   		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7544   7549   		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
  7545         -		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
  7546         -		   crs, minx, miny, maxx, maxy, width, height, mouse_x,
  7547         -		   mouse_y, format);
         7550  +		   "&FEATURE_COUNT=50", url, version, layer, layer,
         7551  +		   crs_prefix, crs, minx, miny, maxx, maxy, width, height,
         7552  +		   mouse_x, mouse_y, format);
  7548   7553         }
  7549   7554       else
  7550   7555         {
  7551   7556   	  if (swap_xy)
  7552   7557   	      request =
  7553   7558   		  sqlite3_mprintf
  7554   7559   		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
  7555   7560   		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7556   7561   		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
  7557         -		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
  7558         -		   crs, miny, minx, maxy, maxx, width, height, mouse_x,
  7559         -		   mouse_y, format);
         7562  +		   "&FEATURE_COUNT=50", url, version, layer, layer,
         7563  +		   crs_prefix, crs, miny, minx, maxy, maxx, width, height,
         7564  +		   mouse_x, mouse_y, format);
  7560   7565   	  else
  7561   7566   	      request =
  7562   7567   		  sqlite3_mprintf
  7563   7568   		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
  7564   7569   		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
  7565   7570   		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
  7566         -		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
  7567         -		   crs, minx, miny, maxx, maxy, width, height, mouse_x,
  7568         -		   mouse_y, format);
         7571  +		   "&FEATURE_COUNT=50", url, version, layer, layer,
         7572  +		   crs_prefix, crs, minx, miny, maxx, maxy, width, height,
         7573  +		   mouse_x, mouse_y, format);
  7569   7574         }
  7570   7575   
  7571   7576       curl = curl_easy_init ();
  7572   7577       if (curl)
  7573   7578         {
  7574   7579   	  /* setting the URL */
  7575   7580   	  curl_easy_setopt (curl, CURLOPT_URL, request);
................................................................................
  7699   7704       return (rl2WmsFeatureCollectionPtr) coll;
  7700   7705   }
  7701   7706   
  7702   7707   RL2_DECLARE rl2WmsFeatureCollectionPtr
  7703   7708   do_wms_GetFeatureInfo_post (const char *url, const char *proxy,
  7704   7709   			    const char *version, const char *format,
  7705   7710   			    const char *layer, const char *crs, int swap_xy,
  7706         -			    double minx, double miny, double maxx, double maxy,
  7707         -			    int width, int height, int mouse_x, int mouse_y,
  7708         -			    char **err_msg)
         7711  +			    double minx, double miny, double maxx,
         7712  +			    double maxy, int width, int height, int mouse_x,
         7713  +			    int mouse_y, char **err_msg)
  7709   7714   {
  7710   7715   /* attempting to execute a WMS GepFeatureInfo request [method POST] */
  7711   7716   
  7712   7717   /* not yet implemented: just a stupid placeholder always returning NULL */
  7713   7718       if (url == NULL || proxy == NULL || version == NULL || format == NULL
  7714   7719   	|| layer == NULL || crs == NULL)
  7715   7720   	return NULL;

Changes to test/Makefile.am.

    17     17   	test_map_indiana test_load_wms \
    18     18   	test_map_noref test_map_trento \
    19     19   	test_map_trieste test_map_infrared \
    20     20   	test_map_orbetello test_raster_symbolizer \
    21     21   	test_svg test_raw test_openjpeg \
    22     22   	test_line_symbolizer test_polygon_symbolizer \
    23     23   	test_point_symbolizer test_text_symbolizer \
    24         -	test_vectors test_font test_copy_rastercov
           24  +	test_vectors test_font test_copy_rastercov \
           25  +	test_tile_callback
    25     26   
    26     27   AM_CPPFLAGS = -I@srcdir@/../headers @LIBXML2_CFLAGS@
    27     28   AM_LDFLAGS = -L../src -lrasterlite2 @LIBCAIRO_LIBS@ @LIBPNG_LIBS@ \
    28     29   	@LIBWEBP_LIBS@ @LIBLZMA_LIBS@ @LIBSPATIALITE_LIBS@ \
    29     30   	@LIBCURL_LIBS@ @LIBXML2_LIBS@  @LIBFREETYPE2_LIBS@ \
    30     31   	$(GCOV_FLAGS)
    31     32   

Changes to test/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   VPATH = @srcdir@
    17         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           17  +am__is_gnu_make = { \
           18  +  if test -z '$(MAKELEVEL)'; then \
           19  +    false; \
           20  +  elif test -n '$(MAKE_HOST)'; then \
           21  +    true; \
           22  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           23  +    true; \
           24  +  else \
           25  +    false; \
           26  +  fi; \
           27  +}
    18     28   am__make_running_with_option = \
    19     29     case $${target_option-} in \
    20     30         ?) ;; \
    21     31         *) echo "am__make_running_with_option: internal error: invalid" \
    22     32                 "target option '$${target_option-}' specified" >&2; \
    23     33            exit 1;; \
    24     34     esac; \
................................................................................
    98    108   	test_map_noref$(EXEEXT) test_map_trento$(EXEEXT) \
    99    109   	test_map_trieste$(EXEEXT) test_map_infrared$(EXEEXT) \
   100    110   	test_map_orbetello$(EXEEXT) test_raster_symbolizer$(EXEEXT) \
   101    111   	test_svg$(EXEEXT) test_raw$(EXEEXT) test_openjpeg$(EXEEXT) \
   102    112   	test_line_symbolizer$(EXEEXT) test_polygon_symbolizer$(EXEEXT) \
   103    113   	test_point_symbolizer$(EXEEXT) test_text_symbolizer$(EXEEXT) \
   104    114   	test_vectors$(EXEEXT) test_font$(EXEEXT) \
   105         -	test_copy_rastercov$(EXEEXT)
          115  +	test_copy_rastercov$(EXEEXT) test_tile_callback$(EXEEXT)
   106    116   subdir = test
   107         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
   108         -	$(top_srcdir)/depcomp $(top_srcdir)/test-driver
   109    117   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
   110    118   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
   111    119   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
   112    120   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
   113    121   	$(top_srcdir)/configure.ac
   114    122   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
   115    123   	$(ACLOCAL_M4)
          124  +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
   116    125   mkinstalldirs = $(install_sh) -d
   117    126   CONFIG_HEADER = $(top_builddir)/config.h
   118    127   CONFIG_CLEAN_FILES =
   119    128   CONFIG_CLEAN_VPATH_FILES =
   120    129   check_sql_stmt_SOURCES = check_sql_stmt.c
   121    130   check_sql_stmt_OBJECTS = check_sql_stmt.$(OBJEXT)
   122    131   check_sql_stmt_LDADD = $(LDADD)
................................................................................
   291    300   test_svg_LDADD = $(LDADD)
   292    301   test_text_symbolizer_SOURCES = test_text_symbolizer.c
   293    302   test_text_symbolizer_OBJECTS = test_text_symbolizer.$(OBJEXT)
   294    303   test_text_symbolizer_LDADD = $(LDADD)
   295    304   test_tifin_SOURCES = test_tifin.c
   296    305   test_tifin_OBJECTS = test_tifin.$(OBJEXT)
   297    306   test_tifin_LDADD = $(LDADD)
          307  +test_tile_callback_SOURCES = test_tile_callback.c
          308  +test_tile_callback_OBJECTS = test_tile_callback.$(OBJEXT)
          309  +test_tile_callback_LDADD = $(LDADD)
   298    310   test_vectors_SOURCES = test_vectors.c
   299    311   test_vectors_OBJECTS = test_vectors.$(OBJEXT)
   300    312   test_vectors_LDADD = $(LDADD)
   301    313   test_webp_SOURCES = test_webp.c
   302    314   test_webp_OBJECTS = test_webp.$(OBJEXT)
   303    315   test_webp_LDADD = $(LDADD)
   304    316   test_wms1_SOURCES = test_wms1.c
................................................................................
   355    367   	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
   356    368   	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
   357    369   	test_map_srtm.c test_map_trento.c test_map_trieste.c \
   358    370   	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
   359    371   	test_point_symbolizer.c test_polygon_symbolizer.c \
   360    372   	test_raster.c test_raster_symbolizer.c test_raw.c \
   361    373   	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
   362         -	test_vectors.c test_webp.c test_wms1.c test_wms2.c \
   363         -	test_wr_tiff.c
          374  +	test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \
          375  +	test_wms2.c test_wr_tiff.c
   364    376   DIST_SOURCES = check_sql_stmt.c test1.c test10.c test11.c test12.c \
   365    377   	test13.c test14.c test15.c test16.c test17.c test18.c test19.c \
   366    378   	test2.c test20.c test3.c test4.c test5.c test6.c test7.c \
   367    379   	test8.c test9.c test_copy_rastercov.c test_coverage.c \
   368    380   	test_font.c test_gif.c test_line_symbolizer.c test_load_wms.c \
   369    381   	test_map_ascii.c test_map_gray.c test_map_indiana.c \
   370    382   	test_map_infrared.c test_map_mono.c test_map_nile_32.c \
................................................................................
   372    384   	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
   373    385   	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
   374    386   	test_map_srtm.c test_map_trento.c test_map_trieste.c \
   375    387   	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
   376    388   	test_point_symbolizer.c test_polygon_symbolizer.c \
   377    389   	test_raster.c test_raster_symbolizer.c test_raw.c \
   378    390   	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
   379         -	test_vectors.c test_webp.c test_wms1.c test_wms2.c \
   380         -	test_wr_tiff.c
          391  +	test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \
          392  +	test_wms2.c test_wr_tiff.c
   381    393   RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
   382    394   	ctags-recursive dvi-recursive html-recursive info-recursive \
   383    395   	install-data-recursive install-dvi-recursive \
   384    396   	install-exec-recursive install-html-recursive \
   385    397   	install-info-recursive install-pdf-recursive \
   386    398   	install-ps-recursive install-recursive installcheck-recursive \
   387    399   	installdirs-recursive pdf-recursive ps-recursive \
................................................................................
   618    630   am__test_logs1 = $(TESTS:=.log)
   619    631   am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
   620    632   TEST_LOGS = $(am__test_logs2:.test.log=.log)
   621    633   TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
   622    634   TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
   623    635   	$(TEST_LOG_FLAGS)
   624    636   DIST_SUBDIRS = $(SUBDIRS)
          637  +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
          638  +	$(top_srcdir)/test-driver
   625    639   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   626    640   am__relativize = \
   627    641     dir0=`pwd`; \
   628    642     sed_first='s,^\([^/]*\)/.*$$,\1,'; \
   629    643     sed_rest='s,^[^/]*/*,,'; \
   630    644     sed_last='s,^.*/\([^/]*\)$$,\1,'; \
   631    645     sed_butlast='s,/*[^/]*$$,,'; \
................................................................................
   885    899   	        && { if test -f $@; then exit 0; else break; fi; }; \
   886    900   	      exit 1;; \
   887    901   	  esac; \
   888    902   	done; \
   889    903   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \
   890    904   	$(am__cd) $(top_srcdir) && \
   891    905   	  $(AUTOMAKE) --gnu test/Makefile
   892         -.PRECIOUS: Makefile
   893    906   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   894    907   	@case '$?' in \
   895    908   	  *config.status*) \
   896    909   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   897    910   	  *) \
   898    911   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   899    912   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
  1144   1157   test_text_symbolizer$(EXEEXT): $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_DEPENDENCIES) $(EXTRA_test_text_symbolizer_DEPENDENCIES) 
  1145   1158   	@rm -f test_text_symbolizer$(EXEEXT)
  1146   1159   	$(AM_V_CCLD)$(LINK) $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_LDADD) $(LIBS)
  1147   1160   
  1148   1161   test_tifin$(EXEEXT): $(test_tifin_OBJECTS) $(test_tifin_DEPENDENCIES) $(EXTRA_test_tifin_DEPENDENCIES) 
  1149   1162   	@rm -f test_tifin$(EXEEXT)
  1150   1163   	$(AM_V_CCLD)$(LINK) $(test_tifin_OBJECTS) $(test_tifin_LDADD) $(LIBS)
         1164  +
         1165  +test_tile_callback$(EXEEXT): $(test_tile_callback_OBJECTS) $(test_tile_callback_DEPENDENCIES) $(EXTRA_test_tile_callback_DEPENDENCIES) 
         1166  +	@rm -f test_tile_callback$(EXEEXT)
         1167  +	$(AM_V_CCLD)$(LINK) $(test_tile_callback_OBJECTS) $(test_tile_callback_LDADD) $(LIBS)
  1151   1168   
  1152   1169   test_vectors$(EXEEXT): $(test_vectors_OBJECTS) $(test_vectors_DEPENDENCIES) $(EXTRA_test_vectors_DEPENDENCIES) 
  1153   1170   	@rm -f test_vectors$(EXEEXT)
  1154   1171   	$(AM_V_CCLD)$(LINK) $(test_vectors_OBJECTS) $(test_vectors_LDADD) $(LIBS)
  1155   1172   
  1156   1173   test_webp$(EXEEXT): $(test_webp_OBJECTS) $(test_webp_DEPENDENCIES) $(EXTRA_test_webp_DEPENDENCIES) 
  1157   1174   	@rm -f test_webp$(EXEEXT)
................................................................................
  1229   1246   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster.Po@am__quote@
  1230   1247   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster_symbolizer.Po@am__quote@
  1231   1248   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raw.Po@am__quote@
  1232   1249   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_section.Po@am__quote@
  1233   1250   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_svg.Po@am__quote@
  1234   1251   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_text_symbolizer.Po@am__quote@
  1235   1252   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tifin.Po@am__quote@
         1253  +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tile_callback.Po@am__quote@
  1236   1254   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_vectors.Po@am__quote@
  1237   1255   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_webp.Po@am__quote@
  1238   1256   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms1.Po@am__quote@
  1239   1257   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms2.Po@am__quote@
  1240   1258   @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wr_tiff.Po@am__quote@
  1241   1259   
  1242   1260   .c.o:
................................................................................
  1391   1409   	  if $(am__make_dryrun); then :; else \
  1392   1410   	    rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
  1393   1411   	  fi; \
  1394   1412   	fi; \
  1395   1413   	if test -n "$$am__remaking_logs"; then \
  1396   1414   	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
  1397   1415   	       "recursion detected" >&2; \
  1398         -	else \
         1416  +	elif test -n "$$redo_logs"; then \
  1399   1417   	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
  1400   1418   	fi; \
  1401   1419   	if $(am__make_dryrun); then :; else \
  1402   1420   	  st=0;  \
  1403   1421   	  errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
  1404   1422   	  for i in $$redo_bases; do \
  1405   1423   	    test -f $$i.trs && test -r $$i.trs \
................................................................................
  1943   1961   test_copy_rastercov.log: test_copy_rastercov$(EXEEXT)
  1944   1962   	@p='test_copy_rastercov$(EXEEXT)'; \
  1945   1963   	b='test_copy_rastercov'; \
  1946   1964   	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
  1947   1965   	--log-file $$b.log --trs-file $$b.trs \
  1948   1966   	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
  1949   1967   	"$$tst" $(AM_TESTS_FD_REDIRECT)
         1968  +test_tile_callback.log: test_tile_callback$(EXEEXT)
         1969  +	@p='test_tile_callback$(EXEEXT)'; \
         1970  +	b='test_tile_callback'; \
         1971  +	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
         1972  +	--log-file $$b.log --trs-file $$b.trs \
         1973  +	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
         1974  +	"$$tst" $(AM_TESTS_FD_REDIRECT)
  1950   1975   .test.log:
  1951   1976   	@p='$<'; \
  1952   1977   	$(am__set_b); \
  1953   1978   	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
  1954   1979   	--log-file $$b.log --trs-file $$b.trs \
  1955   1980   	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
  1956   1981   	"$$tst" $(AM_TESTS_FD_REDIRECT)
................................................................................
  2141   2166   	install-html-am install-info install-info-am install-man \
  2142   2167   	install-pdf install-pdf-am install-ps install-ps-am \
  2143   2168   	install-strip installcheck installcheck-am installdirs \
  2144   2169   	installdirs-am maintainer-clean maintainer-clean-generic \
  2145   2170   	mostlyclean mostlyclean-compile mostlyclean-generic \
  2146   2171   	mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \
  2147   2172   	uninstall uninstall-am
         2173  +
         2174  +.PRECIOUS: Makefile
  2148   2175   
  2149   2176   
  2150   2177   # Tell versions [3.59,3.63) of GNU make to not export all variables.
  2151   2178   # Otherwise a system limit (for SysV at least) may be exceeded.
  2152   2179   .NOEXPORT:

Changes to test/sql_stmt_security_tests/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   VPATH = @srcdir@
    17         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           17  +am__is_gnu_make = { \
           18  +  if test -z '$(MAKELEVEL)'; then \
           19  +    false; \
           20  +  elif test -n '$(MAKE_HOST)'; then \
           21  +    true; \
           22  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           23  +    true; \
           24  +  else \
           25  +    false; \
           26  +  fi; \
           27  +}
    18     28   am__make_running_with_option = \
    19     29     case $${target_option-} in \
    20     30         ?) ;; \
    21     31         *) echo "am__make_running_with_option: internal error: invalid" \
    22     32                 "target option '$${target_option-}' specified" >&2; \
    23     33            exit 1;; \
    24     34     esac; \
................................................................................
    74     84   POST_INSTALL = :
    75     85   NORMAL_UNINSTALL = :
    76     86   PRE_UNINSTALL = :
    77     87   POST_UNINSTALL = :
    78     88   build_triplet = @build@
    79     89   host_triplet = @host@
    80     90   subdir = test/sql_stmt_security_tests
    81         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
    82     91   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    83     92   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    84     93   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    85     94   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    86     95   	$(top_srcdir)/configure.ac
    87     96   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    88     97   	$(ACLOCAL_M4)
           98  +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
    89     99   mkinstalldirs = $(install_sh) -d
    90    100   CONFIG_HEADER = $(top_builddir)/config.h
    91    101   CONFIG_CLEAN_FILES =
    92    102   CONFIG_CLEAN_VPATH_FILES =
    93    103   AM_V_P = $(am__v_P_@AM_V@)
    94    104   am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
    95    105   am__v_P_0 = false
................................................................................
   106    116   DIST_SOURCES =
   107    117   am__can_run_installinfo = \
   108    118     case $$AM_UPDATE_INFO_DIR in \
   109    119       n|no|NO) false;; \
   110    120       *) (install-info --version) >/dev/null 2>&1;; \
   111    121     esac
   112    122   am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
          123  +am__DIST_COMMON = $(srcdir)/Makefile.in
   113    124   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   114    125   ACLOCAL = @ACLOCAL@
   115    126   AMTAR = @AMTAR@
   116    127   AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
   117    128   AR = @AR@
   118    129   AS = @AS@
   119    130   AUTOCONF = @AUTOCONF@
................................................................................
   896    907   	        && { if test -f $@; then exit 0; else break; fi; }; \
   897    908   	      exit 1;; \
   898    909   	  esac; \
   899    910   	done; \
   900    911   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile'; \
   901    912   	$(am__cd) $(top_srcdir) && \
   902    913   	  $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile
   903         -.PRECIOUS: Makefile
   904    914   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   905    915   	@case '$?' in \
   906    916   	  *config.status*) \
   907    917   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   908    918   	  *) \
   909    919   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   910    920   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
  1070   1080   	install-dvi-am install-exec install-exec-am install-html \
  1071   1081   	install-html-am install-info install-info-am install-man \
  1072   1082   	install-pdf install-pdf-am install-ps install-ps-am \
  1073   1083   	install-strip installcheck installcheck-am installdirs \
  1074   1084   	maintainer-clean maintainer-clean-generic mostlyclean \
  1075   1085   	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
  1076   1086   	tags-am uninstall uninstall-am
         1087  +
         1088  +.PRECIOUS: Makefile
  1077   1089   
  1078   1090   
  1079   1091   # Tell versions [3.59,3.63) of GNU make to not export all variables.
  1080   1092   # Otherwise a system limit (for SysV at least) may be exceeded.
  1081   1093   .NOEXPORT:

Changes to test/sql_stmt_tests/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   VPATH = @srcdir@
    17         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           17  +am__is_gnu_make = { \
           18  +  if test -z '$(MAKELEVEL)'; then \
           19  +    false; \
           20  +  elif test -n '$(MAKE_HOST)'; then \
           21  +    true; \
           22  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           23  +    true; \
           24  +  else \
           25  +    false; \
           26  +  fi; \
           27  +}
    18     28   am__make_running_with_option = \
    19     29     case $${target_option-} in \
    20     30         ?) ;; \
    21     31         *) echo "am__make_running_with_option: internal error: invalid" \
    22     32                 "target option '$${target_option-}' specified" >&2; \
    23     33            exit 1;; \
    24     34     esac; \
................................................................................
    74     84   POST_INSTALL = :
    75     85   NORMAL_UNINSTALL = :
    76     86   PRE_UNINSTALL = :
    77     87   POST_UNINSTALL = :
    78     88   build_triplet = @build@
    79     89   host_triplet = @host@
    80     90   subdir = test/sql_stmt_tests
    81         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
    82     91   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    83     92   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    84     93   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    85     94   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    86     95   	$(top_srcdir)/configure.ac
    87     96   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    88     97   	$(ACLOCAL_M4)
           98  +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
    89     99   mkinstalldirs = $(install_sh) -d
    90    100   CONFIG_HEADER = $(top_builddir)/config.h
    91    101   CONFIG_CLEAN_FILES =
    92    102   CONFIG_CLEAN_VPATH_FILES =
    93    103   AM_V_P = $(am__v_P_@AM_V@)
    94    104   am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
    95    105   am__v_P_0 = false
................................................................................
   106    116   DIST_SOURCES =
   107    117   am__can_run_installinfo = \
   108    118     case $$AM_UPDATE_INFO_DIR in \
   109    119       n|no|NO) false;; \
   110    120       *) (install-info --version) >/dev/null 2>&1;; \
   111    121     esac
   112    122   am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
          123  +am__DIST_COMMON = $(srcdir)/Makefile.in
   113    124   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   114    125   ACLOCAL = @ACLOCAL@
   115    126   AMTAR = @AMTAR@
   116    127   AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
   117    128   AR = @AR@
   118    129   AS = @AS@
   119    130   AUTOCONF = @AUTOCONF@
................................................................................
   868    879   	        && { if test -f $@; then exit 0; else break; fi; }; \
   869    880   	      exit 1;; \
   870    881   	  esac; \
   871    882   	done; \
   872    883   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile'; \
   873    884   	$(am__cd) $(top_srcdir) && \
   874    885   	  $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile
   875         -.PRECIOUS: Makefile
   876    886   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   877    887   	@case '$?' in \
   878    888   	  *config.status*) \
   879    889   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   880    890   	  *) \
   881    891   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   882    892   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
  1042   1052   	install-dvi-am install-exec install-exec-am install-html \
  1043   1053   	install-html-am install-info install-info-am install-man \
  1044   1054   	install-pdf install-pdf-am install-ps install-ps-am \
  1045   1055   	install-strip installcheck installcheck-am installdirs \
  1046   1056   	maintainer-clean maintainer-clean-generic mostlyclean \
  1047   1057   	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
  1048   1058   	tags-am uninstall uninstall-am
         1059  +
         1060  +.PRECIOUS: Makefile
  1049   1061   
  1050   1062   	version.testcase 
  1051   1063   
  1052   1064   # Tell versions [3.59,3.63) of GNU make to not export all variables.
  1053   1065   # Otherwise a system limit (for SysV at least) may be exceeded.
  1054   1066   .NOEXPORT:

Changes to test/symbolizers.sqlite.

cannot compute difference between binary files

Changes to test/test_line_symbolizer.c.

  1072   1072       if (rl2_line_symbolizer_get_stroke_color (line, &red, &green, &blue) !=
  1073   1073   	RL2_OK)
  1074   1074         {
  1075   1075   	  fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #4\n");
  1076   1076   	  *retcode += 18;
  1077   1077   	  return 0;
  1078   1078         }
  1079         -    if (red != 0x00 || green != 0x00 || blue != 0xff)
         1079  +    if (red != 0x80 || green != 0x80 || blue != 0x80)
  1080   1080         {
  1081   1081   	  fprintf (stderr,
  1082   1082   		   "Unexpected Line Symbolizer GetStrokeColor #4: %02x%02x%02x\n",
  1083   1083   		   red, green, blue);
  1084   1084   	  *retcode += 19;
  1085   1085   	  return 0;
  1086   1086         }
................................................................................
  1311   1311       if (rl2_line_symbolizer_get_stroke_color (line, &red, &green, &blue) !=
  1312   1312   	RL2_OK)
  1313   1313         {
  1314   1314   	  fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #9\n");
  1315   1315   	  *retcode += 48;
  1316   1316   	  return 0;
  1317   1317         }
  1318         -    if (red != 0x00 || green != 0x00 || blue != 0xff)
         1318  +    if (red != 0x80 || green != 0x80 || blue != 0x80)
  1319   1319         {
  1320   1320   	  fprintf (stderr,
  1321   1321   		   "Unexpected Line Symbolizer GetStrokeColor #9: %02x%02x%02x\n",
  1322   1322   		   red, green, blue);
  1323   1323   	  *retcode += 49;
  1324   1324   	  return 0;
  1325   1325         }
................................................................................
  1359   1359   	RL2_OK)
  1360   1360         {
  1361   1361   	  fprintf (stderr,
  1362   1362   		   "Unable to get Line Symbolizer GetStrokeColor #10\n");
  1363   1363   	  *retcode += 54;
  1364   1364   	  return 0;
  1365   1365         }
  1366         -    if (red != 0x00 || green != 0x00 || blue != 0xff)
         1366  +    if (red != 0x80 || green != 0x80 || blue != 0x80)
  1367   1367         {
  1368   1368   	  fprintf (stderr,
  1369   1369   		   "Unexpected Line Symbolizer GetStrokeColor #10: %02x%02x%02x\n",
  1370   1370   		   red, green, blue);
  1371   1371   	  *retcode += 55;
  1372   1372   	  return 0;
  1373   1373         }
................................................................................
  1407   1407   	RL2_OK)
  1408   1408         {
  1409   1409   	  fprintf (stderr,
  1410   1410   		   "Unable to get Line Symbolizer GetStrokeColor #11\n");
  1411   1411   	  *retcode += 60;
  1412   1412   	  return 0;
  1413   1413         }
  1414         -    if (red != 0x00 || green != 0x00 || blue != 0xff)
         1414  +    if (red != 0x80 || green != 0x80 || blue != 0x80)
  1415   1415         {
  1416   1416   	  fprintf (stderr,
  1417   1417   		   "Unexpected Line Symbolizer GetStrokeColor #11: %02x%02x%02x\n",
  1418   1418   		   red, green, blue);
  1419   1419   	  *retcode += 61;
  1420   1420   	  return 0;
  1421   1421         }

Changes to test/test_point_symbolizer.c.

   786    786       if (strcmp (style_name, "point_3") == 0)
   787    787         {
   788    788   	  if (dblval == 3.0 && dblval2 == 2.0)
   789    789   	      intval = 1;
   790    790         }
   791    791       else
   792    792         {
   793         -	  if (dblval == 0.0 && dblval2 == 0.0)
          793  +	  if (dblval == 0.5 && dblval2 == 0.5)
   794    794   	      intval = 1;
   795    795         }
   796    796       if (intval != 1)
   797    797         {
   798    798   	  fprintf (stderr,
   799    799   		   "%s: Unexpected Point Symbolizer GetAnchorPoint #1: %1.4f %1.4f\n",
   800    800   		   style_name, dblval, dblval2);

Changes to test/test_polygon_symbolizer.c.

  1506   1506       if (symbolizer == NULL)
  1507   1507         {
  1508   1508   	  fprintf (stderr, "Unexpected NULL VectorSymbolizer (%s) #6\n",
  1509   1509   		   style_name);
  1510   1510   	  *retcode += 22;
  1511   1511   	  return 0;
  1512   1512         }
  1513         -    polyg = rl2_get_polygon_symbolizer (symbolizer, 0);
         1513  +    polyg = rl2_get_polygon_symbolizer (symbolizer, 1);
  1514   1514       if (polyg == NULL)
  1515   1515         {
  1516   1516   	  fprintf (stderr, "Unable to get Polygon Symbolizer #5\n");
  1517   1517   	  *retcode += 23;
  1518   1518   	  return 0;
  1519   1519         }
  1520   1520       if (rl2_polygon_symbolizer_get_fill_color (polyg, &red, &green, &blue) !=
................................................................................
  1521   1521   	RL2_OK)
  1522   1522         {
  1523   1523   	  fprintf (stderr,
  1524   1524   		   "Unable to get Polygon Symbolizer GetFillColor #4\n");
  1525   1525   	  *retcode += 24;
  1526   1526   	  return 0;
  1527   1527         }
  1528         -    if (red != 0x70 || green != 0xff || blue != 0xc0)
         1528  +    if (red != 0x37 || green != 0x81 || blue != 0xf2)
  1529   1529         {
  1530   1530   	  fprintf (stderr,
  1531   1531   		   "Unexpected Polygon Symbolizer GetStrokeColor #5: %02x%02x%02x\n",
  1532   1532   		   red, green, blue);
  1533   1533   	  *retcode += 25;
  1534   1534   	  return 0;
  1535   1535         }

Added test/test_tile_callback.c.

            1  +/*
            2  +
            3  + test_tile_callback.c -- RasterLite2 Test Case
            4  +
            5  + Author: Alessandro Furieri <a.furieri@lqt.it>
            6  +
            7  + ------------------------------------------------------------------------------
            8  + 
            9  + Version: MPL 1.1/GPL 2.0/LGPL 2.1
           10  + 
           11  + The contents of this file are subject to the Mozilla Public License Version
           12  + 1.1 (the "License"); you may not use this file except in compliance with
           13  + the License. You may obtain a copy of the License at
           14  + http://www.mozilla.org/MPL/
           15  + 
           16  +Software distributed under the License is distributed on an "AS IS" basis,
           17  +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
           18  +for the specific language governing rights and limitations under the
           19  +License.
           20  +
           21  +The Original Code is the RasterLite2 library
           22  +
           23  +The Initial Developer of the Original Code is Alessandro Furieri
           24  + 
           25  +Portions created by the Initial Developer are Copyright (C) 2013
           26  +the Initial Developer. All Rights Reserved.
           27  +
           28  +Contributor(s):
           29  +
           30  +Alternatively, the contents of this file may be used under the terms of
           31  +either the GNU General Public License Version 2 or later (the "GPL"), or
           32  +the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
           33  +in which case the provisions of the GPL or the LGPL are applicable instead
           34  +of those above. If you wish to allow use of your version of this file only
           35  +under the terms of either the GPL or the LGPL, and not to allow others to
           36  +use your version of this file under the terms of the MPL, indicate your
           37  +decision by deleting the provisions above and replace them with the notice
           38  +and other provisions required by the GPL or the LGPL. If you do not delete
           39  +the provisions above, a recipient may use your version of this file under
           40  +the terms of any one of the MPL, the GPL or the LGPL.
           41  +*/
           42  +#include <stdlib.h>
           43  +#include <unistd.h>
           44  +#include <stdio.h>
           45  +#include <memory.h>
           46  +
           47  +#include "config.h"
           48  +
           49  +#include "sqlite3.h"
           50  +#include "spatialite.h"
           51  +
           52  +#include "rasterlite2/rasterlite2.h"
           53  +
           54  +struct tile_info
           55  +{
           56  +/* a struct supporting the Tile Callback function */
           57  +    unsigned char sample;
           58  +    unsigned char pixel;
           59  +    unsigned char num_bands;
           60  +    int srid;
           61  +    const char *coverage;
           62  +    unsigned int tile_w;
           63  +    unsigned int tile_h;
           64  +};
           65  +
           66  +static void
           67  +set_tile_pixel_gray8 (unsigned char *bufpix, unsigned int x, unsigned int y,
           68  +		      unsigned int tile_w, double map_x, double map_y)
           69  +{
           70  +/* pixel generator - GRAYSCALE UINT8 */
           71  +    unsigned char *p = bufpix + ((y * tile_w) + x);
           72  +    if (map_y >= -15.0 && map_y <= 15.0)
           73  +      {
           74  +	  if (map_x < 0.0)
           75  +	      *p = 248;
           76  +	  else
           77  +	      *p = 216;
           78  +      }
           79  +    else if (map_y >= -60.0 && map_y <= 60.0)
           80  +      {
           81  +	  if (map_x < 0.0)
           82  +	      *p = 208;
           83  +	  else
           84  +	      *p = 192;
           85  +      }
           86  +    else
           87  +      {
           88  +	  if (map_x < 0.0)
           89  +	      *p = 128;
           90  +	  else
           91  +	      *p = 96;
           92  +      }
           93  +}
           94  +
           95  +static void
           96  +set_tile_pixel_rgb8 (unsigned char *bufpix, unsigned int x, unsigned int y,
           97  +		     unsigned int tile_w, double map_x, double map_y,
           98  +		     unsigned int num_bands)
           99  +{
          100  +/* pixel generator - RGB UINT8 */
          101  +    unsigned char *p = bufpix + (y * tile_w * num_bands) + (x * num_bands);
          102  +    if (map_y >= -15.0 && map_y <= 15.0)
          103  +      {
          104  +	  if (map_x < 0.0)
          105  +	    {
          106  +		*p++ = 248;
          107  +		*p++ = 255;
          108  +		*p++ = 0;
          109  +	    }
          110  +	  else
          111  +	    {
          112  +		*p++ = 216;
          113  +		*p++ = 248;
          114  +		*p++ = 0;
          115  +	    }
          116  +      }
          117  +    else if (map_y >= -60.0 && map_y <= 60.0)
          118  +      {
          119  +	  if (map_x < 0.0)
          120  +	    {
          121  +		*p++ = 0;
          122  +		*p++ = 208;
          123  +		*p++ = 248;
          124  +	    }
          125  +	  else
          126  +	    {
          127  +		*p++ = 0;
          128  +		*p++ = 192;
          129  +		*p++ = 248;
          130  +	    }
          131  +      }
          132  +    else
          133  +      {
          134  +	  if (map_x < 0.0)
          135  +	    {
          136  +		*p++ = 192;
          137  +		*p++ = 192;
          138  +		*p++ = 128;
          139  +	    }
          140  +	  else
          141  +	    {
          142  +		*p++ = 192;
          143  +		*p++ = 192;
          144  +		*p++ = 96;
          145  +	    }
          146  +      }
          147  +}
          148  +
          149  +static void
          150  +set_tile_pixel_int16 (unsigned char *bufpix, unsigned int x, unsigned int y,
          151  +		      unsigned int tile_w, double map_x, double map_y)
          152  +{
          153  +/* pixel generator - DATAGRID INT16 */
          154  +    short *p = (short *) bufpix;
          155  +    p += ((y * tile_w) + x);
          156  +    if (map_y >= -15.0 && map_y <= 15.0)
          157  +      {
          158  +	  if (map_x < 0.0)
          159  +	      *p = -10;
          160  +	  else
          161  +	      *p = 50;
          162  +      }
          163  +    else if (map_y >= -60.0 && map_y <= 60.0)
          164  +      {
          165  +	  if (map_x < 0.0)
          166  +	      *p = 100;
          167  +	  else
          168  +	      *p = 200;
          169  +      }
          170  +    else
          171  +      {
          172  +	  if (map_x < 0.0)
          173  +	      *p = -100;
          174  +	  else
          175  +	      *p = -50;
          176  +      }
          177  +}
          178  +
          179  +static void
          180  +set_tile_pixel_double (unsigned char *bufpix, unsigned int x, unsigned int y,
          181  +		       unsigned int tile_w, double map_x, double map_y)
          182  +{
          183  +/* pixel generator - DATAGRID DOUBLE */
          184  +    double *p = (double *) bufpix;
          185  +    p += ((y * tile_w) + x);
          186  +    if (map_y >= -15.0 && map_y <= 15.0)
          187  +      {
          188  +	  if (map_x < 0.0)
          189  +	      *p = -10.06;
          190  +	  else
          191  +	      *p = 50.02;
          192  +      }
          193  +    else if (map_y >= -60.0 && map_y <= 60.0)
          194  +      {
          195  +	  if (map_x < 0.0)
          196  +	      *p = 100.03;
          197  +	  else
          198  +	      *p = 200.81;
          199  +      }
          200  +    else
          201  +      {
          202  +	  if (map_x < 0.0)
          203  +	      *p = -100.23;
          204  +	  else
          205  +	      *p = -50.41;
          206  +      }
          207  +}
          208  +
          209  +static void
          210  +set_tile_pixel_uint8 (unsigned char *bufpix, unsigned int x, unsigned int y,
          211  +		      unsigned int tile_w, double map_x, double map_y,
          212  +		      unsigned char pixel, unsigned char num_bands)
          213  +{
          214  +/* pixel generator - UINT8 */
          215  +    switch (pixel)
          216  +      {
          217  +      case RL2_PIXEL_GRAYSCALE:
          218  +	  set_tile_pixel_gray8 (bufpix, x, y, tile_w, map_x, map_y);
          219  +	  break;
          220  +      case RL2_PIXEL_RGB:
          221  +	  set_tile_pixel_rgb8 (bufpix, x, y, tile_w, map_x, map_y, num_bands);
          222  +	  break;
          223  +      };
          224  +}
          225  +
          226  +static void
          227  +set_tile_pixel (unsigned char *bufpix, unsigned int x, unsigned int y,
          228  +		unsigned int tile_w, double map_x, double map_y,
          229  +		unsigned char sample, unsigned char pixel,
          230  +		unsigned int num_bands)
          231  +{
          232  +/* generalized pixel generator */
          233  +    switch (sample)
          234  +      {
          235  +      case RL2_SAMPLE_UINT8:
          236  +	  set_tile_pixel_uint8 (bufpix, x, y, tile_w, map_x, map_y, pixel,
          237  +				num_bands);
          238  +	  break;
          239  +      case RL2_SAMPLE_INT16:
          240  +	  set_tile_pixel_int16 (bufpix, x, y, tile_w, map_x, map_y);
          241  +	  break;
          242  +      case RL2_SAMPLE_DOUBLE:
          243  +	  set_tile_pixel_double (bufpix, x, y, tile_w, map_x, map_y);
          244  +	  break;
          245  +      };
          246  +}
          247  +
          248  +static int
          249  +tile_callback (void *data, double tile_minx, double tile_miny, double tile_maxx,
          250  +	       double tile_maxy, unsigned char *bufpix, rl2PalettePtr * palette)
          251  +{
          252  +/* callback function initializing a Tile */
          253  +    struct tile_info *info = (struct tile_info *) data;
          254  +    unsigned int x;
          255  +    unsigned int y;
          256  +    double res_x = (tile_maxx - tile_minx) / (double) (info->tile_w);
          257  +    double res_y = (tile_maxy - tile_miny) / (double) (info->tile_h);
          258  +
          259  +/* setting tile pixels */
          260  +    for (y = 0; y < info->tile_h; y++)
          261  +      {
          262  +	  double map_y = tile_maxy - ((double) y * res_y);
          263  +	  if (map_y < tile_miny)
          264  +	      continue;
          265  +	  for (x = 0; x < info->tile_w; x++)
          266  +	    {
          267  +		double map_x = tile_minx + ((double) x * res_x);
          268  +		if (map_x > tile_maxx)
          269  +		    continue;
          270  +		set_tile_pixel (bufpix, x, y, info->tile_w, map_x, map_y,
          271  +				info->sample, info->pixel, info->num_bands);
          272  +	    }
          273  +      }
          274  +
          275  +    return 1;
          276  +}
          277  +
          278  +static rl2PixelPtr
          279  +default_nodata (unsigned char sample, unsigned char pixel,
          280  +		unsigned char num_bands)
          281  +{
          282  +/* creating a default NO-DATA value */
          283  +    int nb;
          284  +    rl2PixelPtr pxl = rl2_create_pixel (sample, pixel, num_bands);
          285  +    if (pxl == NULL)
          286  +	return NULL;
          287  +    switch (pixel)
          288  +      {
          289  +      case RL2_PIXEL_MONOCHROME:
          290  +	  rl2_set_pixel_sample_1bit (pxl, 0);
          291  +	  break;
          292  +      case RL2_PIXEL_PALETTE:
          293  +	  switch (sample)
          294  +	    {
          295  +	    case RL2_SAMPLE_1_BIT:
          296  +		rl2_set_pixel_sample_1bit (pxl, 0);
          297  +		break;
          298  +	    case RL2_SAMPLE_2_BIT:
          299  +		rl2_set_pixel_sample_2bit (pxl, 0);
          300  +		break;
          301  +	    case RL2_SAMPLE_4_BIT:
          302  +		rl2_set_pixel_sample_4bit (pxl, 0);
          303  +		break;
          304  +	    case RL2_SAMPLE_UINT8:
          305  +		rl2_set_pixel_sample_uint8 (pxl, 0, 0);
          306  +		break;
          307  +	    };
          308  +	  break;
          309  +      case RL2_PIXEL_GRAYSCALE:
          310  +	  switch (sample)
          311  +	    {
          312  +	    case RL2_SAMPLE_1_BIT:
          313  +		rl2_set_pixel_sample_1bit (pxl, 1);
          314  +		break;
          315  +	    case RL2_SAMPLE_2_BIT:
          316  +		rl2_set_pixel_sample_2bit (pxl, 3);
          317  +		break;
          318  +	    case RL2_SAMPLE_4_BIT:
          319  +		rl2_set_pixel_sample_4bit (pxl, 15);
          320  +		break;
          321  +	    case RL2_SAMPLE_UINT8:
          322  +		rl2_set_pixel_sample_uint8 (pxl, 0, 255);
          323  +		break;
          324  +	    case RL2_SAMPLE_UINT16:
          325  +		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
          326  +		break;
          327  +	    };
          328  +	  break;
          329  +      case RL2_PIXEL_RGB:
          330  +	  switch (sample)
          331  +	    {
          332  +	    case RL2_SAMPLE_UINT8:
          333  +		rl2_set_pixel_sample_uint8 (pxl, 0, 255);
          334  +		rl2_set_pixel_sample_uint8 (pxl, 1, 255);
          335  +		rl2_set_pixel_sample_uint8 (pxl, 2, 255);
          336  +		break;
          337  +	    case RL2_SAMPLE_UINT16:
          338  +		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
          339  +		rl2_set_pixel_sample_uint16 (pxl, 1, 0);
          340  +		rl2_set_pixel_sample_uint16 (pxl, 2, 0);
          341  +		break;
          342  +	    };
          343  +	  break;
          344  +      case RL2_PIXEL_DATAGRID:
          345  +	  switch (sample)
          346  +	    {
          347  +	    case RL2_SAMPLE_INT8:
          348  +		rl2_set_pixel_sample_int8 (pxl, 0);
          349  +		break;
          350  +	    case RL2_SAMPLE_UINT8:
          351  +		rl2_set_pixel_sample_uint8 (pxl, 0, 0);
          352  +		break;
          353  +	    case RL2_SAMPLE_INT16:
          354  +		rl2_set_pixel_sample_int16 (pxl, 0);
          355  +		break;
          356  +	    case RL2_SAMPLE_UINT16:
          357  +		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
          358  +		break;
          359  +	    case RL2_SAMPLE_INT32:
          360  +		rl2_set_pixel_sample_int32 (pxl, 0);
          361  +		break;
          362  +	    case RL2_SAMPLE_UINT32:
          363  +		rl2_set_pixel_sample_uint32 (pxl, 0);
          364  +		break;
          365  +	    case RL2_SAMPLE_FLOAT:
          366  +		rl2_set_pixel_sample_float (pxl, 0.0);
          367  +		break;
          368  +	    case RL2_SAMPLE_DOUBLE:
          369  +		rl2_set_pixel_sample_double (pxl, 0.0);
          370  +		break;
          371  +	    };
          372  +	  break;
          373  +      case RL2_PIXEL_MULTIBAND:
          374  +	  switch (sample)
          375  +	    {
          376  +	    case RL2_SAMPLE_UINT8:
          377  +		for (nb = 0; nb < num_bands; nb++)
          378  +		    rl2_set_pixel_sample_uint8 (pxl, nb, 255);
          379  +		break;
          380  +	    case RL2_SAMPLE_UINT16:
          381  +		for (nb = 0; nb < num_bands; nb++)
          382  +		    rl2_set_pixel_sample_uint16 (pxl, nb, 0);
          383  +		break;
          384  +	    };
          385  +	  break;
          386  +      };
          387  +    return pxl;
          388  +}
          389  +
          390  +static int
          391  +test_uint8_gray (sqlite3 * handle)
          392  +{
          393  +/* testing UINT8 GRAYSCALE */
          394  +    struct tile_info info;
          395  +    rl2CoveragePtr cvg;
          396  +
          397  +    info.sample = RL2_SAMPLE_UINT8;
          398  +    info.pixel = RL2_PIXEL_GRAYSCALE;
          399  +    info.num_bands = 1;
          400  +    info.srid = 4326;
          401  +    info.coverage = "UINT8_GRAYSCALE";
          402  +    info.tile_w = 512;
          403  +    info.tile_h = 512;
          404  +
          405  +    rl2PixelPtr no_data =
          406  +	default_nodata (info.sample, info.pixel, info.num_bands);
          407  +    if (rl2_create_dbms_coverage
          408  +	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
          409  +	 RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1,
          410  +	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
          411  +      {
          412  +	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
          413  +	  return 0;
          414  +      }
          415  +
          416  +    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
          417  +    if (cvg == NULL)
          418  +      {
          419  +	  rl2_destroy_coverage (cvg);
          420  +	  return 0;
          421  +      }
          422  +
          423  +    if (rl2_load_raw_tiles_into_dbms
          424  +	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
          425  +	 tile_callback, &info, 1) != RL2_OK)
          426  +      {
          427  +	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
          428  +		   info.coverage);
          429  +	  return 0;
          430  +      }
          431  +
          432  +    rl2_destroy_coverage (cvg);
          433  +    rl2_destroy_pixel (no_data);
          434  +    return 1;
          435  +}
          436  +
          437  +static int
          438  +test_uint8_rgb (sqlite3 * handle)
          439  +{
          440  +/* testing UINT8 RGB */
          441  +    struct tile_info info;
          442  +    rl2CoveragePtr cvg;
          443  +
          444  +    info.sample = RL2_SAMPLE_UINT8;
          445  +    info.pixel = RL2_PIXEL_RGB;
          446  +    info.num_bands = 3;
          447  +    info.srid = 4326;
          448  +    info.coverage = "UINT8_RGB";
          449  +    info.tile_w = 512;
          450  +    info.tile_h = 512;
          451  +
          452  +    rl2PixelPtr no_data =
          453  +	default_nodata (info.sample, info.pixel, info.num_bands);
          454  +    if (rl2_create_dbms_coverage
          455  +	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
          456  +	 RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1,
          457  +	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
          458  +      {
          459  +	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
          460  +	  return 0;
          461  +      }
          462  +
          463  +    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
          464  +    if (cvg == NULL)
          465  +      {
          466  +	  rl2_destroy_coverage (cvg);
          467  +	  return 0;
          468  +      }
          469  +
          470  +    if (rl2_load_raw_tiles_into_dbms
          471  +	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
          472  +	 tile_callback, &info, 1) != RL2_OK)
          473  +      {
          474  +	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
          475  +		   info.coverage);
          476  +	  return 0;
          477  +      }
          478  +
          479  +    rl2_destroy_coverage (cvg);
          480  +    rl2_destroy_pixel (no_data);
          481  +    return 1;
          482  +}
          483  +
          484  +static int
          485  +test_int16_grid (sqlite3 * handle)
          486  +{
          487  +/* testing INT8 DATAGRID */
          488  +    struct tile_info info;
          489  +    rl2CoveragePtr cvg;
          490  +
          491  +    info.sample = RL2_SAMPLE_INT16;
          492  +    info.pixel = RL2_PIXEL_DATAGRID;
          493  +    info.num_bands = 1;
          494  +    info.srid = 4326;
          495  +    info.coverage = "INT16_GRID";
          496  +    info.tile_w = 512;
          497  +    info.tile_h = 512;
          498  +
          499  +    rl2PixelPtr no_data =
          500  +	default_nodata (info.sample, info.pixel, info.num_bands);
          501  +    if (rl2_create_dbms_coverage
          502  +	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
          503  +	 RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1,
          504  +	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
          505  +      {
          506  +	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
          507  +	  return 0;
          508  +      }
          509  +
          510  +    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
          511  +    if (cvg == NULL)
          512  +      {
          513  +	  rl2_destroy_coverage (cvg);
          514  +	  return 0;
          515  +      }
          516  +
          517  +    if (rl2_load_raw_tiles_into_dbms
          518  +	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
          519  +	 tile_callback, &info, 1) != RL2_OK)
          520  +      {
          521  +	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
          522  +		   info.coverage);
          523  +	  return 0;
          524  +      }
          525  +
          526  +    rl2_destroy_coverage (cvg);
          527  +    rl2_destroy_pixel (no_data);
          528  +    return 1;
          529  +}
          530  +
          531  +static int
          532  +test_double_grid (sqlite3 * handle)
          533  +{
          534  +/* testing DOUBLE DATAGRID */
          535  +    struct tile_info info;
          536  +    rl2CoveragePtr cvg;
          537  +
          538  +    info.sample = RL2_SAMPLE_DOUBLE;
          539  +    info.pixel = RL2_PIXEL_DATAGRID;
          540  +    info.num_bands = 1;
          541  +    info.srid = 4326;
          542  +    info.coverage = "DOUBLE_GRID";
          543  +    info.tile_w = 512;
          544  +    info.tile_h = 512;
          545  +
          546  +    rl2PixelPtr no_data =
          547  +	default_nodata (info.sample, info.pixel, info.num_bands);
          548  +    if (rl2_create_dbms_coverage
          549  +	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
          550  +	 RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1,
          551  +	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
          552  +      {
          553  +	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
          554  +	  return 0;
          555  +      }
          556  +
          557  +    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
          558  +    if (cvg == NULL)
          559  +      {
          560  +	  rl2_destroy_coverage (cvg);
          561  +	  return 0;
          562  +      }
          563  +
          564  +    if (rl2_load_raw_tiles_into_dbms
          565  +	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
          566  +	 tile_callback, &info, 1) != RL2_OK)
          567  +      {
          568  +	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
          569  +		   info.coverage);
          570  +	  return 0;
          571  +      }
          572  +
          573  +    rl2_destroy_coverage (cvg);
          574  +    rl2_destroy_pixel (no_data);
          575  +    return 1;
          576  +}
          577  +
          578  +int
          579  +main (int argc, char *argv[])
          580  +{
          581  +    int ret;
          582  +    sqlite3 *handle = NULL;
          583  +    char *err_msg = NULL;
          584  +    void *cache = spatialite_alloc_connection ();
          585  +    void *priv_data = rl2_alloc_private ();
          586  +
          587  +    if (argc > 1 || argv[0] == NULL)
          588  +	argc = 1;		/* silencing stupid compiler warnings */
          589  +    ret =
          590  +	sqlite3_open_v2 ("callback.sqlite", &handle,
          591  +			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
          592  +    if (ret != SQLITE_OK)
          593  +      {
          594  +	  fprintf (stderr, "cannot open in-memory db: %s\n",
          595  +		   sqlite3_errmsg (handle));
          596  +	  return -1;
          597  +      }
          598  +    spatialite_init_ex (handle, cache, 0);
          599  +    rl2_init (handle, priv_data, 0);
          600  +
          601  +/* the complete test is handled as an unique SQL Transaction */
          602  +    ret = sqlite3_exec (handle, "BEGIN", NULL, NULL, &err_msg);
          603  +    if (ret != SQLITE_OK)
          604  +      {
          605  +	  fprintf (stderr, "BEGIN TRANSACTION error: %s\n", err_msg);
          606  +	  sqlite3_free (err_msg);
          607  +	  return -2;
          608  +      }
          609  +
          610  +    ret =
          611  +	sqlite3_exec (handle, "SELECT InitSpatialMetadata()", NULL, NULL,
          612  +		      &err_msg);
          613  +    if (ret != SQLITE_OK)
          614  +      {
          615  +	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
          616  +	  sqlite3_free (err_msg);
          617  +	  sqlite3_close (handle);
          618  +	  return -3;
          619  +      }
          620  +    ret =
          621  +	sqlite3_exec (handle, "SELECT CreateRasterCoveragesTable()", NULL,
          622  +		      NULL, &err_msg);
          623  +    if (ret != SQLITE_OK)
          624  +      {
          625  +	  fprintf (stderr, "CreateRasterCoveragesTable() error: %s\n", err_msg);
          626  +	  sqlite3_free (err_msg);
          627  +	  return -4;
          628  +      }
          629  +
          630  +    if (!test_uint8_gray (handle))
          631  +	return -5;
          632  +
          633  +    if (!test_uint8_rgb (handle))
          634  +	return -6;
          635  +
          636  +    if (!test_int16_grid (handle))
          637  +	return -7;
          638  +
          639  +    if (!test_double_grid (handle))
          640  +	return -8;
          641  +
          642  +/* committing the SQL Transaction */
          643  +    ret = sqlite3_exec (handle, "COMMIT", NULL, NULL, &err_msg);
          644  +    if (ret != SQLITE_OK)
          645  +      {
          646  +	  fprintf (stderr, "COMMIT TRANSACTION error: %s\n", err_msg);
          647  +	  sqlite3_free (err_msg);
          648  +	  return -9;
          649  +      }
          650  +
          651  +    sqlite3_close (handle);
          652  +    spatialite_cleanup_ex (cache);
          653  +    rl2_cleanup_private (priv_data);
          654  +    spatialite_shutdown ();
          655  +    fprintf (stderr, "******** endok\n");
          656  +    return 0;
          657  +}

Changes to tools/Makefile.in.

     1         -# Makefile.in generated by automake 1.14.1 from Makefile.am.
            1  +# Makefile.in generated by automake 1.15 from Makefile.am.
     2      2   # @configure_input@
     3      3   
     4         -# Copyright (C) 1994-2013 Free Software Foundation, Inc.
            4  +# Copyright (C) 1994-2014 Free Software Foundation, Inc.
     5      5   
     6      6   # This Makefile.in is free software; the Free Software Foundation
     7      7   # gives unlimited permission to copy and/or distribute it,
     8      8   # with or without modifications, as long as this notice is preserved.
     9      9   
    10     10   # This program is distributed in the hope that it will be useful,
    11     11   # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
    12     12   # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    13     13   # PARTICULAR PURPOSE.
    14     14   
    15     15   @SET_MAKE@
    16     16   
    17     17   VPATH = @srcdir@
    18         -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
           18  +am__is_gnu_make = { \
           19  +  if test -z '$(MAKELEVEL)'; then \
           20  +    false; \
           21  +  elif test -n '$(MAKE_HOST)'; then \
           22  +    true; \
           23  +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
           24  +    true; \
           25  +  else \
           26  +    false; \
           27  +  fi; \
           28  +}
    19     29   am__make_running_with_option = \
    20     30     case $${target_option-} in \
    21     31         ?) ;; \
    22     32         *) echo "am__make_running_with_option: internal error: invalid" \
    23     33                 "target option '$${target_option-}' specified" >&2; \
    24     34            exit 1;; \
    25     35     esac; \
................................................................................
    76     86   NORMAL_UNINSTALL = :
    77     87   PRE_UNINSTALL = :
    78     88   POST_UNINSTALL = :
    79     89   build_triplet = @build@
    80     90   host_triplet = @host@
    81     91   bin_PROGRAMS = rl2sniff$(EXEEXT) rl2tool$(EXEEXT) wmslite$(EXEEXT)
    82     92   subdir = tools
    83         -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
    84         -	$(top_srcdir)/depcomp
    85     93   ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    86     94   am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
    87     95   	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
    88     96   	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
    89     97   	$(top_srcdir)/configure.ac
    90     98   am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    91     99   	$(ACLOCAL_M4)
          100  +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
    92    101   mkinstalldirs = $(install_sh) -d
    93    102   CONFIG_HEADER = $(top_builddir)/config.h
    94    103   CONFIG_CLEAN_FILES =
    95    104   CONFIG_CLEAN_VPATH_FILES =
    96    105   am__installdirs = "$(DESTDIR)$(bindir)"
    97    106   PROGRAMS = $(bin_PROGRAMS)
    98    107   am_rl2sniff_OBJECTS = rl2sniff.$(OBJEXT)
................................................................................
   165    174   am__define_uniq_tagged_files = \
   166    175     list='$(am__tagged_files)'; \
   167    176     unique=`for i in $$list; do \
   168    177       if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   169    178     done | $(am__uniquify_input)`
   170    179   ETAGS = etags
   171    180   CTAGS = ctags
          181  +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
   172    182   DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
   173    183   ACLOCAL = @ACLOCAL@
   174    184   AMTAR = @AMTAR@
   175    185   AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
   176    186   AR = @AR@
   177    187   AS = @AS@
   178    188   AUTOCONF = @AUTOCONF@
................................................................................
   353    363   	        && { if test -f $@; then exit 0; else break; fi; }; \
   354    364   	      exit 1;; \
   355    365   	  esac; \
   356    366   	done; \
   357    367   	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \
   358    368   	$(am__cd) $(top_srcdir) && \
   359    369   	  $(AUTOMAKE) --gnu tools/Makefile
   360         -.PRECIOUS: Makefile
   361    370   Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
   362    371   	@case '$?' in \
   363    372   	  *config.status*) \
   364    373   	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
   365    374   	  *) \
   366    375   	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
   367    376   	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
   674    683   	install-exec install-exec-am install-html install-html-am \
   675    684   	install-info install-info-am install-man install-pdf \
   676    685   	install-pdf-am install-ps install-ps-am install-strip \
   677    686   	installcheck installcheck-am installdirs maintainer-clean \
   678    687   	maintainer-clean-generic mostlyclean mostlyclean-compile \
   679    688   	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
   680    689   	tags tags-am uninstall uninstall-am uninstall-binPROGRAMS
          690  +
          691  +.PRECIOUS: Makefile
   681    692   
   682    693   
   683    694   # Tell versions [3.59,3.63) of GNU make to not export all variables.
   684    695   # Otherwise a system limit (for SysV at least) may be exceeded.
   685    696   .NOEXPORT:

Changes to tools/rl2sniff.c.

   730    730       double cy;
   731    731       double minX;
   732    732       double minY;
   733    733       double maxX;
   734    734       double maxY;
   735    735       double x_res;
   736    736       double y_res;
          737  +    short pixel_mode = RasterPixelIsArea;
   737    738       GTIFDefn definition;
   738    739       char *md5 = NULL;
   739    740       TIFF *in = (TIFF *) 0;
   740    741       GTIF *gtif = (GTIF *) 0;
   741    742   
   742    743   /* suppressing TIFF messages */
   743    744       TIFFSetErrorHandler (NULL);
................................................................................
   897    898       GTIFImageToPCS (gtif, &cx, &cy);
   898    899       maxX = cx;
   899    900   
   900    901   /* computing the pixel resolution */
   901    902       x_res = (maxX - minX) / (double) width;
   902    903       y_res = (maxY - minY) / (double) height;
   903    904       is_geotiff = 1;
          905  +
          906  +/* retrieving GTRasterTypeGeoKey */
          907  +    if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1))
          908  +	pixel_mode = RasterPixelIsArea;
          909  +    if (pixel_mode == RasterPixelIsPoint)
          910  +      {
          911  +	  /* adjusting the BBOX */
          912  +	  minX -= x_res / 2.0;
          913  +	  minY -= y_res / 2.0;
          914  +	  maxX += x_res / 2.0;
          915  +	  maxY += y_res / 2.0;
          916  +
          917  +      }
   904    918       goto print;
   905    919   
   906    920     recover:
   907    921       is_geotiff =
   908    922   	recover_incomplete_geotiff (in, width, height, &minX, &minY, &maxX,
   909    923   				    &maxY, &x_res, &y_res);
   910    924   

Changes to tools/rl2tool.c.

  1429   1429   
  1430   1430       sql =
  1431   1431   	"SELECT coverage_name, title, abstract, sample_type, pixel_type, "
  1432   1432   	"num_bands, compression, quality, tile_width, tile_height, "
  1433   1433   	"horz_resolution, vert_resolution, srid, auth_name, auth_srid, "
  1434   1434   	"ref_sys_name, extent_minx, extent_miny, extent_maxx, extent_maxy, "
  1435   1435   	"nodata_pixel, palette, statistics, red_band_index, green_band_index, "
  1436         -	"blue_band_index, nir_band_index, eneble_auto_ndvi "
         1436  +	"blue_band_index, nir_band_index, enable_auto_ndvi "
  1437   1437   	"FROM raster_coverages_ref_sys ORDER BY coverage_name";
  1438   1438       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  1439   1439       if (ret != SQLITE_OK)
  1440   1440   	goto stop;
  1441   1441   
  1442   1442       while (1)
  1443   1443         {
................................................................................
  1730   1730   			    printf
  1731   1731   				("       NIR band index: *** undefined ***\n");
  1732   1732   			}
  1733   1733   		  }
  1734   1734   		if (palette != NULL)
  1735   1735   		  {
  1736   1736   		      /* printing an eventual Palette */
  1737         -		      unsigned char i;
         1737  +		      unsigned short i;
  1738   1738   		      unsigned short num_entries;
  1739   1739   		      unsigned char *red = NULL;
  1740   1740   		      unsigned char *green = NULL;
  1741   1741   		      unsigned char *blue = NULL;
  1742   1742   		      rl2_get_palette_colors (palette, &num_entries, &red,
  1743   1743   					      &green, &blue);
  1744   1744   		      for (i = 0; i < num_entries; i++)

Changes to tools/wmslite.c.

    47     47   #endif
    48     48   
    49     49   #include <rasterlite2/rasterlite2.h>
    50     50   #include <spatialite.h>
    51     51   
    52     52   #define ARG_NONE		0
    53     53   #define ARG_DB_PATH		1
    54         -#define ARG_IP_PORT		2
    55         -#define ARG_MAX_THREADS		3
    56         -#define ARG_CACHE_SIZE		4
           54  +#define ARG_IP_ADDR		2
           55  +#define ARG_IP_PORT		3
           56  +#define ARG_MAX_THREADS		4
           57  +#define ARG_CACHE_SIZE		5
    57     58   
    58     59   #define WMS_ILLEGAL_REQUEST	0
    59     60   #define WMS_GET_CAPABILITIES	1
    60     61   #define WMS_GET_MAP		2
    61     62   
    62     63   #define WMS_UNKNOWN		-1
    63     64   #define WMS_TRANSPARENT		10
................................................................................
   305    306       unsigned char blue;
   306    307   };
   307    308   
   308    309   struct http_request
   309    310   {
   310    311   /* a struct wrapping an HTTP request */
   311    312       unsigned int id;		/* request ID */
          313  +    const char *ip_addr;
   312    314       int port_no;
   313    315   #ifdef _WIN32
   314    316       SOCKET socket;		/* Socket on which to receive data */
   315    317   #else
   316    318       int socket;			/* Socket on which to receive data */
   317    319   #endif
   318    320       struct wms_list *list;
................................................................................
  2566   2568       sqlite3_free (dummy);
  2567   2569       gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
  2568   2570       gaiaAppendToOutBuffer (xml_response, xml_text.Buffer);
  2569   2571       gaiaOutBufferReset (&xml_text);
  2570   2572   }
  2571   2573   
  2572   2574   static void
  2573         -build_http_error (int http_status, gaiaOutBufferPtr xml_response, int port_no)
         2575  +build_http_error (int http_status, gaiaOutBufferPtr xml_response,
         2576  +		  const char *ip_addr, int port_no)
  2574   2577   {
  2575   2578   /* preparing an HTTP error */
  2576   2579       char *dummy;
  2577   2580       gaiaOutBuffer http_text;
  2578   2581       gaiaOutBufferInitialize (&http_text);
  2579   2582       gaiaAppendToOutBuffer (&http_text,
  2580   2583   			   "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n");
................................................................................
  2593   2596   				 "HTTP/1.1 500 Internal Server Error\r\n");
  2594   2597   	  gaiaAppendToOutBuffer (&http_text,
  2595   2598   				 "<title>500 Internal Server Error</title>\r\n");
  2596   2599   	  gaiaAppendToOutBuffer (&http_text, "</head><body>\r\n");
  2597   2600   	  gaiaAppendToOutBuffer (&http_text,
  2598   2601   				 "<h1>Internal Server Error</h1>\n");
  2599   2602         }
  2600         -    dummy =
  2601         -	sqlite3_mprintf
  2602         -	("<address>WmsLite/%s [%s] at localhost (127.0.0.1) Port %d</address>\r\n",
  2603         -	 rl2_version (), rl2_target_cpu (), port_no);
         2603  +    if (strcmp (ip_addr, "127.0.0.1") == 0)
         2604  +	dummy =
         2605  +	    sqlite3_mprintf
         2606  +	    ("<address>WmsLite/%s [%s] at localhost (127.0.0.1) Port %d</address>\r\n",
         2607  +	     rl2_version (), rl2_target_cpu (), port_no);
         2608  +    else
         2609  +	dummy =
         2610  +	    sqlite3_mprintf
         2611  +	    ("<address>WmsLite/%s [%s] at IP-addr %s Port %d</address>\r\n",
         2612  +	     rl2_version (), rl2_target_cpu (), ip_addr, port_no);
  2604   2613       gaiaAppendToOutBuffer (&http_text, dummy);
  2605   2614       sqlite3_free (dummy);
  2606   2615       gaiaAppendToOutBuffer (&http_text, "</body></html>\r\n");
  2607   2616       gaiaAppendToOutBuffer (&http_text, "");
  2608   2617       dummy = get_current_timestamp ();
  2609   2618       gaiaAppendToOutBuffer (xml_response, dummy);
  2610   2619       sqlite3_free (dummy);
................................................................................
  2616   2625       gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
  2617   2626       gaiaAppendToOutBuffer (xml_response, http_text.Buffer);
  2618   2627       gaiaOutBufferReset (&http_text);
  2619   2628   }
  2620   2629   
  2621   2630   static void
  2622   2631   build_get_capabilities (struct wms_list *list, char **cached, int *cached_len,
  2623         -			int port_no)
         2632  +			const char *ip_addr, int port_no)
  2624   2633   {
  2625   2634   /* preparing the WMS GetCapabilities XML document */
  2626   2635       struct wms_layer *lyr;
  2627   2636       struct wms_group *grp;
  2628   2637       struct wms_style *style;
  2629   2638       struct wms_alt_srid *alt_srid;
  2630   2639       struct wms_keyword *keyword;
................................................................................
  2643   2652   			   "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd\">\r\n");
  2644   2653       gaiaAppendToOutBuffer (&xml_text, "<Service>\r\n<Name>WMS</Name>\r\n");
  2645   2654       gaiaAppendToOutBuffer (&xml_text, "<Title>WmsLite test server</Title>\r\n");
  2646   2655       gaiaAppendToOutBuffer (&xml_text,
  2647   2656   			   "<Abstract>A simple light-weight WMS server for testing RasterLite2 Coverages.</Abstract>\r\n");
  2648   2657       gaiaAppendToOutBuffer (&xml_text,
  2649   2658   			   "<KeywordList>\r\n<Keyword>maps</Keyword>\r\n</KeywordList>\r\n");
  2650         -    dummy =
  2651         -	sqlite3_mprintf
  2652         -	("<OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",
  2653         -	 port_no);
         2659  +    if (port_no == 80)
         2660  +	dummy =
         2661  +	    sqlite3_mprintf
         2662  +	    ("<OnlineResource xlink:href=\"http://%s/wmslite?\" ", ip_addr);
         2663  +    else
         2664  +	dummy =
         2665  +	    sqlite3_mprintf
         2666  +	    ("<OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
         2667  +	     ip_addr, port_no);
  2654   2668       gaiaAppendToOutBuffer (&xml_text, dummy);
  2655   2669       sqlite3_free (dummy);
  2656   2670       gaiaAppendToOutBuffer (&xml_text,
  2657   2671   			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/>\r\n");
  2658   2672       gaiaAppendToOutBuffer (&xml_text,
  2659   2673   			   "<ContactInformation>\r\n<ContactPersonPrimary>\r\n");
  2660   2674       gaiaAppendToOutBuffer (&xml_text,
................................................................................
  2682   2696       gaiaAppendToOutBuffer (&xml_text, "<MaxWidth>5000</MaxWidth>\r\n");
  2683   2697       gaiaAppendToOutBuffer (&xml_text, "<MaxHeight>5000</MaxHeight>\r\n");
  2684   2698       gaiaAppendToOutBuffer (&xml_text, "</Service>\r\n");
  2685   2699       gaiaAppendToOutBuffer (&xml_text,
  2686   2700   			   "<Capability>\r\n<Request>\r\n<GetCapabilities>\r\n");
  2687   2701       gaiaAppendToOutBuffer (&xml_text,
  2688   2702   			   "<Format>text/xml</Format>\r\n<DCPType>\r\n<HTTP>\r\n");
  2689         -    dummy =
  2690         -	sqlite3_mprintf
  2691         -	("<Get><OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",
  2692         -	 port_no);
         2703  +    if (port_no == 80)
         2704  +	dummy =
         2705  +	    sqlite3_mprintf
         2706  +	    ("<Get><OnlineResource xlink:href=\"http://%s/wmslite?\" ",
         2707  +	     ip_addr);
         2708  +    else
         2709  +	dummy =
         2710  +	    sqlite3_mprintf
         2711  +	    ("<Get><OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
         2712  +	     ip_addr, port_no);
  2693   2713       gaiaAppendToOutBuffer (&xml_text, dummy);
  2694   2714       sqlite3_free (dummy);
  2695   2715       gaiaAppendToOutBuffer (&xml_text,
  2696   2716   			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
  2697   2717       gaiaAppendToOutBuffer (&xml_text,
  2698   2718   			   "</HTTP>\r\n</DCPType>\r\n</GetCapabilities>\r\n");
  2699   2719       gaiaAppendToOutBuffer (&xml_text,
  2700   2720   			   "<GetMap>\r\n<Format>image/png</Format>\r\n");
  2701   2721       gaiaAppendToOutBuffer (&xml_text, "<Format>image/jpeg</Format>\r\n");
  2702   2722       gaiaAppendToOutBuffer (&xml_text, "<Format>application/x-pdf</Format>\r\n");
  2703   2723       gaiaAppendToOutBuffer (&xml_text, "<Format>image/tiff</Format>\r\n");
  2704   2724       gaiaAppendToOutBuffer (&xml_text, "<DCPType>\r\n<HTTP>\r\n<Get>");
  2705         -    dummy =
  2706         -	sqlite3_mprintf
  2707         -	("<OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",
  2708         -	 port_no);
         2725  +    if (port_no == 80)
         2726  +	dummy =
         2727  +	    sqlite3_mprintf
         2728  +	    ("<OnlineResource xlink:href=\"http://%s/wmslite?\" ", ip_addr);
         2729  +    else
         2730  +	dummy =
         2731  +	    sqlite3_mprintf
         2732  +	    ("<OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
         2733  +	     ip_addr, port_no);
  2709   2734       gaiaAppendToOutBuffer (&xml_text, dummy);
  2710   2735       sqlite3_free (dummy);
  2711   2736       gaiaAppendToOutBuffer (&xml_text,
  2712   2737   			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
  2713   2738       gaiaAppendToOutBuffer (&xml_text,
  2714   2739   			   "</HTTP>\r\n</DCPType>\r\n</GetMap>\r\n</Request>\r\n");
  2715   2740       gaiaAppendToOutBuffer (&xml_text,
................................................................................
  3193   3218   	sqlite3_bind_text (stmt, 9, "image/png", strlen ("image/png"),
  3194   3219   			   SQLITE_TRANSIENT);
  3195   3220       if (args->has_bgcolor)
  3196   3221   	sprintf (bgcolor, "#%02x%02x%02x", args->red, args->green, args->blue);
  3197   3222       else
  3198   3223   	strcpy (bgcolor, "#ffffff");
  3199   3224       sqlite3_bind_text (stmt, 10, bgcolor, strlen (bgcolor), SQLITE_TRANSIENT);
  3200         -    sqlite3_bind_int (stmt, 11, args->transparent);
         3225  +    if (args->transparent == WMS_OPAQUE)
         3226  +	sqlite3_bind_int (stmt, 11, 0);
         3227  +    else
         3228  +	sqlite3_bind_int (stmt, 11, 1);
  3201   3229       if (args->format == RL2_OUTPUT_FORMAT_JPEG)
  3202   3230   	sqlite3_bind_int (stmt, 12, 80);
  3203   3231       else
  3204   3232   	sqlite3_bind_int (stmt, 12, 100);
  3205   3233       while (1)
  3206   3234         {
  3207   3235   	  ret = sqlite3_step (stmt);
................................................................................
  3399   3427   	  wms_get_capabilities (req->socket, req->cached_capabilities,
  3400   3428   				req->cached_capabilities_len, req->log);
  3401   3429         }
  3402   3430       if (args->request_type == WMS_GET_MAP)
  3403   3431         {
  3404   3432   	  /* preparing the WMS GetMap payload */
  3405   3433   	  args->db_handle = req->conn->handle;
  3406         -	  args->stmt_get_map = req->conn->stmt_get_map;
         3434  +	  args->stmt_get_map_raster = req->conn->stmt_get_map_raster;
         3435  +	  args->stmt_get_map_vector = req->conn->stmt_get_map_vector;
  3407   3436   	  log_get_map_1 (req->log, timestamp, http_status, method, url, args);
  3408   3437   	  wms_get_map (args, req->socket, req->log);
  3409   3438         }
  3410   3439       goto end_request;
  3411   3440   
  3412   3441   /* preparing an HTTP error code */
  3413   3442     http_error:
  3414   3443       gaiaOutBufferInitialize (&xml_response);
  3415         -    build_http_error (http_status, &xml_response, req->port_no);
         3444  +    build_http_error (http_status, &xml_response, req->ip_addr, req->port_no);
  3416   3445       curr = 0;
  3417   3446       while (1)
  3418   3447         {
  3419   3448   	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
  3420   3449   	  if (rd == 0)
  3421   3450   	      break;
  3422   3451   	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
  3520   3549   	  wms_get_map (args, req->socket, req->log);
  3521   3550         }
  3522   3551       goto end_request;
  3523   3552   
  3524   3553   /* preparing an HTTP error code */
  3525   3554     http_error:
  3526   3555       gaiaOutBufferInitialize (&xml_response);
  3527         -    build_http_error (http_status, &xml_response, req->port_no);
         3556  +    build_http_error (http_status, &xml_response, req->ip_addr, req->port_no);
  3528   3557       curr = 0;
  3529   3558       while (1)
  3530   3559         {
  3531   3560   	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
  3532   3561   	  if (rd == 0)
  3533   3562   	      break;
  3534   3563   	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
  3563   3592       req->conn->status = CONNECTION_AVAILABLE;
  3564   3593       free (req);
  3565   3594       pthread_exit (NULL);
  3566   3595   }
  3567   3596   #endif
  3568   3597   
  3569   3598   static void
  3570         -do_accept_loop (struct neutral_socket *skt, struct wms_list *list, int port_no,
  3571         -		sqlite3 * db_handle, sqlite3_stmt * stmt_log,
  3572         -		struct connections_pool *pool, struct server_log *log,
  3573         -		char *cached_capab, int cached_capab_len)
         3599  +do_accept_loop (struct neutral_socket *skt, struct wms_list *list,
         3600  +		const char *xip_addr, int port_no, sqlite3 * db_handle,
         3601  +		sqlite3_stmt * stmt_log, struct connections_pool *pool,
         3602  +		struct server_log *log, char *cached_capab,
         3603  +		int cached_capab_len)
  3574   3604   {
  3575   3605   /* implementing the ACCEPT loop */
  3576   3606       unsigned int id = 0;
  3577   3607       struct read_connection *conn;
  3578   3608       int ic;
  3579   3609       time_t diff;
  3580   3610       time_t now;
................................................................................
  3607   3637   		      WSACleanup ();
  3608   3638   		      fprintf (stderr, "error from accept()\n");
  3609   3639   		      return;
  3610   3640   		  }
  3611   3641   	    }
  3612   3642   	  req = malloc (sizeof (struct http_request));
  3613   3643   	  req->id = id++;
         3644  +	  req->ip_addr = xip_addr;
  3614   3645   	  req->port_no = port_no;
  3615   3646   	  req->socket = client;
  3616   3647   	  req->list = list;
  3617   3648   	  req->cached_capabilities = cached_capab;
  3618   3649   	  req->cached_capabilities_len = cached_capab_len;
  3619   3650   	  while (1)
  3620   3651   	    {
................................................................................
  3692   3723   	    {
  3693   3724   		close (socket);
  3694   3725   		fprintf (stderr, "error from accept()\n");
  3695   3726   		return;
  3696   3727   	    }
  3697   3728   	  req = malloc (sizeof (struct http_request));
  3698   3729   	  req->id = id++;
         3730  +	  req->ip_addr = xip_addr;
  3699   3731   	  req->port_no = port_no;
  3700   3732   	  req->socket = client;
  3701   3733   	  req->list = list;
  3702   3734   	  req->cached_capabilities = cached_capab;
  3703   3735   	  req->cached_capabilities_len = cached_capab_len;
  3704   3736   	  while (1)
  3705   3737   	    {
................................................................................
  3761   3793   	  pthread_create (&thread_id, NULL, berkeley_http_request,
  3762   3794   			  (void *) req);
  3763   3795         }
  3764   3796   #endif
  3765   3797   }
  3766   3798   
  3767   3799   static int
  3768         -do_start_http (int port_no, struct neutral_socket *srv_skt, int max_threads)
         3800  +do_start_http (const char *ip_addr, int port_no, struct neutral_socket *srv_skt,
         3801  +	       int max_threads)
  3769   3802   {
  3770   3803   /* starting the HTTP server */
  3771   3804   #ifdef _WIN32
  3772   3805   /* Winsockets */
  3773   3806       WSADATA wd;
  3774   3807       SOCKET skt = INVALID_SOCKET;
  3775   3808       SOCKADDR_IN addr;
................................................................................
  3783   3816       if (skt == INVALID_SOCKET)
  3784   3817         {
  3785   3818   	  fprintf (stderr, "unable to create a socket\n");
  3786   3819   	  return 0;
  3787   3820         }
  3788   3821       addr.sin_family = AF_INET;
  3789   3822       addr.sin_port = htons (port_no);
  3790         -    addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
         3823  +    addr.sin_addr.s_addr = inet_addr (ip_addr);
  3791   3824       if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
  3792   3825         {
  3793   3826   	  fprintf (stderr, "unable to bind the socket\n");
  3794   3827   	  closesocket (skt);
  3795   3828   	  return 0;
  3796   3829         }
  3797   3830       if (listen (skt, SOMAXCONN) == SOCKET_ERROR)
................................................................................
  3810   3843       if (skt == -1)
  3811   3844         {
  3812   3845   	  fprintf (stderr, "unable to create a socket\n");
  3813   3846   	  return 0;
  3814   3847         }
  3815   3848       addr.sin_family = AF_INET;
  3816   3849       addr.sin_port = htons (port_no);
  3817         -    addr.sin_addr.s_addr = htonl (INADDR_ANY);
         3850  +    //addr.sin_addr.s_addr = htonl (INADDR_ANY);
         3851  +    addr.sin_addr.s_addr = inet_addr (ip_addr);
  3818   3852       if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == -1)
  3819   3853         {
  3820   3854   	  fprintf (stderr, "unable to bind the socket\n");
  3821   3855   	  close (skt);
  3822   3856   	  return 0;
  3823   3857         }
  3824   3858       if (listen (skt, SOMAXCONN) == -1)
................................................................................
  4440   4474   static void
  4441   4475   get_raster_styles (sqlite3 * handle, struct wms_list *list)
  4442   4476   {
  4443   4477   /* retrieving all declared Raster Styles */
  4444   4478       int ret;
  4445   4479       sqlite3_stmt *stmt;
  4446   4480       const char *sql = "SELECT coverage_name, name, title, abstract "
  4447         -	"FROM SE_raster_styled_layers_view ORDER BY coverage_name, style_id";
         4481  +	"FROM SE_raster_styled_layers_view ORDER BY coverage_name, name";
  4448   4482       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  4449   4483       if (ret != SQLITE_OK)
  4450   4484   	return;
  4451   4485       while (1)
  4452   4486         {
  4453   4487   	  /* scrolling the result set rows */
  4454   4488   	  ret = sqlite3_step (stmt);
................................................................................
  4475   4509   static void
  4476   4510   get_vector_styles (sqlite3 * handle, struct wms_list *list)
  4477   4511   {
  4478   4512   /* retrieving all declared Vector Styles */
  4479   4513       int ret;
  4480   4514       sqlite3_stmt *stmt;
  4481   4515       const char *sql = "SELECT coverage_name, name, title, abstract "
  4482         -	"FROM SE_vector_styled_layers_view ORDER BY coverage_name, style_id";
         4516  +	"FROM SE_vector_styled_layers_view ORDER BY coverage_name, name";
  4483   4517       ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
  4484   4518       if (ret != SQLITE_OK)
  4485   4519   	return;
  4486   4520       while (1)
  4487   4521         {
  4488   4522   	  /* scrolling the result set rows */
  4489   4523   	  ret = sqlite3_step (stmt);
................................................................................
  4746   4780   {
  4747   4781   /* printing the argument list */
  4748   4782       fprintf (stderr, "\n\nusage: wmslite ARGLIST ]\n");
  4749   4783       fprintf (stderr,
  4750   4784   	     "==============================================================\n");
  4751   4785       fprintf (stderr, "-db or --db-path      pathname  RasterLite2 DB path\n");
  4752   4786       fprintf (stderr,
         4787  +	     "-ip or --ip-addr    ip-address  IP address [default: 127.0.0.1]\n\n");
         4788  +    fprintf (stderr,
  4753   4789   	     "-p or --ip-port       number    IP port number [default: 8080]\n\n");
  4754   4790       fprintf (stderr,
  4755   4791   	     "-mt or --max-threads   num      max number of concurrent threads\n");
  4756   4792       fprintf (stderr,
  4757   4793   	     "-cs or --cache-size    num      DB cache size (how many pages)\n");
  4758   4794       fprintf (stderr,
  4759   4795   	     "-dbg or --debug                 verbose debugginh mode\n");
................................................................................
  4768   4804       sqlite3_stmt *stmt_log = NULL;
  4769   4805       const char *sql;
  4770   4806       int ret;
  4771   4807       int i;
  4772   4808       int error = 0;
  4773   4809       int next_arg = ARG_NONE;
  4774   4810       const char *db_path = NULL;
         4811  +    const char *ip_addr = "127.0.0.1";
  4775   4812       int port_no = 8080;
  4776   4813       int cache_size = 0;
  4777   4814       void *cache;
  4778   4815       void *priv_data;
  4779   4816       struct wms_list *list = NULL;
  4780   4817       struct connections_pool *pool;
  4781   4818       struct server_log *log;
................................................................................
  4805   4842   	  if (next_arg != ARG_NONE)
  4806   4843   	    {
  4807   4844   		switch (next_arg)
  4808   4845   		  {
  4809   4846   		  case ARG_DB_PATH:
  4810   4847   		      db_path = argv[i];
  4811   4848   		      break;
         4849  +		  case ARG_IP_ADDR:
         4850  +		      ip_addr = argv[i];
         4851  +		      break;
  4812   4852   		  case ARG_IP_PORT:
  4813   4853   		      port_no = atoi (argv[i]);
  4814   4854   		      break;
  4815   4855   		  case ARG_CACHE_SIZE:
  4816   4856   		      cache_size = atoi (argv[i]);
  4817   4857   		      break;
  4818   4858   		  case ARG_MAX_THREADS:
................................................................................
  4830   4870   		return -1;
  4831   4871   	    }
  4832   4872   	  if (strcmp (argv[i], "-db") == 0
  4833   4873   	      || strcasecmp (argv[i], "--db-path") == 0)
  4834   4874   	    {
  4835   4875   		next_arg = ARG_DB_PATH;
  4836   4876   		continue;
         4877  +	    }
         4878  +	  if (strcmp (argv[i], "-ip") == 0
         4879  +	      || strcasecmp (argv[i], "--ip-addr") == 0)
         4880  +	    {
         4881  +		next_arg = ARG_IP_ADDR;
         4882  +		continue;
  4837   4883   	    }
  4838   4884   	  if (strcmp (argv[i], "-p") == 0
  4839   4885   	      || strcasecmp (argv[i], "--ip-port") == 0)
  4840   4886   	    {
  4841   4887   		next_arg = ARG_IP_PORT;
  4842   4888   		continue;
  4843   4889   	    }
................................................................................
  4932   4978       get_raster_alt_srids (handle, list);
  4933   4979       get_vector_alt_srids (handle, list);
  4934   4980       get_raster_keywords (handle, list);
  4935   4981       get_vector_keywords (handle, list);
  4936   4982       glob.list = list;
  4937   4983       complete_layer_config (handle, list);
  4938   4984       build_get_capabilities (list, &cached_capabilities,
  4939         -			    &cached_capabilities_len, port_no);
         4985  +			    &cached_capabilities_len, ip_addr, port_no);
  4940   4986       glob.cached_capabilities = cached_capabilities;
  4941   4987   
  4942   4988   /* creating the read connections pool */
  4943   4989       pool = alloc_connections_pool (db_path, max_threads);
  4944   4990       if (pool == NULL)
  4945   4991         {
  4946   4992   	  fprintf (stderr, "ERROR: unable to initialize a connections pool\n");
................................................................................
  4954   5000         {
  4955   5001   	  fprintf (stderr, "ERROR: unable to initialize the server log\n");
  4956   5002   	  goto stop;
  4957   5003         }
  4958   5004       glob.log = log;
  4959   5005   
  4960   5006   /* starting the HTTP server */
  4961         -    if (!do_start_http (port_no, &skt_ptr, max_threads))
         5007  +    if (!do_start_http (ip_addr, port_no, &skt_ptr, max_threads))
  4962   5008   	goto stop;
  4963   5009   
  4964   5010   /* starting the logging facility */
  4965   5011       sql = "CREATE TABLE IF NOT EXISTS wms_server_log (\n"
  4966   5012   	"\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n"
  4967   5013   	"\ttimestamp TEXT NOT NULL,\n"
  4968   5014   	"\tclient_ip_addr TEXT NOT NULL,\n"
................................................................................
  4999   5045         {
  5000   5046   	  printf ("INSERT INTO LOG error: %s\n", sqlite3_errmsg (handle));
  5001   5047   	  goto stop;
  5002   5048         }
  5003   5049       glob.stmt_log = stmt_log;
  5004   5050   
  5005   5051   /* looping on requests */
  5006         -    do_accept_loop (&skt_ptr, list, port_no, handle, stmt_log, pool, log,
  5007         -		    cached_capabilities, cached_capabilities_len);
         5052  +    do_accept_loop (&skt_ptr, list, ip_addr, port_no, handle, stmt_log, pool,
         5053  +		    log, cached_capabilities, cached_capabilities_len);
  5008   5054   
  5009   5055     stop:
  5010   5056       destroy_wms_list (list);
  5011   5057       list = NULL;
  5012   5058       glob.list = NULL;
  5013   5059       clean_shutdown ();
  5014   5060       return 0;
  5015   5061   }