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

include $(LOCAL_PATH)/jsqlite-R4.2.0.mk
include $(LOCAL_PATH)/iconv-1.13.1.mk
include $(LOCAL_PATH)/sqlite-3080403.mk
include $(LOCAL_PATH)/proj4-4.8.0.mk
include $(LOCAL_PATH)/geos-3.4.2.mk
include $(LOCAL_PATH)/spatialite-4.2.0.mk
include $(LOCAL_PATH)/libjpeg-8d.mk
include $(LOCAL_PATH)/giflib-5.0.6.mk
include $(LOCAL_PATH)/libpng-1.6.10.mk
include $(LOCAL_PATH)/libtiff-4.0.3.mk
include $(LOCAL_PATH)/libwebp-0.4.0.mk
include $(LOCAL_PATH)/pixman-0.32.4.mk
include $(LOCAL_PATH)/freetype-2.5.3.mk
include $(LOCAL_PATH)/fontconfig-2.11.1.mk
include $(LOCAL_PATH)/expat-2.1.0.mk
include $(LOCAL_PATH)/cairo-1.12.14.mk
include $(LOCAL_PATH)/libgeotiff-1.4.0.mk
include $(LOCAL_PATH)/libxml2-2.9.1.mk
include $(LOCAL_PATH)/libcurl-7.36.0.mk
include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk
include $(LOCAL_PATH)/rasterlite2-4.2.0.mk
$(call import-module,android/cpufeatures)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




































































































Added Android_R4.3.0.mk.













































































































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

include $(LOCAL_PATH)/charls-1.0.mk
include $(LOCAL_PATH)/jsqlite-R4.2.0.mk
include $(LOCAL_PATH)/iconv-1.13.1.mk
include $(LOCAL_PATH)/sqlite-3081002.mk
include $(LOCAL_PATH)/proj4-4.9.1.mk
include $(LOCAL_PATH)/geos-3.4.2.mk
include $(LOCAL_PATH)/spatialite-4.3.0.mk
include $(LOCAL_PATH)/libjpeg-8d.mk
include $(LOCAL_PATH)/openjpeg-2.0.0.mk
include $(LOCAL_PATH)/giflib-5.0.6.mk
include $(LOCAL_PATH)/libpng-1.6.10.mk
include $(LOCAL_PATH)/libtiff-4.0.3.mk
include $(LOCAL_PATH)/libwebp-0.4.0.mk
include $(LOCAL_PATH)/pixman-0.32.4.mk
include $(LOCAL_PATH)/freetype-2.5.3.mk
include $(LOCAL_PATH)/fontconfig-2.11.1.mk
include $(LOCAL_PATH)/expat-2.1.0.mk
include $(LOCAL_PATH)/cairo-1.12.14.mk
include $(LOCAL_PATH)/libgeotiff-1.4.0.mk
include $(LOCAL_PATH)/libxml2-2.9.1.mk
include $(LOCAL_PATH)/libcurl-7.36.0.mk
include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk
include $(LOCAL_PATH)/rasterlite2-4.3.0.mk
$(call import-module,android/cpufeatures)

Changes to Makefile-static-MinGW.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	./static_bin/wmslite.exe

./static_bin/rl2sniff.exe: ./tools/rl2sniff.o 
	$(GG) ./tools/rl2sniff.o -o ./static_bin/rl2sniff.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/liblwgeom.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \
................................................................................
	strip --strip-all ./static_bin/rl2sniff.exe
	
./static_bin/rl2tool.exe: ./tools/rl2tool.o 
	$(GG) ./tools/rl2tool.o -o ./static_bin/rl2tool.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/liblwgeom.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \
................................................................................
	strip --strip-all ./static_bin/rl2tool.exe

./static_bin/wmslite.exe: ./tools/wmslite.o 
	$(GG) ./tools/wmslite.o -o ./static_bin/wmslite.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/liblwgeom.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \







|







 







|







 







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	./static_bin/wmslite.exe

./static_bin/rl2sniff.exe: ./tools/rl2sniff.o 
	$(GG) ./tools/rl2sniff.o -o ./static_bin/rl2sniff.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/librttopo.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \
................................................................................
	strip --strip-all ./static_bin/rl2sniff.exe
	
./static_bin/rl2tool.exe: ./tools/rl2tool.o 
	$(GG) ./tools/rl2tool.o -o ./static_bin/rl2tool.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/librttopo.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \
................................................................................
	strip --strip-all ./static_bin/rl2tool.exe

./static_bin/wmslite.exe: ./tools/wmslite.o 
	$(GG) ./tools/wmslite.o -o ./static_bin/wmslite.exe \
	/usr/local/lib/librasterlite2.a \
	/usr/local/lib/libspatialite.a \
	/usr/local/lib/libsqlite3.a \
	/usr/local/lib/librttopo.a \
	/usr/local/lib/libproj.a \
	/usr/local/lib/libgeos_c.a \
	/usr/local/lib/libgeos.a \
	/usr/local/lib/libfreexl.a \
	/usr/local/lib/libcairo.a \
	/usr/local/lib/libpixman-1.a \
	/usr/local/lib/libfontconfig.a \

Changes to Makefile.am.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = headers src test tools

EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \
	Makefile-static-MinGW

AUTOMAKE_OPTIONS = dist-zip

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = rasterlite2.pc

coverage-init:
	lcov --directory src --capture --initial --output-file rasterlite2_cov.info

coverage::
	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture

	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info

MOSTLYCLEANFILES = rasterlite2_cov.info 




|


|









>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = headers src test tools

EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \
	Makefile-static-MinGW

AUTOMAKE_OPTIONS = dist-zip foreign

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = rasterlite2.pc

coverage-init:
	lcov --directory src --capture --initial --output-file rasterlite2_cov.info

coverage::
	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture
	lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info
	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info

MOSTLYCLEANFILES = rasterlite2_cov.info 

Changes to Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18










19
20
21
22
23
24
25
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94


95
96
97
98
99
100
101
...
180
181
182
183
184
185
186




187
188
189
190
191
192
193
...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
...
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
...
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
...
882
883
884
885
886
887
888


889
890
891
892
893
894

895
896
897
898
899
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = .
DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
	$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
	$(top_srcdir)/configure $(am__configure_deps) \
	$(srcdir)/config.h.in $(srcdir)/Doxyfile.in \
	$(srcdir)/rasterlite2.pc.in COPYING compile config.guess \
	config.sub depcomp install-sh missing ltmain.sh
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)


am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
 configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES = Doxyfile rasterlite2.pc
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
................................................................................
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
CSCOPE = cscope
DIST_SUBDIRS = $(SUBDIRS)




DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
  if test -d "$(distdir)"; then \
    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
      && rm -rf "$(distdir)" \
................................................................................
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = headers src test tools
EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \
	Makefile-static-MinGW

AUTOMAKE_OPTIONS = dist-zip
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = rasterlite2.pc
MOSTLYCLEANFILES = rasterlite2_cov.info 
all: config.h
	$(MAKE) $(AM_MAKEFLAGS) all-recursive

.SUFFIXES:
am--refresh: Makefile
	@:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
	@for dep in $?; do \
	  case '$(am__configure_deps)' in \
	    *$$dep*) \
	      echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \
	      $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \
		&& exit 0; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    echo ' $(SHELL) ./config.status'; \
	    $(SHELL) ./config.status;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
................................................................................
	$(am__post_remove_distdir)

dist-xz: distdir
	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
	$(am__post_remove_distdir)

dist-tarZ: distdir
	@echo WARNING: "Support for shar distribution archives is" \
	               "deprecated." >&2
	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
	$(am__post_remove_distdir)

dist-shar: distdir
	@echo WARNING: "Support for distribution archives compressed with" \
		       "legacy program 'compress' is deprecated." >&2
	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
	$(am__post_remove_distdir)
dist-zip: distdir
	-rm -f $(distdir).zip
	zip -rq $(distdir).zip $(distdir)
	$(am__post_remove_distdir)
................................................................................
	*.shar.gz*) \
	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
	*.zip*) \
	  unzip $(distdir).zip ;;\
	esac
	chmod -R a-w $(distdir)
	chmod u+w $(distdir)
	mkdir $(distdir)/_build $(distdir)/_inst
	chmod a-w $(distdir)
	test -d $(distdir)/_build || exit 0; \
	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
	  && am__cwd=`pwd` \
	  && $(am__cd) $(distdir)/_build \
	  && ../configure \
	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
	    $(DISTCHECK_CONFIGURE_FLAGS) \
	    --srcdir=.. --prefix="$$dc_install_base" \
	  && $(MAKE) $(AM_MAKEFLAGS) \
	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
	  && $(MAKE) $(AM_MAKEFLAGS) check \
	  && $(MAKE) $(AM_MAKEFLAGS) install \
	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
................................................................................
	install-man install-pdf install-pdf-am install-pkgconfigDATA \
	install-ps install-ps-am install-strip installcheck \
	installcheck-am installdirs installdirs-am maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
	uninstall-am uninstall-pkgconfigDATA




coverage-init:
	lcov --directory src --capture --initial --output-file rasterlite2_cov.info

coverage::
	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture

	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|













|
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<







>
>







 







>
>
>
>







 







|


|













|
|




|

|
<







 







|
|





|
|







 







|





|
|


|







 







>
>






>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
85
86
87
88
89
90
91






92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
...
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = .






ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
	$(am__configure_deps) $(am__DIST_COMMON)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
 configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES = Doxyfile rasterlite2.pc
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
................................................................................
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
CSCOPE = cscope
DIST_SUBDIRS = $(SUBDIRS)
am__DIST_COMMON = $(srcdir)/Doxyfile.in $(srcdir)/Makefile.in \
	$(srcdir)/config.h.in $(srcdir)/rasterlite2.pc.in AUTHORS \
	COPYING ChangeLog INSTALL NEWS README compile config.guess \
	config.sub depcomp install-sh ltmain.sh missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
  if test -d "$(distdir)"; then \
    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
      && rm -rf "$(distdir)" \
................................................................................
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = headers src test tools
EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \
	Makefile-static-MinGW

AUTOMAKE_OPTIONS = dist-zip foreign
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = rasterlite2.pc
MOSTLYCLEANFILES = rasterlite2_cov.info 
all: config.h
	$(MAKE) $(AM_MAKEFLAGS) all-recursive

.SUFFIXES:
am--refresh: Makefile
	@:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
	@for dep in $?; do \
	  case '$(am__configure_deps)' in \
	    *$$dep*) \
	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
		&& exit 0; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --foreign Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    echo ' $(SHELL) ./config.status'; \
	    $(SHELL) ./config.status;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
................................................................................
	$(am__post_remove_distdir)

dist-xz: distdir
	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
	$(am__post_remove_distdir)

dist-tarZ: distdir
	@echo WARNING: "Support for distribution archives compressed with" \
		       "legacy program 'compress' is deprecated." >&2
	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
	$(am__post_remove_distdir)

dist-shar: distdir
	@echo WARNING: "Support for shar distribution archives is" \
	               "deprecated." >&2
	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
	$(am__post_remove_distdir)
dist-zip: distdir
	-rm -f $(distdir).zip
	zip -rq $(distdir).zip $(distdir)
	$(am__post_remove_distdir)
................................................................................
	*.shar.gz*) \
	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
	*.zip*) \
	  unzip $(distdir).zip ;;\
	esac
	chmod -R a-w $(distdir)
	chmod u+w $(distdir)
	mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst
	chmod a-w $(distdir)
	test -d $(distdir)/_build || exit 0; \
	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
	  && am__cwd=`pwd` \
	  && $(am__cd) $(distdir)/_build/sub \
	  && ../../configure \
	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
	    $(DISTCHECK_CONFIGURE_FLAGS) \
	    --srcdir=../.. --prefix="$$dc_install_base" \
	  && $(MAKE) $(AM_MAKEFLAGS) \
	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
	  && $(MAKE) $(AM_MAKEFLAGS) check \
	  && $(MAKE) $(AM_MAKEFLAGS) install \
	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
................................................................................
	install-man install-pdf install-pdf-am install-pkgconfigDATA \
	install-ps install-ps-am install-strip installcheck \
	installcheck-am installdirs installdirs-am maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
	uninstall-am uninstall-pkgconfigDATA

.PRECIOUS: Makefile


coverage-init:
	lcov --directory src --capture --initial --output-file rasterlite2_cov.info

coverage::
	lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture
	lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info
	genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to aclocal.m4.

1
2
3
4
5
6
7
8
9
10
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
...
784
785
786
787
788
789
790
791




792
793
794
795
796
797
798
...
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
...
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
...
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
...
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
....
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
....
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
....
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
....
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
....
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
....
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
....
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
....
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
# generated automatically by aclocal 1.14.1 -*- Autoconf -*-

# Copyright (C) 1996-2013 Free Software Foundation, Inc.

# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................

_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])

AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR

# Copyright (C) 2002-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_AUTOMAKE_VERSION(VERSION)
# ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.14'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version.  Point them to the right macro.
m4_if([$1], [1.14.1], [],
      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])

# _AM_AUTOCONF_VERSION(VERSION)
# -----------------------------
# aclocal traces this macro to find the Autoconf version.
# This is a private macro too.  Using m4_define simplifies
................................................................................
m4_define([_AM_AUTOCONF_VERSION], [])

# AM_SET_CURRENT_AUTOMAKE_VERSION
# -------------------------------
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.14.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])

# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
# $ac_aux_dir to '$srcdir/foo'.  In other projects, it is set to
................................................................................
# configure, and could therefore not use this "fixed" $ac_aux_dir.
#
# Another solution, used here, is to always expand $ac_aux_dir to an
# absolute PATH.  The drawback is that using absolute paths prevent a
# configured tree to be moved without reconfiguration.

AC_DEFUN([AM_AUX_DIR_EXPAND],
[dnl Rely on autoconf to set up CDPATH properly.
AC_PREREQ([2.50])dnl
# expand $ac_aux_dir to an absolute path
am_aux_dir=`cd $ac_aux_dir && pwd`
])

# AM_CONDITIONAL                                            -*- Autoconf -*-

# Copyright (C) 1997-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
................................................................................
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
  AC_MSG_ERROR([[conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.]])
fi])])

# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.


# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
................................................................................
_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
AC_SUBST([am__nodep])dnl
_AM_SUBST_NOTMAKE([am__nodep])dnl
])

# Generate code to set up dependency tracking.              -*- Autoconf -*-

# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.


# _AM_OUTPUT_DEPENDENCY_COMMANDS
................................................................................
[AC_CONFIG_COMMANDS([depfiles],
     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
])

# Do all the work for Automake.                             -*- Autoconf -*-

# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This macro actually does too much.  Some checks are only needed if
# your package does certain things.  But this isn't really a big deal.
................................................................................
AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
AC_REQUIRE([AC_PROG_MKDIR_P])dnl
# For better backward compatibility.  To be removed once Automake 1.9.x
# dies out for good.  For more background, see:
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
# We need awk for the "check" target.  The system "awk" is bad on
# some platforms.
AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl
_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
			     [_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],,
................................................................................
If you want to complete the configuration process using your problematic
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.

END
    AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
  fi
fi])





dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])

................................................................................
      break ;;
    * )
      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
  esac
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_PROG_INSTALL_SH
# ------------------
# Define $install_sh.
AC_DEFUN([AM_PROG_INSTALL_SH],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
if test x"${install_sh}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
  *)
    install_sh="\${SHELL} $am_aux_dir/install-sh"
  esac
fi
AC_SUBST([install_sh])])

# Copyright (C) 2003-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# Check whether the underlying file-system supports filenames
# with a leading dot.  For instance MS-DOS doesn't.
................................................................................
fi
rmdir .tst 2>/dev/null
AC_SUBST([am__leading_dot])])

# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
# From Jim Meyering

# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MAINTAINER_MODE([DEFAULT-MODE])
# ----------------------------------
................................................................................
  MAINT=$MAINTAINER_MODE_TRUE
  AC_SUBST([MAINT])dnl
]
)

# Check to see how 'make' treats includes.	            -*- Autoconf -*-

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MAKE_INCLUDE()
# -----------------
................................................................................
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])

# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-

# Copyright (C) 1997-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------
................................................................................
fi
])

#  -*- Autoconf -*-
# Obsolete and "removed" macros, that must however still report explicit
# error messages when used, to smooth transition.
#
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

AC_DEFUN([AM_CONFIG_HEADER],
[AC_DIAGNOSE([obsolete],
................................................................................

AC_DEFUN([AM_C_PROTOTYPES],
         [AC_FATAL([automatic de-ANSI-fication support has been removed])])
AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES])

# Helper functions for option handling.                     -*- Autoconf -*-

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_MANGLE_OPTION(NAME)
# -----------------------
................................................................................

# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
# -------------------------------------------
# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])

# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_PROG_CC_C_O
# ---------------
................................................................................
   CC="$am_aux_dir/compile $CC"
fi
AC_LANG_POP([C])])

# For backward compatibility.
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_RUN_LOG(COMMAND)
# -------------------
................................................................................
   ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
   (exit $ac_status); }])

# Check to make sure that the build environment is sane.    -*- Autoconf -*-

# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_SANITY_CHECK
# ---------------
................................................................................
     # Hide warnings about reused PIDs.
     wait $am_sleep_pid 2>/dev/null
   fi
   AC_MSG_RESULT([done])])
rm -f conftest.file
])

# Copyright (C) 2009-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_SILENT_RULES([DEFAULT])
# --------------------------
................................................................................
AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
AM_BACKSLASH='\'
AC_SUBST([AM_BACKSLASH])dnl
_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
])

# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_PROG_INSTALL_STRIP
# ---------------------
................................................................................
dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
if test "$cross_compiling" != no; then
  AC_CHECK_TOOL([STRIP], [strip], :)
fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])

# Copyright (C) 2006-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
................................................................................
# AM_SUBST_NOTMAKE(VARIABLE)
# --------------------------
# Public sister of _AM_SUBST_NOTMAKE.
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])

# Check how to create a tarball.                            -*- Autoconf -*-

# Copyright (C) 2004-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_PROG_TAR(FORMAT)
# --------------------
|

|







 







|











|


|







 







|






|







 







|
<
|
|




|







 







|







 







|







 







|







 







|
|







 







|
>
>
>
>







 







|










|









|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







1
2
3
4
5
6
7
8
9
10
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
...
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
...
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
...
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
...
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
...
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
...
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
...
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
...
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
....
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
....
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
....
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
....
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
....
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
....
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
....
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
....
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# generated automatically by aclocal 1.15 -*- Autoconf -*-

# Copyright (C) 1996-2014 Free Software Foundation, Inc.

# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................

_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])

AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR

# Copyright (C) 2002-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_AUTOMAKE_VERSION(VERSION)
# ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.15'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version.  Point them to the right macro.
m4_if([$1], [1.15], [],
      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])

# _AM_AUTOCONF_VERSION(VERSION)
# -----------------------------
# aclocal traces this macro to find the Autoconf version.
# This is a private macro too.  Using m4_define simplifies
................................................................................
m4_define([_AM_AUTOCONF_VERSION], [])

# AM_SET_CURRENT_AUTOMAKE_VERSION
# -------------------------------
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.15])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])

# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
# $ac_aux_dir to '$srcdir/foo'.  In other projects, it is set to
................................................................................
# configure, and could therefore not use this "fixed" $ac_aux_dir.
#
# Another solution, used here, is to always expand $ac_aux_dir to an
# absolute PATH.  The drawback is that using absolute paths prevent a
# configured tree to be moved without reconfiguration.

AC_DEFUN([AM_AUX_DIR_EXPAND],
[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl

# Expand $ac_aux_dir to an absolute path.
am_aux_dir=`cd "$ac_aux_dir" && pwd`
])

# AM_CONDITIONAL                                            -*- Autoconf -*-

# Copyright (C) 1997-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
................................................................................
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
  AC_MSG_ERROR([[conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.]])
fi])])

# Copyright (C) 1999-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.


# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
................................................................................
_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
AC_SUBST([am__nodep])dnl
_AM_SUBST_NOTMAKE([am__nodep])dnl
])

# Generate code to set up dependency tracking.              -*- Autoconf -*-

# Copyright (C) 1999-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.


# _AM_OUTPUT_DEPENDENCY_COMMANDS
................................................................................
[AC_CONFIG_COMMANDS([depfiles],
     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
])

# Do all the work for Automake.                             -*- Autoconf -*-

# Copyright (C) 1996-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This macro actually does too much.  Some checks are only needed if
# your package does certain things.  But this isn't really a big deal.
................................................................................
AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
AC_REQUIRE([AC_PROG_MKDIR_P])dnl
# For better backward compatibility.  To be removed once Automake 1.9.x
# dies out for good.  For more background, see:
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
# We need awk for the "check" target (and possibly the TAP driver).  The
# system "awk" is bad on some platforms.
AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl
_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
			     [_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],,
................................................................................
If you want to complete the configuration process using your problematic
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.

END
    AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
  fi
fi
dnl The trailing newline in this macro's definition is deliberate, for
dnl backward compatibility and to allow trailing 'dnl'-style comments
dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841.
])

dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])

................................................................................
      break ;;
    * )
      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
  esac
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_PROG_INSTALL_SH
# ------------------
# Define $install_sh.
AC_DEFUN([AM_PROG_INSTALL_SH],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
if test x"${install_sh+set}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
  *)
    install_sh="\${SHELL} $am_aux_dir/install-sh"
  esac
fi
AC_SUBST([install_sh])])

# Copyright (C) 2003-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# Check whether the underlying file-system supports filenames
# with a leading dot.  For instance MS-DOS doesn't.
................................................................................
fi
rmdir .tst 2>/dev/null
AC_SUBST([am__leading_dot])])

# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
# From Jim Meyering

# Copyright (C) 1996-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MAINTAINER_MODE([DEFAULT-MODE])
# ----------------------------------
................................................................................
  MAINT=$MAINTAINER_MODE_TRUE
  AC_SUBST([MAINT])dnl
]
)

# Check to see how 'make' treats includes.	            -*- Autoconf -*-

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MAKE_INCLUDE()
# -----------------
................................................................................
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])

# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-

# Copyright (C) 1997-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------
................................................................................
fi
])

#  -*- Autoconf -*-
# Obsolete and "removed" macros, that must however still report explicit
# error messages when used, to smooth transition.
#
# Copyright (C) 1996-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

AC_DEFUN([AM_CONFIG_HEADER],
[AC_DIAGNOSE([obsolete],
................................................................................

AC_DEFUN([AM_C_PROTOTYPES],
         [AC_FATAL([automatic de-ANSI-fication support has been removed])])
AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES])

# Helper functions for option handling.                     -*- Autoconf -*-

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_MANGLE_OPTION(NAME)
# -----------------------
................................................................................

# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
# -------------------------------------------
# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])

# Copyright (C) 1999-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_PROG_CC_C_O
# ---------------
................................................................................
   CC="$am_aux_dir/compile $CC"
fi
AC_LANG_POP([C])])

# For backward compatibility.
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_RUN_LOG(COMMAND)
# -------------------
................................................................................
   ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
   (exit $ac_status); }])

# Check to make sure that the build environment is sane.    -*- Autoconf -*-

# Copyright (C) 1996-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_SANITY_CHECK
# ---------------
................................................................................
     # Hide warnings about reused PIDs.
     wait $am_sleep_pid 2>/dev/null
   fi
   AC_MSG_RESULT([done])])
rm -f conftest.file
])

# Copyright (C) 2009-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_SILENT_RULES([DEFAULT])
# --------------------------
................................................................................
AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
AM_BACKSLASH='\'
AC_SUBST([AM_BACKSLASH])dnl
_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
])

# Copyright (C) 2001-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# AM_PROG_INSTALL_STRIP
# ---------------------
................................................................................
dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
if test "$cross_compiling" != no; then
  AC_CHECK_TOOL([STRIP], [strip], :)
fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])

# Copyright (C) 2006-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
................................................................................
# AM_SUBST_NOTMAKE(VARIABLE)
# --------------------------
# Public sister of _AM_SUBST_NOTMAKE.
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])

# Check how to create a tarball.                            -*- Autoconf -*-

# Copyright (C) 2004-2014 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# _AM_PROG_TAR(FORMAT)
# --------------------

Changes to configure.

1
2
3
4
5
6
7
8
9
10
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
....
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
....
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
....
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
....
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
....
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
....
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
....
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
....
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
....
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
....
3097
3098
3099
3100
3101
3102
3103

3104
3105
3106
3107
3108
3109
3110
.....
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
.....
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-rc1.
#
# Report bugs to <a.furieri@lqt.it>.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
#
#
................................................................................
subdirs=
MFLAGS=
MAKEFLAGS=

# Identity of this package.
PACKAGE_NAME='librasterlite2'
PACKAGE_TARNAME='librasterlite2'
PACKAGE_VERSION='1.0.0-rc1'
PACKAGE_STRING='librasterlite2 1.0.0-rc1'
PACKAGE_BUGREPORT='a.furieri@lqt.it'
PACKAGE_URL=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
................................................................................
#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
\`configure' configures librasterlite2 1.0.0-rc1 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.
................................................................................
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of librasterlite2 1.0.0-rc1:";;
   esac
  cat <<\_ACEOF

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
    cd "$ac_pwd" || { ac_status=$?; break; }
  done
fi

test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
  cat <<\_ACEOF
librasterlite2 configure 1.0.0-rc1
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit
................................................................................
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_type
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by librasterlite2 $as_me 1.0.0-rc1, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ $0 $@

_ACEOF
exec 5>>config.log
{
................................................................................
ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.




am__api_version='1.14'

# Find a good install program.  We prefer a C program (faster),
# so one script is as good as another.  But avoid the broken or
# incompatible versions:
# SysV /etc/install, /usr/sbin/install
# SunOS /usr/etc/install
# IRIX /sbin/install
................................................................................
test "$program_suffix" != NONE &&
  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
# Double any \ or $.
# By default was `s,x,x', remove it if useless.
ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`

# expand $ac_aux_dir to an absolute path
am_aux_dir=`cd $ac_aux_dir && pwd`

if test x"${MISSING+set}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
  *)
    MISSING="\${SHELL} $am_aux_dir/missing" ;;
................................................................................
  am_missing_run="$MISSING "
else
  am_missing_run=
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
fi

if test x"${install_sh}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
  *)
    install_sh="\${SHELL} $am_aux_dir/install-sh"
  esac
fi
................................................................................
    CYGPATH_W=echo
  fi
fi


# Define the identity of the package.
 PACKAGE='librasterlite2'
 VERSION='1.0.0-rc1'


cat >>confdefs.h <<_ACEOF
#define PACKAGE "$PACKAGE"
_ACEOF


................................................................................

# For better backward compatibility.  To be removed once Automake 1.9.x
# dies out for good.  For more background, see:
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
mkdir_p='$(MKDIR_P)'

# We need awk for the "check" target.  The system "awk" is bad on
# some platforms.
# Always define AMTAR for backward compatibility.  Yes, it's still used
# in the wild :-(  We should find a proper way to deprecate it ...
AMTAR='$${TAR-tar}'


# We'll loop over all known methods to create a tar archive until one works.
_am_tools='gnutar  pax cpio none'
................................................................................
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.

END
    as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
  fi
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
    # Check whether --enable-maintainer-mode was given.
if test "${enable_maintainer_mode+set}" = set; then :
  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
else
................................................................................
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by librasterlite2 $as_me 1.0.0-rc1, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@
................................................................................

Report bugs to <a.furieri@lqt.it>."

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
librasterlite2 config.status 1.0.0-rc1
configured by $0, generated by GNU Autoconf 2.69,
  with options \\"\$ac_cs_config\\"

Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."



|







 







|
|







 







|







 







|







 







|







 







|







 







|







 







|
|







 







|







 







|







 







|
|







 







>







 







|







 







|







1
2
3
4
5
6
7
8
9
10
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
....
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
....
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
....
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
....
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
....
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
....
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
....
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
....
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
....
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
....
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
.....
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
.....
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-devel.
#
# Report bugs to <a.furieri@lqt.it>.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
#
#
................................................................................
subdirs=
MFLAGS=
MAKEFLAGS=

# Identity of this package.
PACKAGE_NAME='librasterlite2'
PACKAGE_TARNAME='librasterlite2'
PACKAGE_VERSION='1.0.0-devel'
PACKAGE_STRING='librasterlite2 1.0.0-devel'
PACKAGE_BUGREPORT='a.furieri@lqt.it'
PACKAGE_URL=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
................................................................................
#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
\`configure' configures librasterlite2 1.0.0-devel to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.
................................................................................
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of librasterlite2 1.0.0-devel:";;
   esac
  cat <<\_ACEOF

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
    cd "$ac_pwd" || { ac_status=$?; break; }
  done
fi

test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
  cat <<\_ACEOF
librasterlite2 configure 1.0.0-devel
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit
................................................................................
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_type
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by librasterlite2 $as_me 1.0.0-devel, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ $0 $@

_ACEOF
exec 5>>config.log
{
................................................................................
ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.




am__api_version='1.15'

# Find a good install program.  We prefer a C program (faster),
# so one script is as good as another.  But avoid the broken or
# incompatible versions:
# SysV /etc/install, /usr/sbin/install
# SunOS /usr/etc/install
# IRIX /sbin/install
................................................................................
test "$program_suffix" != NONE &&
  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
# Double any \ or $.
# By default was `s,x,x', remove it if useless.
ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`

# Expand $ac_aux_dir to an absolute path.
am_aux_dir=`cd "$ac_aux_dir" && pwd`

if test x"${MISSING+set}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
  *)
    MISSING="\${SHELL} $am_aux_dir/missing" ;;
................................................................................
  am_missing_run="$MISSING "
else
  am_missing_run=
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
fi

if test x"${install_sh+set}" != xset; then
  case $am_aux_dir in
  *\ * | *\	*)
    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
  *)
    install_sh="\${SHELL} $am_aux_dir/install-sh"
  esac
fi
................................................................................
    CYGPATH_W=echo
  fi
fi


# Define the identity of the package.
 PACKAGE='librasterlite2'
 VERSION='1.0.0-devel'


cat >>confdefs.h <<_ACEOF
#define PACKAGE "$PACKAGE"
_ACEOF


................................................................................

# For better backward compatibility.  To be removed once Automake 1.9.x
# dies out for good.  For more background, see:
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
mkdir_p='$(MKDIR_P)'

# We need awk for the "check" target (and possibly the TAP driver).  The
# system "awk" is bad on some platforms.
# Always define AMTAR for backward compatibility.  Yes, it's still used
# in the wild :-(  We should find a proper way to deprecate it ...
AMTAR='$${TAR-tar}'


# We'll loop over all known methods to create a tar archive until one works.
_am_tools='gnutar  pax cpio none'
................................................................................
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.

END
    as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
  fi
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
    # Check whether --enable-maintainer-mode was given.
if test "${enable_maintainer_mode+set}" = set; then :
  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
else
................................................................................
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by librasterlite2 $as_me 1.0.0-devel, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@
................................................................................

Report bugs to <a.furieri@lqt.it>."

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
librasterlite2 config.status 1.0.0-devel
configured by $0, generated by GNU Autoconf 2.69,
  with options \\"\$ac_cs_config\\"

Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."

Changes to configure.ac.

1
2
3
4
5
6
7
8
9
10
11
12
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(librasterlite2, 1.0.0-rc1, a.furieri@lqt.it)
AC_LANG(C)
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)




|







1
2
3
4
5
6
7
8
9
10
11
12
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(librasterlite2, 1.0.0-devel, a.furieri@lqt.it)
AC_LANG(C)
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)

Changes to headers/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18










19
20
21
22
23
24
25
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90


91
92
93
94
95
96
97
...
155
156
157
158
159
160
161

162
163
164
165
166
167
168
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
570
571
572
573
574
575
576


577
578
579
580
581
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = headers
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
	$(nobase_include_HEADERS) $(noinst_HEADERS)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)


mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags

DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu headers/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu headers/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-info install-info-am install-man \
	install-nobase_includeHEADERS install-pdf install-pdf-am \
	install-ps install-ps-am install-strip installcheck \
	installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
	uninstall-am uninstall-nobase_includeHEADERS




# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|













|
>
>
>
>
>
>
>
>
>
>







 







<
<







>
>







 







>







 







<







 







>
>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
332
333
334
335
336
337
338

339
340
341
342
343
344
345
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = headers


ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(nobase_include_HEADERS) \
	$(noinst_HEADERS) $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
am__DIST_COMMON = $(srcdir)/Makefile.in
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu headers/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu headers/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-info install-info-am install-man \
	install-nobase_includeHEADERS install-pdf install-pdf-am \
	install-ps install-ps-am install-strip installcheck \
	installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
	uninstall-am uninstall-nobase_includeHEADERS

.PRECIOUS: Makefile


# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to headers/rasterlite2/rasterlite2.h.

3465
3466
3467
3468
3469
3470
3471

























3472
3473
3474
3475
3476
3477
3478
3479
3480








3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492










3493
3494
3495
3496
3497
3498
3499
....
3673
3674
3675
3676
3677
3678
3679





3680
3681
3682
3683
3684
3685
3686
    RL2_DECLARE int rl2_load_raw_raster_into_dbms (sqlite3 * sqlite,
						   int max_threads,
						   rl2CoveragePtr cvg,
						   const char *sctn_name,
						   rl2RasterPtr rst,
						   int pyramidize);


























    RL2_DECLARE int
	rl2_get_raw_raster_data (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, unsigned int width,
				 unsigned int height, double minx, double miny,
				 double maxx, double maxy, double x_res,
				 double y_res, unsigned char **buffer,
				 int *buf_size, rl2PalettePtr * palette,
				 unsigned char out_pixel);









    RL2_DECLARE int
	rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
					 rl2CoveragePtr cvg,
					 sqlite3_int64 section_id,
					 unsigned int width,
					 unsigned int height, double minx,
					 double miny, double maxx, double maxy,
					 double x_res, double y_res,
					 unsigned char **buffer, int *buf_size,
					 rl2PalettePtr * palette,
					 unsigned char out_pixel);











    RL2_DECLARE int
	rl2_get_triple_band_raw_raster_data (sqlite3 * handle,
					     rl2CoveragePtr cvg,
					     unsigned int width,
					     unsigned int height,
					     double minx, double miny,
					     double maxx, double maxy,
................................................................................
    RL2_DECLARE int
	rl2_compare_palettes (rl2PalettePtr palette_1, rl2PalettePtr palette_2);

    RL2_DECLARE int
	rl2_check_dbms_palette (sqlite3 * handle, rl2CoveragePtr cvg,
				rl2TiffOriginPtr tiff);






    RL2_DECLARE int
	rl2_serialize_dbms_pixel (rl2PixelPtr pixel, unsigned char **blob,
				  int *blob_size);

    RL2_DECLARE int
	rl2_is_valid_dbms_pixel (const unsigned char *blob, int blob_size,
				 unsigned char sample_type,







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>







3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
....
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
    RL2_DECLARE int rl2_load_raw_raster_into_dbms (sqlite3 * sqlite,
						   int max_threads,
						   rl2CoveragePtr cvg,
						   const char *sctn_name,
						   rl2RasterPtr rst,
						   int pyramidize);

    RL2_DECLARE int rl2_load_raw_tiles_into_dbms (sqlite3 * sqlite,
						  rl2CoveragePtr cvg,
						  const char *sctn_name,
						  unsigned int sctn_width,
						  unsigned int sctn_height,
						  int sctn_srid,
						  double sctn_minx,
						  double sctn_miny,
						  double sctn_maxx,
						  double sctn_maxy,
						  int (*getTile) (void *data,
								  double
								  tile_minx,
								  double
								  tile_miny,
								  double
								  tile_maxx,
								  double
								  tile_maxy,
								  unsigned char
								  *bufpix,
								  rl2PalettePtr
								  * palette),
						  void *data, int pyramidize);

    RL2_DECLARE int
	rl2_get_raw_raster_data (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, unsigned int width,
				 unsigned int height, double minx, double miny,
				 double maxx, double maxy, double x_res,
				 double y_res, unsigned char **buffer,
				 int *buf_size, rl2PalettePtr * palette,
				 unsigned char out_pixel);

    RL2_DECLARE int
	rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, unsigned int width,
				 unsigned int height, double minx, double miny,
				 double maxx, double maxy, double x_res,
				 double y_res, unsigned char **mask,
				 int *mask_size);

    RL2_DECLARE int
	rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
					 rl2CoveragePtr cvg,
					 sqlite3_int64 section_id,
					 unsigned int width,
					 unsigned int height, double minx,
					 double miny, double maxx, double maxy,
					 double x_res, double y_res,
					 unsigned char **buffer, int *buf_size,
					 rl2PalettePtr * palette,
					 unsigned char out_pixel);

    RL2_DECLARE int
	rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads,
					 rl2CoveragePtr cvg,
					 sqlite3_int64 section_id,
					 unsigned int width,
					 unsigned int height, double minx,
					 double miny, double maxx, double maxy,
					 double x_res, double y_res,
					 unsigned char **mask, int *mask_size);

    RL2_DECLARE int
	rl2_get_triple_band_raw_raster_data (sqlite3 * handle,
					     rl2CoveragePtr cvg,
					     unsigned int width,
					     unsigned int height,
					     double minx, double miny,
					     double maxx, double maxy,
................................................................................
    RL2_DECLARE int
	rl2_compare_palettes (rl2PalettePtr palette_1, rl2PalettePtr palette_2);

    RL2_DECLARE int
	rl2_check_dbms_palette (sqlite3 * handle, rl2CoveragePtr cvg,
				rl2TiffOriginPtr tiff);

    RL2_DECLARE int
	rl2_install_dbms_palette_from_tiff (sqlite3 * handle,
					    rl2CoveragePtr cvg,
					    rl2TiffOriginPtr tiff);

    RL2_DECLARE int
	rl2_serialize_dbms_pixel (rl2PixelPtr pixel, unsigned char **blob,
				  int *blob_size);

    RL2_DECLARE int
	rl2_is_valid_dbms_pixel (const unsigned char *blob, int blob_size,
				 unsigned char sample_type,

Changes to headers/rasterlite2/rl2graphics.h.

1339
1340
1341
1342
1343
1344
1345





















1346
1347
1348
1349
1350
1351
1352
    RL2_DECLARE int rl2_graph_draw_rescaled_bitmap (rl2GraphicsContextPtr
						    context,
						    rl2GraphicsBitmapPtr bitmap,
						    double scale_x,
						    double scale_y, double x,
						    double y);






















/**
 Creates an RGB Array corresponding to the current Canvass

 \param context the pointer to a valid Graphics Context (aka Canvass).

 \return the pointer to the RGB Array: NULL on failure.
 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
    RL2_DECLARE int rl2_graph_draw_rescaled_bitmap (rl2GraphicsContextPtr
						    context,
						    rl2GraphicsBitmapPtr bitmap,
						    double scale_x,
						    double scale_y, double x,
						    double y);

/**
 Rescales a raw pixbuf (RGB or GRAYSCALE)

 \param inbuf pointer to the input pixbuf.
 \param inwidth the width (measured in pixels) of the input pixbuf.
 \param inheight the height (measured in pixels) of the input pixbuf.
 \param pixtype either RL2_PIXEL_RGB or RL2_PIXEL_GRAYSCALE.
 \param outbuf pointer to the input pixbuf.
 \param outwidth the width (measured in pixels) of the output pixbuf.
 \param outheight the height (measured in pixels) of the output pixbuf.

 \return 0 (false) on error, any other value on success.
 */
    RL2_DECLARE int rl2_rescale_pixbuf (const unsigned char *inbuf,
					unsigned int inwidth,
					unsigned int inheight,
					unsigned char pixtype,
					const unsigned char *outbuf,
					unsigned int outwidth,
					unsigned int outheight);

/**
 Creates an RGB Array corresponding to the current Canvass

 \param context the pointer to a valid Graphics Context (aka Canvass).

 \return the pointer to the RGB Array: NULL on failure.
 

Changes to headers/rasterlite2/sqlite.h.

47
48
49
50
51
52
53
54



55



#ifdef LOADABLE_EXTENSION	/* loadable-extension only */
#include <sqlite3ext.h>
extern const sqlite3_api_routines *sqlite3_api;
#else /* ordinary lib */
#include <sqlite3.h>
#endif




#endif










>
>
>

>
>
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#ifdef LOADABLE_EXTENSION	/* loadable-extension only */
#include <sqlite3ext.h>
extern const sqlite3_api_routines *sqlite3_api;
#else /* ordinary lib */
#include <sqlite3.h>
#endif

#ifndef SQLITE_DETERMINISTIC
/* probably SQLite < 3.8.3 - attempting to fix */
#define SQLITE_DETERMINISTIC	SQLITE_UTF8
#endif

#endif

Changes to headers/rasterlite2_private.h.

1097
1098
1099
1100
1101
1102
1103




1104
1105
1106
1107
1108
1109
1110
1111




1112
1113
1114
1115
1116
1117
1118
....
1202
1203
1204
1205
1206
1207
1208





















1209
1210
1211
1212
1213
1214
1215
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
....
1278
1279
1280
1281
1282
1283
1284
1285

1286
1287
1288
1289
1290
1291
1292
1293
....
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
....
1364
1365
1366
1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
1379
....
1389
1390
1391
1392
1393
1394
1395



1396
1397
1398
1399
1400
1401
1402
....
1447
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
....
1497
1498
1499
1500
1501
1502
1503
1504

1505

1506
1507
1508

1509
1510

1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547

1548
1549
1550
1551
1552
1553
1554
1555
....
1574
1575
1576
1577
1578
1579
1580
1581

1582
1583
1584
1585
1586
1587
1588
....
1614
1615
1616
1617
1618
1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
....
1658
1659
1660
1661
1662
1663
1664
1665

1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678

1679
1680
1681

1682
1683
1684
1685
1686
1687
1688
1689
1690
1691

1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704

1705

1706
1707
1708
1709
1710
1711
1712
1713
1714
1715

1716
1717
1718
1719
1720
1721
1722
1723
....
1742
1743
1744
1745
1746
1747
1748
1749

1750
1751
1752
1753
1754
1755
1756
....
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
....
1876
1877
1878
1879
1880
1881
1882








1883
1884
1885
1886
1887
1888

1889
1890
1891
1892
1893
1894
1895
1896
1897


1898
1899
1900
1901
1902
1903
1904
....
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925









1926
1927
1928
1929
1930
1931
1932
....
1950
1951
1952
1953
1954
1955
1956
1957

1958
1959
1960
1961
1962
1963
1964
1965
1966

















1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980

1981
1982
1983

1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997

1998
1999
2000
2001
2002
2003
2004
....
2012
2013
2014
2015
2016
2017
2018

2019
2020
2021

2022
2023
2024
2025
2026
2027
2028
2029
....
2033
2034
2035
2036
2037
2038
2039




2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
....
2053
2054
2055
2056
2057
2058
2059















2060
2061
2062
2063
2064
2065
    } rl2Point;
    typedef rl2Point *rl2PointPtr;

    typedef struct rl2_linestring
    {
	int points;
	double *coords;




	struct rl2_linestring *next;
    } rl2Linestring;
    typedef rl2Linestring *rl2LinestringPtr;

    typedef struct rl2_ring
    {
	int points;
	double *coords;




	struct rl2_ring *next;
    } rl2Ring;
    typedef rl2Ring *rl2RingPtr;

    typedef struct rl2_polygon
    {
	rl2RingPtr exterior;
................................................................................
	rl2PrivRasterStatisticsPtr stats;
	rl2PrivRasterPtr raster;
	rl2PrivPalettePtr palette;
	int retcode;
    } rl2AuxDecoder;
    typedef rl2AuxDecoder *rl2AuxDecoderPtr;






















    typedef struct rl2_aux_shadower
    {
	void *opaque_thread_id;
	unsigned int width;
	unsigned int height;
	double relief_factor;
	double scale_factor;
................................................................................
				    unsigned int *height,
				    unsigned char sample_type,
				    unsigned char pixel_type,
				    unsigned char num_bands,
				    unsigned char **pixels, int *pixels_sz);

    RL2_PRIVATE int
	rl2_data_to_png (const unsigned char *pixels, const unsigned char *mask,
			 double opacity, rl2PalettePtr plt,
			 unsigned int width, unsigned int height,
			 unsigned char sample_type, unsigned char pixel_type,
			 unsigned char num_bands, unsigned char **compr_data,
			 int *compressed_size);

    RL2_PRIVATE int
	rl2_decode_png (const unsigned char *png, int png_sz,
			unsigned int *width, unsigned int *height,
			unsigned char *sample_type, unsigned char *pixel_type,
			unsigned char *num_bands, unsigned char **pixels,
			int *pixels_sz, unsigned char **mask, int *mask_sz,
................................................................................
			    unsigned char pixel_type, unsigned char num_bands,
			    unsigned char **compr_data, int *compressed_size);

    RL2_PRIVATE int
	rl2_decode_charls (const unsigned char *charls, int charls_sz,
			   unsigned int *width, unsigned int *height,
			   unsigned char *sample_type,
			   unsigned char *pixel_type, unsigned char *num_bands,

			   unsigned char **pixels, int *pixels_sz);

    RL2_PRIVATE int
	rl2_data_to_gif (const unsigned char *pixels,
			 rl2PalettePtr plt, unsigned int width,
			 unsigned int height, unsigned char sample_type,
			 unsigned char pixel_type, unsigned char **compr_data,
			 int *compressed_size);
................................................................................
					 unsigned int height,
					 unsigned char sample_type,
					 unsigned char num_bands,
					 unsigned char auto_ndvi,
					 unsigned char red_band_index,
					 unsigned char nir_band_index,
					 double x_res, double y_res,
					 double minx, double miny, double maxx,
					 double maxy, int level, int scale,
					 rl2PalettePtr palette,
					 rl2PixelPtr no_data,
					 rl2RasterSymbolizerPtr style,
					 rl2RasterStatisticsPtr stats);

    RL2_PRIVATE int rl2_load_dbms_tiles_section (sqlite3 * handle,
						 int max_threads,
						 sqlite3_int64 section_id,
................................................................................
						 unsigned int height,
						 unsigned char sample_type,
						 unsigned char num_bands,
						 unsigned char auto_ndvi,
						 unsigned char red_band_index,
						 unsigned char nir_band_index,
						 double x_res, double y_res,
						 double minx, double maxy,

						 int scale,
						 rl2PalettePtr palette,
						 rl2PixelPtr no_data);

    RL2_PRIVATE void
	compute_aggregate_sq_diff (rl2RasterStatisticsPtr aggreg_stats);

    RL2_PRIVATE int get_coverage_sample_bands (sqlite3 * sqlite,
................................................................................
				       unsigned char *num_bands,
				       unsigned char *compression);

    RL2_PRIVATE rl2PixelPtr default_nodata (unsigned char sample,
					    unsigned char pixel,
					    unsigned char num_bands);




    RL2_PRIVATE WmsRetryListPtr alloc_retry_list ();

    RL2_PRIVATE void free_retry_list (WmsRetryListPtr lst);

    RL2_PRIVATE void add_retry (WmsRetryListPtr lst, double minx, double miny,
				double maxx, double maxy);

................................................................................
					  int scale, double x_res,
					  double y_res);

    RL2_PRIVATE int rl2_find_best_resolution_level (sqlite3 * handle,
						    const char *coverage,
						    int by_section,
						    sqlite3_int64 section_id,
						    double x_res, double y_res,

						    int *level_id, int *scale,
						    int *real_scale,
						    double *xx_res,
						    double *yy_res);

    RL2_PRIVATE unsigned char get_palette_format (rl2PrivPalettePtr plt);

................................................................................
						     unsigned char format,
						     int quality,
						     unsigned char **image,
						     int *image_sz);

    RL2_PRIVATE int get_payload_from_palette_transparent (unsigned int width,
							  unsigned int height,
							  unsigned char *pixels,

							  rl2PalettePtr palette,

							  unsigned char format,
							  int quality,
							  unsigned char **image,

							  int *image_sz,
							  unsigned char bg_red,

							  unsigned char
							  bg_green,
							  unsigned char
							  bg_blue,
							  double opacity);

    RL2_PRIVATE int get_payload_from_grayscale_opaque (unsigned int width,
						       unsigned int height,
						       sqlite3 * handle,
						       double minx, double miny,

						       double maxx, double maxy,
						       int srid,
						       unsigned char *pixels,
						       unsigned char format,
						       int quality,
						       unsigned char **image,
						       int *image_sz);

    RL2_PRIVATE int get_payload_from_grayscale_transparent (unsigned int
							    width,
							    unsigned int
							    height,
							    unsigned char
							    *pixels,
							    unsigned char

							    format, int quality,
							    unsigned char
							    **image,
							    int *image_sz,
							    unsigned char
							    bg_gray,
							    double opacity);

    RL2_PRIVATE int get_payload_from_rgb_opaque (unsigned int width,
						 unsigned int height,
						 sqlite3 * handle, double minx,
						 double miny, double maxx,

						 double maxy, int srid,
						 unsigned char *pixels,
						 unsigned char format,
						 int quality,
						 unsigned char **image,
						 int *image_sz);

    RL2_PRIVATE int get_payload_from_rgb_transparent (unsigned int width,
................................................................................
    RL2_PRIVATE int get_rgba_from_monochrome_opaque (unsigned int width,
						     unsigned int height,
						     unsigned char *pixels,
						     unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_monochrome_transparent (unsigned int width,
							  unsigned int height,
							  unsigned char *pixels,

							  unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_palette_mask (unsigned int base_width,
						unsigned int base_height,
						unsigned char *pixels,
						unsigned char *mask,
						rl2PalettePtr palette,
................................................................................
    RL2_PRIVATE int get_rgba_from_grayscale_opaque (unsigned int width,
						    unsigned int height,
						    unsigned char *pixels,
						    unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_grayscale_transparent (unsigned int width,
							 unsigned int height,
							 unsigned char *pixels,

							 unsigned char *rgba,
							 unsigned char bg_gray);

    RL2_PRIVATE int get_rgba_from_rgb_mask (unsigned int width,
					    unsigned int height,
					    unsigned char *pixels,
					    unsigned char *mask,
................................................................................
						  unsigned char *mask,
						  rl2PrivPixelPtr no_made,
						  unsigned char *rgba);

    RL2_PRIVATE int get_payload_from_gray_rgba_opaque (unsigned int width,
						       unsigned int height,
						       sqlite3 * handle,
						       double minx, double miny,

						       double maxx, double maxy,
						       int srid,
						       unsigned char *rgb,
						       unsigned char format,
						       int quality,
						       unsigned char **image,
						       int *image_sz);

    RL2_PRIVATE int get_payload_from_gray_rgba_transparent (unsigned int
							    width,
							    unsigned int
							    height,
							    unsigned char *rgb,

							    unsigned char
							    *alpha,
							    unsigned char

							    format, int quality,
							    unsigned char
							    **image,
							    int *image_sz,
							    double opacity);

    RL2_PRIVATE int get_payload_from_rgb_rgba_opaque (unsigned int width,
						      unsigned int height,
						      sqlite3 * handle,
						      double minx, double miny,

						      double maxx, double maxy,
						      int srid,
						      unsigned char *rgb,
						      unsigned char format,
						      int quality,
						      unsigned char **image,
						      int *image_sz);

    RL2_PRIVATE int get_payload_from_rgb_rgba_transparent (unsigned int width,
							   unsigned int
							   height,
							   unsigned char *rgb,
							   unsigned char *alpha,

							   unsigned char format,

							   int quality,
							   unsigned char
							   **image,
							   int *image_sz,
							   double opacity,
							   int
							   half_transparent);

    RL2_PRIVATE int build_rgb_alpha (unsigned int width,
				     unsigned int height, unsigned char *rgba,

				     unsigned char **rgb, unsigned char **alpha,
				     unsigned char bg_red,
				     unsigned char bg_green,
				     unsigned char bg_blue);

    RL2_PRIVATE int get_rgba_from_multiband8 (unsigned int width,
					      unsigned int height,
					      unsigned char red_band,
................................................................................
    RL2_PRIVATE int parse_worldfile (FILE * in, double *px, double *py,
				     double *pres_x, double *pres_y);

    RL2_PRIVATE rl2CoverageStylePtr coverage_style_from_xml (char *name,
							     unsigned char
							     *xml);

    RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char *name,

								    unsigned
								    char *xml);

    RL2_PRIVATE rl2GroupStylePtr group_style_from_sld_xml (char *name,
							   unsigned char *xml);

    RL2_PRIVATE rl2PrivCoverageStylePtr
................................................................................

    RL2_PRIVATE void rl2_destroy_point_symbolizer (rl2PrivPointSymbolizerPtr
						   symbolizer);

    RL2_PRIVATE void rl2_destroy_line_symbolizer (rl2PrivLineSymbolizerPtr
						  symbolizer);

    RL2_PRIVATE void rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr
						     symbolizer);

    RL2_PRIVATE void rl2_destroy_text_symbolizer (rl2PrivTextSymbolizerPtr
						  symbolizer);

    RL2_PRIVATE rl2PrivRuleSingleArgPtr
	rl2_create_default_rule_single_arg (void);

................................................................................
					 unsigned char nir_band_index,
					 double x_res, double y_res,
					 double minx, double maxy,
					 double tile_minx, double tile_maxy,
					 rl2PixelPtr no_data,
					 rl2RasterSymbolizerPtr style,
					 rl2RasterStatisticsPtr stats);









    RL2_PRIVATE unsigned char *rl2_copy_endian_raw_pixels (const unsigned char
							   *pixels,
							   int pixels_sz,
							   unsigned int width,
							   unsigned int height,

							   unsigned char
							   sample_type,
							   unsigned char
							   num_bands,
							   int big_endian);

    RL2_PRIVATE int rl2_build_shaded_relief_mask (sqlite3 * handle,
						  int max_threads,
						  rl2CoveragePtr cvg,


						  double relief_factor,
						  double scale_factor,
						  unsigned int width,
						  unsigned int height,
						  double minx, double miny,
						  double maxx, double maxy,
						  double x_res, double y_res,
................................................................................
					const char *title,
					const char *abstract);

    RL2_PRIVATE int rl2_test_layer_group (sqlite3 * handle,
					  const char *group_name);

    RL2_PRIVATE int rl2_rgba_raster_data (sqlite3 * handle,
					  const char *coverage_name, void *ctx,
					  int level, double minx, double miny,
					  double maxx, double maxy,
					  rl2PalettePtr palette,
					  rl2PixelPtr no_data);

    RL2_PRIVATE int rl2_aux_render_image (struct aux_renderer *aux,
					  unsigned char **ximage,
					  int *ximage_size);










    RL2_PRIVATE void rl2_aux_group_renderer (struct aux_group_renderer *auxgrp);

    RL2_PRIVATE double rl2_get_shaded_relief_scale_factor (sqlite3 * handle,
							   const char
							   *coverage);

................................................................................
						    rl2CoveragePtr cvg,
						    int by_section,
						    sqlite3_int64 section_id,
						    unsigned int width,
						    unsigned int height,
						    double minx, double miny,
						    double maxx, double maxy,
						    double x_res, double y_res,

						    unsigned char **buffer,
						    int *buf_size,
						    rl2PalettePtr * palette,
						    unsigned char out_pixel,
						    rl2PixelPtr bgcolor,
						    rl2RasterSymbolizerPtr
						    style,
						    rl2RasterStatisticsPtr
						    stats);


















    RL2_PRIVATE char *rl2_double_quoted_sql (const char *value);

    RL2_PRIVATE int rl2_parse_point (sqlite3 * sqlite,
				     const unsigned char *blob, int blob_sz,
				     double *x, double *y);

    RL2_PRIVATE int rl2_parse_point_generic (sqlite3 * sqlite,
					     const unsigned char *blob,
					     int blob_sz, double *x, double *y);

    RL2_PRIVATE int rl2_parse_bbox_srid (sqlite3 * sqlite,
					 const unsigned char *blob, int blob_sz,
					 int *srid, double *minx, double *miny,

					 double *maxx, double *maxy);

    RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite, const unsigned char *blob,

				    int blob_sz, double *minx, double *miny,
				    double *maxx, double *maxy);

    RL2_PRIVATE int rl2_build_bbox (sqlite3 * sqlite, int srid, double minx,
				    double miny, double maxx, double maxy,
				    unsigned char **blob, int *blob_sz);

    RL2_PRIVATE int rl2_delta_encode (unsigned char *buffer, int size,
				      int distance);

    RL2_PRIVATE int rl2_delta_decode (unsigned char *buffer, int size,
				      int distance);

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char *name,

							       sqlite3_int64
							       value);

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_double (const char
								  *name,
								  double value);

................................................................................

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_null (const char
								*name);

    RL2_PRIVATE void rl2_destroy_variant_value (rl2PrivVariantValuePtr value);

    RL2_PRIVATE void rl2_draw_vector_feature (void *ctx, sqlite3 * handle,

					      rl2VectorSymbolizerPtr symbolizer,
					      int height, double minx,
					      double miny, double x_res,

					      double y_res,
					      rl2GeometryPtr geom,
					      rl2VariantArrayPtr variant);

    RL2_PRIVATE rl2GeometryPtr
	rl2_geometry_from_blob (const unsigned char *blob, int blob_sz);

    RL2_PRIVATE rl2GeometryPtr
................................................................................

    RL2_PRIVATE int rl2_serialize_linestring (rl2LinestringPtr line,
					      unsigned char **blob,
					      int *blob_sz);

    RL2_PRIVATE int rl2_serialize_ring (rl2RingPtr ring, unsigned char **blob,
					int *blob_sz);





    RL2_PRIVATE double rl2_compute_curve_length (rl2GeometryPtr geom);

    RL2_PRIVATE rl2GeometryPtr
	rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom, double from,
			     double to);

    RL2_PRIVATE rl2GeometryPtr rl2_clone_curve (rl2GeometryPtr in);

    RL2_PRIVATE rl2GeometryPtr rl2_clone_linestring (rl2LinestringPtr in);

    RL2_PRIVATE rl2GeometryPtr
	rl2_build_circle (double x, double y, double radius);
................................................................................

    RL2_PRIVATE int rl2_load_font_into_dbms (sqlite3 * handle,
					     unsigned char *blob, int blob_sz);

    RL2_PRIVATE int rl2_get_font_from_dbms (sqlite3 * handle,
					    const char *facename,
					    unsigned char **font, int *font_sz);
















#ifdef __cplusplus
}
#endif

#endif				/* _RASTERLITE2_PRIVATE_H */







>
>
>
>








>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|
|







 







|
>
|







 







|
|
|







 







|
>
|







 







>
>
>







 







|
>







 







|
>
|
>
|
|
|
>

|
>









|
>
|
|













>
|









|
|
>
|







 







|
>







 







|
>







 







|
>
|
|










|
>



>
|








|
>
|
|










|
>
|
>










>
|







 







|
>







 







|
|







 







>
>
>
>
>
>
>
>





|
>









>
>







 







|
|
|
|





>
>
>
>
>
>
>
>
>







 







|
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












|
|
>
|

|
>
|
|











|
>







 







>
|
|
|
>
|







 







>
>
>
>




|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
....
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
....
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
....
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
....
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
....
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
....
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
....
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
....
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
....
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
....
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
....
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
....
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
....
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
....
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
....
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
....
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
....
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
....
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
....
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
    } rl2Point;
    typedef rl2Point *rl2PointPtr;

    typedef struct rl2_linestring
    {
	int points;
	double *coords;
	double minx;
	double miny;
	double maxx;
	double maxy;
	struct rl2_linestring *next;
    } rl2Linestring;
    typedef rl2Linestring *rl2LinestringPtr;

    typedef struct rl2_ring
    {
	int points;
	double *coords;
	double minx;
	double miny;
	double maxx;
	double maxy;
	struct rl2_ring *next;
    } rl2Ring;
    typedef rl2Ring *rl2RingPtr;

    typedef struct rl2_polygon
    {
	rl2RingPtr exterior;
................................................................................
	rl2PrivRasterStatisticsPtr stats;
	rl2PrivRasterPtr raster;
	rl2PrivPalettePtr palette;
	int retcode;
    } rl2AuxDecoder;
    typedef rl2AuxDecoder *rl2AuxDecoderPtr;

    typedef struct rl2_aux_mask_decoder
    {
	void *opaque_thread_id;
	sqlite3_int64 tile_id;
	unsigned char *blob_odd;
	int blob_odd_sz;
	unsigned char *maskbuf;
	unsigned int width;
	unsigned int height;
	double x_res;
	double y_res;
	int scale;
	double minx;
	double maxy;
	double tile_minx;
	double tile_maxy;
	rl2PrivRasterPtr raster;
	int retcode;
    } rl2AuxMaskDecoder;
    typedef rl2AuxMaskDecoder *rl2AuxMaskDecoderPtr;

    typedef struct rl2_aux_shadower
    {
	void *opaque_thread_id;
	unsigned int width;
	unsigned int height;
	double relief_factor;
	double scale_factor;
................................................................................
				    unsigned int *height,
				    unsigned char sample_type,
				    unsigned char pixel_type,
				    unsigned char num_bands,
				    unsigned char **pixels, int *pixels_sz);

    RL2_PRIVATE int
	rl2_data_to_png (const unsigned char *pixels,
			 const unsigned char *mask, double opacity,
			 rl2PalettePtr plt, unsigned int width,
			 unsigned int height, unsigned char sample_type,
			 unsigned char pixel_type, unsigned char num_bands,
			 unsigned char **compr_data, int *compressed_size);

    RL2_PRIVATE int
	rl2_decode_png (const unsigned char *png, int png_sz,
			unsigned int *width, unsigned int *height,
			unsigned char *sample_type, unsigned char *pixel_type,
			unsigned char *num_bands, unsigned char **pixels,
			int *pixels_sz, unsigned char **mask, int *mask_sz,
................................................................................
			    unsigned char pixel_type, unsigned char num_bands,
			    unsigned char **compr_data, int *compressed_size);

    RL2_PRIVATE int
	rl2_decode_charls (const unsigned char *charls, int charls_sz,
			   unsigned int *width, unsigned int *height,
			   unsigned char *sample_type,
			   unsigned char *pixel_type,
			   unsigned char *num_bands, unsigned char **pixels,
			   int *pixels_sz);

    RL2_PRIVATE int
	rl2_data_to_gif (const unsigned char *pixels,
			 rl2PalettePtr plt, unsigned int width,
			 unsigned int height, unsigned char sample_type,
			 unsigned char pixel_type, unsigned char **compr_data,
			 int *compressed_size);
................................................................................
					 unsigned int height,
					 unsigned char sample_type,
					 unsigned char num_bands,
					 unsigned char auto_ndvi,
					 unsigned char red_band_index,
					 unsigned char nir_band_index,
					 double x_res, double y_res,
					 double minx, double miny,
					 double maxx, double maxy, int level,
					 int scale, rl2PalettePtr palette,
					 rl2PixelPtr no_data,
					 rl2RasterSymbolizerPtr style,
					 rl2RasterStatisticsPtr stats);

    RL2_PRIVATE int rl2_load_dbms_tiles_section (sqlite3 * handle,
						 int max_threads,
						 sqlite3_int64 section_id,
................................................................................
						 unsigned int height,
						 unsigned char sample_type,
						 unsigned char num_bands,
						 unsigned char auto_ndvi,
						 unsigned char red_band_index,
						 unsigned char nir_band_index,
						 double x_res, double y_res,
						 double minx, double miny,
						 double maxx, double maxy,
						 int level, int scale,
						 rl2PalettePtr palette,
						 rl2PixelPtr no_data);

    RL2_PRIVATE void
	compute_aggregate_sq_diff (rl2RasterStatisticsPtr aggreg_stats);

    RL2_PRIVATE int get_coverage_sample_bands (sqlite3 * sqlite,
................................................................................
				       unsigned char *num_bands,
				       unsigned char *compression);

    RL2_PRIVATE rl2PixelPtr default_nodata (unsigned char sample,
					    unsigned char pixel,
					    unsigned char num_bands);

    RL2_PRIVATE int
	do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg);

    RL2_PRIVATE WmsRetryListPtr alloc_retry_list ();

    RL2_PRIVATE void free_retry_list (WmsRetryListPtr lst);

    RL2_PRIVATE void add_retry (WmsRetryListPtr lst, double minx, double miny,
				double maxx, double maxy);

................................................................................
					  int scale, double x_res,
					  double y_res);

    RL2_PRIVATE int rl2_find_best_resolution_level (sqlite3 * handle,
						    const char *coverage,
						    int by_section,
						    sqlite3_int64 section_id,
						    double x_res,
						    double y_res,
						    int *level_id, int *scale,
						    int *real_scale,
						    double *xx_res,
						    double *yy_res);

    RL2_PRIVATE unsigned char get_palette_format (rl2PrivPalettePtr plt);

................................................................................
						     unsigned char format,
						     int quality,
						     unsigned char **image,
						     int *image_sz);

    RL2_PRIVATE int get_payload_from_palette_transparent (unsigned int width,
							  unsigned int height,
							  unsigned char
							  *pixels,
							  rl2PalettePtr
							  palette,
							  unsigned char
							  format, int quality,
							  unsigned char
							  **image,
							  int *image_sz,
							  unsigned char
							  bg_red,
							  unsigned char
							  bg_green,
							  unsigned char
							  bg_blue,
							  double opacity);

    RL2_PRIVATE int get_payload_from_grayscale_opaque (unsigned int width,
						       unsigned int height,
						       sqlite3 * handle,
						       double minx,
						       double miny,
						       double maxx,
						       double maxy, int srid,
						       unsigned char *pixels,
						       unsigned char format,
						       int quality,
						       unsigned char **image,
						       int *image_sz);

    RL2_PRIVATE int get_payload_from_grayscale_transparent (unsigned int
							    width,
							    unsigned int
							    height,
							    unsigned char
							    *pixels,
							    unsigned char
							    format,
							    int quality,
							    unsigned char
							    **image,
							    int *image_sz,
							    unsigned char
							    bg_gray,
							    double opacity);

    RL2_PRIVATE int get_payload_from_rgb_opaque (unsigned int width,
						 unsigned int height,
						 sqlite3 * handle,
						 double minx, double miny,
						 double maxx, double maxy,
						 int srid,
						 unsigned char *pixels,
						 unsigned char format,
						 int quality,
						 unsigned char **image,
						 int *image_sz);

    RL2_PRIVATE int get_payload_from_rgb_transparent (unsigned int width,
................................................................................
    RL2_PRIVATE int get_rgba_from_monochrome_opaque (unsigned int width,
						     unsigned int height,
						     unsigned char *pixels,
						     unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_monochrome_transparent (unsigned int width,
							  unsigned int height,
							  unsigned char
							  *pixels,
							  unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_palette_mask (unsigned int base_width,
						unsigned int base_height,
						unsigned char *pixels,
						unsigned char *mask,
						rl2PalettePtr palette,
................................................................................
    RL2_PRIVATE int get_rgba_from_grayscale_opaque (unsigned int width,
						    unsigned int height,
						    unsigned char *pixels,
						    unsigned char *rgba);

    RL2_PRIVATE int get_rgba_from_grayscale_transparent (unsigned int width,
							 unsigned int height,
							 unsigned char
							 *pixels,
							 unsigned char *rgba,
							 unsigned char bg_gray);

    RL2_PRIVATE int get_rgba_from_rgb_mask (unsigned int width,
					    unsigned int height,
					    unsigned char *pixels,
					    unsigned char *mask,
................................................................................
						  unsigned char *mask,
						  rl2PrivPixelPtr no_made,
						  unsigned char *rgba);

    RL2_PRIVATE int get_payload_from_gray_rgba_opaque (unsigned int width,
						       unsigned int height,
						       sqlite3 * handle,
						       double minx,
						       double miny,
						       double maxx,
						       double maxy, int srid,
						       unsigned char *rgb,
						       unsigned char format,
						       int quality,
						       unsigned char **image,
						       int *image_sz);

    RL2_PRIVATE int get_payload_from_gray_rgba_transparent (unsigned int
							    width,
							    unsigned int
							    height,
							    unsigned char
							    *rgb,
							    unsigned char
							    *alpha,
							    unsigned char
							    format,
							    int quality,
							    unsigned char
							    **image,
							    int *image_sz,
							    double opacity);

    RL2_PRIVATE int get_payload_from_rgb_rgba_opaque (unsigned int width,
						      unsigned int height,
						      sqlite3 * handle,
						      double minx,
						      double miny,
						      double maxx,
						      double maxy, int srid,
						      unsigned char *rgb,
						      unsigned char format,
						      int quality,
						      unsigned char **image,
						      int *image_sz);

    RL2_PRIVATE int get_payload_from_rgb_rgba_transparent (unsigned int width,
							   unsigned int
							   height,
							   unsigned char *rgb,
							   unsigned char
							   *alpha,
							   unsigned char
							   format,
							   int quality,
							   unsigned char
							   **image,
							   int *image_sz,
							   double opacity,
							   int
							   half_transparent);

    RL2_PRIVATE int build_rgb_alpha (unsigned int width,
				     unsigned int height, unsigned char *rgba,
				     unsigned char **rgb,
				     unsigned char **alpha,
				     unsigned char bg_red,
				     unsigned char bg_green,
				     unsigned char bg_blue);

    RL2_PRIVATE int get_rgba_from_multiband8 (unsigned int width,
					      unsigned int height,
					      unsigned char red_band,
................................................................................
    RL2_PRIVATE int parse_worldfile (FILE * in, double *px, double *py,
				     double *pres_x, double *pres_y);

    RL2_PRIVATE rl2CoverageStylePtr coverage_style_from_xml (char *name,
							     unsigned char
							     *xml);

    RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char
								    *name,
								    unsigned
								    char *xml);

    RL2_PRIVATE rl2GroupStylePtr group_style_from_sld_xml (char *name,
							   unsigned char *xml);

    RL2_PRIVATE rl2PrivCoverageStylePtr
................................................................................

    RL2_PRIVATE void rl2_destroy_point_symbolizer (rl2PrivPointSymbolizerPtr
						   symbolizer);

    RL2_PRIVATE void rl2_destroy_line_symbolizer (rl2PrivLineSymbolizerPtr
						  symbolizer);

    RL2_PRIVATE void
	rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr symbolizer);

    RL2_PRIVATE void rl2_destroy_text_symbolizer (rl2PrivTextSymbolizerPtr
						  symbolizer);

    RL2_PRIVATE rl2PrivRuleSingleArgPtr
	rl2_create_default_rule_single_arg (void);

................................................................................
					 unsigned char nir_band_index,
					 double x_res, double y_res,
					 double minx, double maxy,
					 double tile_minx, double tile_maxy,
					 rl2PixelPtr no_data,
					 rl2RasterSymbolizerPtr style,
					 rl2RasterStatisticsPtr stats);

    RL2_PRIVATE int rl2_copy_raw_mask (rl2RasterPtr raster,
				       unsigned char *maskbuf,
				       unsigned int width,
				       unsigned int height,
				       double x_res, double y_res,
				       double minx, double maxy,
				       double tile_minx, double tile_maxy);

    RL2_PRIVATE unsigned char *rl2_copy_endian_raw_pixels (const unsigned char
							   *pixels,
							   int pixels_sz,
							   unsigned int width,
							   unsigned int
							   height,
							   unsigned char
							   sample_type,
							   unsigned char
							   num_bands,
							   int big_endian);

    RL2_PRIVATE int rl2_build_shaded_relief_mask (sqlite3 * handle,
						  int max_threads,
						  rl2CoveragePtr cvg,
						  int by_section,
						  sqlite3_int64 section_id,
						  double relief_factor,
						  double scale_factor,
						  unsigned int width,
						  unsigned int height,
						  double minx, double miny,
						  double maxx, double maxy,
						  double x_res, double y_res,
................................................................................
					const char *title,
					const char *abstract);

    RL2_PRIVATE int rl2_test_layer_group (sqlite3 * handle,
					  const char *group_name);

    RL2_PRIVATE int rl2_rgba_raster_data (sqlite3 * handle,
					  const char *coverage_name,
					  void *ctx, int level, double minx,
					  double miny, double maxx,
					  double maxy, rl2PalettePtr palette,
					  rl2PixelPtr no_data);

    RL2_PRIVATE int rl2_aux_render_image (struct aux_renderer *aux,
					  unsigned char **ximage,
					  int *ximage_size);

    RL2_PRIVATE int rl2_aux_default_image (unsigned int width,
					   unsigned int height,
					   unsigned char red,
					   unsigned char green,
					   unsigned char blue, int format_id,
					   int transparent, int quality,
					   unsigned char **ximage,
					   int *ximage_size);

    RL2_PRIVATE void rl2_aux_group_renderer (struct aux_group_renderer *auxgrp);

    RL2_PRIVATE double rl2_get_shaded_relief_scale_factor (sqlite3 * handle,
							   const char
							   *coverage);

................................................................................
						    rl2CoveragePtr cvg,
						    int by_section,
						    sqlite3_int64 section_id,
						    unsigned int width,
						    unsigned int height,
						    double minx, double miny,
						    double maxx, double maxy,
						    double x_res,
						    double y_res,
						    unsigned char **buffer,
						    int *buf_size,
						    rl2PalettePtr * palette,
						    unsigned char out_pixel,
						    rl2PixelPtr bgcolor,
						    rl2RasterSymbolizerPtr
						    style,
						    rl2RasterStatisticsPtr
						    stats);

    RL2_PRIVATE int rl2_get_raw_raster_mask_common (sqlite3 * handle,
						    int max_threads,
						    rl2CoveragePtr cvg,
						    int by_section,
						    sqlite3_int64 section_id,
						    unsigned int width,
						    unsigned int height,
						    double minx, double miny,
						    double maxx, double maxy,
						    double x_res, double y_res,
						    unsigned char **mask,
						    int *mask_size);

    RL2_PRIVATE rl2RasterPtr
	rl2_raster_decode_mask (int scale, const unsigned char *blob_odd,
				int blob_odd_sz, int *status);

    RL2_PRIVATE char *rl2_double_quoted_sql (const char *value);

    RL2_PRIVATE int rl2_parse_point (sqlite3 * sqlite,
				     const unsigned char *blob, int blob_sz,
				     double *x, double *y);

    RL2_PRIVATE int rl2_parse_point_generic (sqlite3 * sqlite,
					     const unsigned char *blob,
					     int blob_sz, double *x, double *y);

    RL2_PRIVATE int rl2_parse_bbox_srid (sqlite3 * sqlite,
					 const unsigned char *blob,
					 int blob_sz, int *srid, double *minx,
					 double *miny, double *maxx,
					 double *maxy);

    RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite,
				    const unsigned char *blob, int blob_sz,
				    double *minx, double *miny, double *maxx,
				    double *maxy);

    RL2_PRIVATE int rl2_build_bbox (sqlite3 * sqlite, int srid, double minx,
				    double miny, double maxx, double maxy,
				    unsigned char **blob, int *blob_sz);

    RL2_PRIVATE int rl2_delta_encode (unsigned char *buffer, int size,
				      int distance);

    RL2_PRIVATE int rl2_delta_decode (unsigned char *buffer, int size,
				      int distance);

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char
							       *name,
							       sqlite3_int64
							       value);

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_double (const char
								  *name,
								  double value);

................................................................................

    RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_null (const char
								*name);

    RL2_PRIVATE void rl2_destroy_variant_value (rl2PrivVariantValuePtr value);

    RL2_PRIVATE void rl2_draw_vector_feature (void *ctx, sqlite3 * handle,
					      const void *priv_data,
					      rl2VectorSymbolizerPtr
					      symbolizer, int height,
					      double minx, double miny,
					      double maxx, double maxy,
					      double x_res, double y_res,
					      rl2GeometryPtr geom,
					      rl2VariantArrayPtr variant);

    RL2_PRIVATE rl2GeometryPtr
	rl2_geometry_from_blob (const unsigned char *blob, int blob_sz);

    RL2_PRIVATE rl2GeometryPtr
................................................................................

    RL2_PRIVATE int rl2_serialize_linestring (rl2LinestringPtr line,
					      unsigned char **blob,
					      int *blob_sz);

    RL2_PRIVATE int rl2_serialize_ring (rl2RingPtr ring, unsigned char **blob,
					int *blob_sz);

    RL2_PRIVATE int rl2_serialize_ring_as_linestring (rl2RingPtr ring,
						      unsigned char **blob,
						      int *blob_sz);

    RL2_PRIVATE double rl2_compute_curve_length (rl2GeometryPtr geom);

    RL2_PRIVATE rl2GeometryPtr
	rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom,
			     double from, double to);

    RL2_PRIVATE rl2GeometryPtr rl2_clone_curve (rl2GeometryPtr in);

    RL2_PRIVATE rl2GeometryPtr rl2_clone_linestring (rl2LinestringPtr in);

    RL2_PRIVATE rl2GeometryPtr
	rl2_build_circle (double x, double y, double radius);
................................................................................

    RL2_PRIVATE int rl2_load_font_into_dbms (sqlite3 * handle,
					     unsigned char *blob, int blob_sz);

    RL2_PRIVATE int rl2_get_font_from_dbms (sqlite3 * handle,
					    const char *facename,
					    unsigned char **font, int *font_sz);

    RL2_PRIVATE rl2LinestringPtr rl2_linestring_to_image (rl2LinestringPtr line,
							  int height,
							  double minx,
							  double miny,
							  double x_res,
							  double y_res);

    RL2_PRIVATE rl2RingPtr rl2_ring_to_image (rl2RingPtr ring, int height,
					      double minx, double miny,
					      double x_res, double y_res);

    RL2_PRIVATE void rl2DestroyLinestring (rl2LinestringPtr ptr);

    RL2_PRIVATE void rl2DestroyRing (rl2RingPtr ptr);

#ifdef __cplusplus
}
#endif

#endif				/* _RASTERLITE2_PRIVATE_H */

Changes to headers/rl2svg_private.h.

502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
...
606
607
608
609
610
611
612
613

614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
							in);

    RL2_PRIVATE rl2PrivSvgLinePtr svg_alloc_line (double x1, double y1,
						  double x2, double y2);

    RL2_PRIVATE rl2PrivSvgLinePtr svg_clone_line (rl2PrivSvgLinePtr in);

    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points, double *x,
							  double *y);

    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_clone_polyline (rl2PrivSvgPolylinePtr
							  in);

    RL2_PRIVATE rl2PrivSvgPolygonPtr svg_alloc_polygon (int points, double *x,
							double *y);

    RL2_PRIVATE rl2PrivSvgPolygonPtr svg_clone_polygon (rl2PrivSvgPolygonPtr
							in);

    RL2_PRIVATE rl2PrivSvgPathMovePtr svg_alloc_path_move (double x, double y);

    RL2_PRIVATE rl2PrivSvgPathMovePtr svg_clone_path_move (rl2PrivSvgPathMovePtr
							   in);

    RL2_PRIVATE rl2PrivSvgPathBezierPtr svg_alloc_path_bezier (double x1,
							       double y1,
							       double x2,
							       double y2,
							       double x,
							       double y);
................................................................................

    RL2_PRIVATE void svg_set_group_parent (rl2PrivSvgItemPtr item,
					   rl2PrivSvgGroupPtr grp);

    RL2_PRIVATE rl2PrivSvgGradientStopPtr svg_alloc_gradient_stop (double
								   offset,
								   double red,
								   double green,

								   double blue,

								   double
								   opacity);

    RL2_PRIVATE rl2PrivSvgGradientStopPtr
	svg_clone_gradient_stop (rl2PrivSvgGradientStopPtr in);

    RL2_PRIVATE rl2PrivSvgGradientPtr svg_alloc_gradient (void);

    RL2_PRIVATE rl2PrivSvgGradientPtr svg_clone_gradient (rl2PrivSvgGradientPtr
							  in,
							  rl2PrivSvgGradientPtr
							  old);

    RL2_PRIVATE rl2PrivSvgDocumentPtr svg_alloc_document (void);

    RL2_PRIVATE void svg_close_group (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_insert_group (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_close_clip (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_insert_clip (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr svg_doc,

						 const char *xlink_href,
						 double x, double y,
						 double width, double height);

    RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc, int type,
				       void *data);

    RL2_PRIVATE void svg_insert_gradient_stop (rl2PrivSvgGradientPtr gradient,
					       double offset, double red,
					       double green, double blue,
					       double opacity);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_linear_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double x1, double y1, double x2, double y2,
				    int units);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double cx, double cy, double fx, double fy,
				    double r, int units);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double cx, double cy, double fx, double fy,
				    double r, int units);

    RL2_PRIVATE void svg_init_style (rl2PrivSvgStylePtr style);

    RL2_PRIVATE void svg_style_cleanup (rl2PrivSvgStylePtr style);


#ifdef __cplusplus
}
#endif

#endif				/* _RL2SVG_PRIVATE_H */







|
|

|
|









|
|







 







|
>
|
>








|
|
|
<











|
>




|
|









|
|




|
|




|
|











502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
...
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
							in);

    RL2_PRIVATE rl2PrivSvgLinePtr svg_alloc_line (double x1, double y1,
						  double x2, double y2);

    RL2_PRIVATE rl2PrivSvgLinePtr svg_clone_line (rl2PrivSvgLinePtr in);

    RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points,
							  double *x, double *y);

    RL2_PRIVATE rl2PrivSvgPolylinePtr
	svg_clone_polyline (rl2PrivSvgPolylinePtr in);

    RL2_PRIVATE rl2PrivSvgPolygonPtr svg_alloc_polygon (int points, double *x,
							double *y);

    RL2_PRIVATE rl2PrivSvgPolygonPtr svg_clone_polygon (rl2PrivSvgPolygonPtr
							in);

    RL2_PRIVATE rl2PrivSvgPathMovePtr svg_alloc_path_move (double x, double y);

    RL2_PRIVATE rl2PrivSvgPathMovePtr
	svg_clone_path_move (rl2PrivSvgPathMovePtr in);

    RL2_PRIVATE rl2PrivSvgPathBezierPtr svg_alloc_path_bezier (double x1,
							       double y1,
							       double x2,
							       double y2,
							       double x,
							       double y);
................................................................................

    RL2_PRIVATE void svg_set_group_parent (rl2PrivSvgItemPtr item,
					   rl2PrivSvgGroupPtr grp);

    RL2_PRIVATE rl2PrivSvgGradientStopPtr svg_alloc_gradient_stop (double
								   offset,
								   double red,
								   double
								   green,
								   double
								   blue,
								   double
								   opacity);

    RL2_PRIVATE rl2PrivSvgGradientStopPtr
	svg_clone_gradient_stop (rl2PrivSvgGradientStopPtr in);

    RL2_PRIVATE rl2PrivSvgGradientPtr svg_alloc_gradient (void);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_clone_gradient (rl2PrivSvgGradientPtr in,
			    rl2PrivSvgGradientPtr old);


    RL2_PRIVATE rl2PrivSvgDocumentPtr svg_alloc_document (void);

    RL2_PRIVATE void svg_close_group (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_insert_group (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_close_clip (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE void svg_insert_clip (rl2PrivSvgDocumentPtr svg_doc);

    RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr
						 svg_doc,
						 const char *xlink_href,
						 double x, double y,
						 double width, double height);

    RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc,
				       int type, void *data);

    RL2_PRIVATE void svg_insert_gradient_stop (rl2PrivSvgGradientPtr gradient,
					       double offset, double red,
					       double green, double blue,
					       double opacity);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_linear_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double x1, double y1, double x2,
				    double y2, int units);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double cx, double cy, double fx,
				    double fy, double r, int units);

    RL2_PRIVATE rl2PrivSvgGradientPtr
	svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc,
				    const char *id, const char *xlink_href,
				    double cx, double cy, double fx,
				    double fy, double r, int units);

    RL2_PRIVATE void svg_init_style (rl2PrivSvgStylePtr style);

    RL2_PRIVATE void svg_style_cleanup (rl2PrivSvgStylePtr style);


#ifdef __cplusplus
}
#endif

#endif				/* _RL2SVG_PRIVATE_H */

Deleted rasterlite2-4.2.0.mk.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
include $(CLEAR_VARS)
# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
LOCAL_MODULE    := rasterlite2

# SQLite flags copied from ASOP [may not be needed for rasterlite2]
common_sqlite_flags := \
 -DHAVE_USLEEP=1 \
 -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
 -DSQLITE_THREADSAFE=1 \
 -DNDEBUG=1 \
 -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
 -DSQLITE_DEFAULT_AUTOVACUUM=1 \
 -DSQLITE_TEMP_STORE=3 \
 -DSQLITE_ENABLE_FTS3 \
 -DSQLITE_ENABLE_FTS3_BACKWARDS \
 -DSQLITE_ENABLE_RTREE=1 \
 -DSQLITE_DEFAULT_FILE_FORMAT=4

# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
spatialite_flags := \
 -DOMIT_FREEXL \
 -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
 -Dfdatasync=fsync \
 -DSQLITE_ENABLE_RTREE=1 \
 -DSQLITE_OMIT_BUILTIN_TEST=1

# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
rasterlite2_flags := \
 -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
 -O

LOCAL_CFLAGS    := \
 $(common_sqlite_flags) \
 $(spatialite_flags) \
 $(rasterlite2_flags)

LOCAL_C_INCLUDES := \
 $(SQLITE_PATH) \
 $(GEOTIFF_PATH)/libxtiff \
 $(GEOTIFF_PATH) \
 $(TIFF_PATH) \
 $(JPEG_PATH) \
 $(GIF_PATH) \
 $(PNG_PATH) \
 $(WEBP_PATH)/src/webp \
 $(WEBP_PATH)/src/dec \
 $(WEBP_PATH)/src/dsp \
 $(WEBP_PATH)/src/enc \
 $(WEBP_PATH)/src/utils \
 $(WEBP_PATH)/src \
 $(WEBP_PATH) \
 $(CAIRO_PATH) \
 $(ICONV_PATH)/include \
 $(ICONV_PATH)/libcharset/include \
 $(XML2_PATH)/include \
 $(CURL_PATH) \
 $(CURL_PATH)/include \
 $(CURL_PATH)/lib \
 $(RASTERLITE2_PATH) \
 $(RASTERLITE2_PATH)/headers \
 $(SPATIALITE_PATH)/src/headers \
 $(LZMA_PATH)/src/liblzma/api
LOCAL_SRC_FILES := \
 $(RASTERLITE2_PATH)/src/rasterlite2.c \
 $(RASTERLITE2_PATH)/src/rl2ascii.c \
 $(RASTERLITE2_PATH)/src/rl2codec.c \
 $(RASTERLITE2_PATH)/src/rl2dbms.c \
 $(RASTERLITE2_PATH)/src/rl2gif.c \
 $(RASTERLITE2_PATH)/src/rl2import.c \
 $(RASTERLITE2_PATH)/src/rl2jpeg.c \
 $(RASTERLITE2_PATH)/src/rl2paint.c \
 $(RASTERLITE2_PATH)/src/rl2png.c \
 $(RASTERLITE2_PATH)/src/rl2rastersym.c \
 $(RASTERLITE2_PATH)/src/rl2raw.c \
 $(RASTERLITE2_PATH)/src/rl2sql.c \
 $(RASTERLITE2_PATH)/src/rl2sqlaux.c \
 $(RASTERLITE2_PATH)/src/rl2svg.c \
 $(RASTERLITE2_PATH)/src/rl2svgaux.c \
 $(RASTERLITE2_PATH)/src/rl2svgxml.c \
 $(RASTERLITE2_PATH)/src/rl2symbolizer.c \
 $(RASTERLITE2_PATH)/src/rl2tiff.c \
 $(RASTERLITE2_PATH)/src/rl2version.c \
 $(RASTERLITE2_PATH)/src/rl2webp.c \
 $(RASTERLITE2_PATH)/src/rl2wms.c
LOCAL_STATIC_LIBRARIES := libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg
include $(BUILD_STATIC_LIBRARY)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<












































































































































































Added rasterlite2-4.3.0.mk.





















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
include $(CLEAR_VARS)
# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
LOCAL_MODULE    := rasterlite2

# SQLite flags copied from ASOP [may not be needed for rasterlite2]
common_sqlite_flags := \
 -DHAVE_USLEEP=1 \
 -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
 -DSQLITE_THREADSAFE=1 \
 -DNDEBUG=1 \
 -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
 -DSQLITE_DEFAULT_AUTOVACUUM=1 \
 -DSQLITE_TEMP_STORE=3 \
 -DSQLITE_ENABLE_FTS3 \
 -DSQLITE_ENABLE_FTS3_BACKWARDS \
 -DSQLITE_ENABLE_RTREE=1 \
 -DSQLITE_DEFAULT_FILE_FORMAT=4

# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
spatialite_flags := \
 -DOMIT_FREEXL \
 -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
 -Dfdatasync=fsync \
 -DSQLITE_ENABLE_RTREE=1 \
 -DENABLE_GCP=1 \
 -DENABLE_GEOPACKAGE=1 \
 -DENABLE_LIBXML2=1 \
 -DSQLITE_OMIT_BUILTIN_TEST=1

# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI
# comment out VERSION in config.h - manually set to avoid conflict with other packages
rasterlite2_flags := \
 -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \
 -DVERSION=\"0.9\" \
 -O

LOCAL_CFLAGS    := \
 $(common_sqlite_flags) \
 $(spatialite_flags) \
 $(rasterlite2_flags)

# 2014-10-03 - adapted based on ls -1 result
LOCAL_C_INCLUDES := \
 $(SQLITE_PATH) \
 $(GEOTIFF_PATH)/libxtiff \
 $(GEOTIFF_PATH) \
 $(TIFF_PATH) \
 $(JPEG_PATH) \
 $(GIF_PATH) \
 $(PNG_PATH) \
 $(WEBP_PATH)/src/webp \
 $(WEBP_PATH)/src/dec \
 $(WEBP_PATH)/src/dsp \
 $(WEBP_PATH)/src/enc \
 $(WEBP_PATH)/src/utils \
 $(WEBP_PATH)/src \
 $(WEBP_PATH) \
 $(CAIRO_PATH) \
 $(FONTCONFIG_PATH) \
 $(ICONV_PATH)/include \
 $(FREETYPE_PATH)/include \
 $(ICONV_PATH)/libcharset/include \
 $(XML2_PATH)/include \
 $(CURL_PATH) \
 $(CURL_PATH)/include \
 $(CURL_PATH)/lib \
 $(RASTERLITE2_PATH) \
 $(RASTERLITE2_PATH)/headers \
 $(SPATIALITE_PATH)/src/headers \
 $(LZMA_PATH)/src/liblzma/api \
 $(OPENJPEG_PATH)/src/lib/openjp2 \
 $(CHARLS_PATH)

LOCAL_SRC_FILES := \
 $(RASTERLITE2_PATH)/src/md5.c \
 $(RASTERLITE2_PATH)/src/rasterlite2.c \
 $(RASTERLITE2_PATH)/src/rl2ascii.c \
 $(RASTERLITE2_PATH)/src/rl2auxfont.c \
 $(RASTERLITE2_PATH)/src/rl2auxgeom.c \
 $(RASTERLITE2_PATH)/src/rl2auxrender.c \
 $(RASTERLITE2_PATH)/src/rl2charls.c \
 $(RASTERLITE2_PATH)/src/rl2codec.c \
 $(RASTERLITE2_PATH)/src/rl2dbms.c \
 $(RASTERLITE2_PATH)/src/rl2gif.c \
 $(RASTERLITE2_PATH)/src/rl2import.c \
 $(RASTERLITE2_PATH)/src/rl2jpeg.c \
 $(RASTERLITE2_PATH)/src/rl2md5.c \
 $(RASTERLITE2_PATH)/src/rl2openjpeg.c \
 $(RASTERLITE2_PATH)/src/rl2paint.c \
 $(RASTERLITE2_PATH)/src/rl2png.c \
 $(RASTERLITE2_PATH)/src/rl2pyramid.c \
 $(RASTERLITE2_PATH)/src/rl2rastersym.c \
 $(RASTERLITE2_PATH)/src/rl2raw.c \
 $(RASTERLITE2_PATH)/src/rl2sql.c \
 $(RASTERLITE2_PATH)/src/rl2sqlaux.c \
 $(RASTERLITE2_PATH)/src/rl2svg.c \
 $(RASTERLITE2_PATH)/src/rl2svgaux.c \
 $(RASTERLITE2_PATH)/src/rl2svgxml.c \
 $(RASTERLITE2_PATH)/src/rl2symbaux.c \
 $(RASTERLITE2_PATH)/src/rl2symbolizer.c \
 $(RASTERLITE2_PATH)/src/rl2tiff.c \
 $(RASTERLITE2_PATH)/src/rl2version.c \
 $(RASTERLITE2_PATH)/src/rl2webp.c \
 $(RASTERLITE2_PATH)/src/rl2wms.c
LOCAL_STATIC_LIBRARIES := libcharls libopenjpeg libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg
include $(BUILD_STATIC_LIBRARY)

Changes to src/Makefile.am.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
46
47
48
49
50
51
52
53
54
55
56
57
	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@	@LIBCURL_LIBS@ \
	@LIBXML2_LIBS@ @LIBFREETYPE2_LIBS@

if MINGW
librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
librasterlite2_la_LIBADD += -lm
else
librasterlite2_la_LDFLAGS = -version-info 0:0:0
librasterlite2_la_LIBADD += -lpthread -lm
endif

mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
................................................................................
mod_rasterlite2_la_CPPFLAGS += -DLOADABLE_EXTENSION
mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static

if MINGW
mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
mod_rasterlite2_la_LIBADD += -lm
else
mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0
mod_rasterlite2_la_LIBADD += -lpthread -lm
endif

MOSTLYCLEANFILES = *.gcna *.gcno *.gcda







|







 







|




21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
46
47
48
49
50
51
52
53
54
55
56
57
	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@	@LIBCURL_LIBS@ \
	@LIBXML2_LIBS@ @LIBFREETYPE2_LIBS@

if MINGW
librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
librasterlite2_la_LIBADD += -lm
else
librasterlite2_la_LDFLAGS = -version-info 1:0:0
librasterlite2_la_LIBADD += -lpthread -lm
endif

mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
................................................................................
mod_rasterlite2_la_CPPFLAGS += -DLOADABLE_EXTENSION
mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static

if MINGW
mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
mod_rasterlite2_la_LIBADD += -lm
else
mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0
mod_rasterlite2_la_LIBADD += -lpthread -lm
endif

MOSTLYCLEANFILES = *.gcna *.gcno *.gcda

Changes to src/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
..
12
13
14
15
16
17
18
19










20
21
22
23
24
25
26
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
...
230
231
232
233
234
235
236

237
238
239
240
241
242
243
...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
996
997
998
999
1000
1001
1002


1003
1004
1005
1006
1007
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@


VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
build_triplet = @build@
host_triplet = @host@
@MINGW_TRUE@am__append_1 = -lm
@MINGW_FALSE@am__append_2 = -lpthread -lm
@MINGW_TRUE@am__append_3 = -lm
@MINGW_FALSE@am__append_4 = -lpthread -lm
subdir = src
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
	$(top_srcdir)/depcomp $(noinst_HEADERS)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)


mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags

DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
	rl2auxgeom.c rl2auxfont.c

librasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ @LIBLZMA_LIBS@ \
	@LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
	@LIBFREETYPE2_LIBS@ $(am__append_1) $(am__append_2)
@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 0:0:0
@MINGW_TRUE@librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
................................................................................

mod_rasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ \
	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
	@LIBFREETYPE2_LIBS@ $(am__append_3) $(am__append_4)
mod_rasterlite2_la_CPPFLAGS = @CFLAGS@ -I$(top_srcdir)/headers -I. \
	-DLOADABLE_EXTENSION
mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static
@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0
@MINGW_TRUE@mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
MOSTLYCLEANFILES = *.gcna *.gcno *.gcda
all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-exec-am install-html install-html-am install-info \
	install-info-am install-libLTLIBRARIES install-man install-pdf \
	install-pdf-am install-ps install-ps-am install-strip \
	installcheck installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES




# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|







 







|
>
>
>
>
>
>
>
>
>
>







 







<
<







>
>







 







>







 







|







 







|







 







<







 







>
>





1
2
3
4
5
6
7
8
9
10
11
..
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
90
91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
...
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
...
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
...
437
438
439
440
441
442
443

444
445
446
447
448
449
450
....
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
................................................................................
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@


VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
build_triplet = @build@
host_triplet = @host@
@MINGW_TRUE@am__append_1 = -lm
@MINGW_FALSE@am__append_2 = -lpthread -lm
@MINGW_TRUE@am__append_3 = -lm
@MINGW_FALSE@am__append_4 = -lpthread -lm
subdir = src


ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \
	$(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
	rl2auxgeom.c rl2auxfont.c

librasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ @LIBLZMA_LIBS@ \
	@LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
	@LIBFREETYPE2_LIBS@ $(am__append_1) $(am__append_2)
@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 1:0:0
@MINGW_TRUE@librasterlite2_la_LDFLAGS = -avoid-version -no-undefined
mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \
	rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \
	rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \
	rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \
	rl2svgaux.c rl2symbolizer.c rl2symbaux.c rl2rastersym.c \
	rl2version.c rl2md5.c md5.c rl2charls.c rl2openjpeg.c \
................................................................................

mod_rasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ \
	@LIBLZMA_LIBS@ @LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \
	@LIBFREETYPE2_LIBS@ $(am__append_3) $(am__append_4)
mod_rasterlite2_la_CPPFLAGS = @CFLAGS@ -I$(top_srcdir)/headers -I. \
	-DLOADABLE_EXTENSION
mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static
@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0
@MINGW_TRUE@mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined
MOSTLYCLEANFILES = *.gcna *.gcno *.gcda
all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu src/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-exec-am install-html install-html-am install-info \
	install-info-am install-libLTLIBRARIES install-man install-pdf \
	install-pdf-am install-ps install-ps-am install-strip \
	installcheck installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES

.PRECIOUS: Makefile


# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to src/rasterlite2.c.

510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
....
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
....
1428
1429
1430
1431
1432
1433
1434
1435

1436
1437
1438
1439
1440
1441
1442
1443
....
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
....
1473
1474
1475
1476
1477
1478
1479
1480

1481
1482
1483
1484
1485
1486
1487
1488
....
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
....
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
	  return RL2_FALSE;
#endif
      };
    return RL2_ERROR;
}

static int
check_coverage_no_data (rl2PrivPixelPtr pxl_no_data, unsigned char sample_type,

			unsigned char pixel_type, unsigned char num_samples)
{
/* checking if the NoData pixel is consistent with the Coverage */
    if (pxl_no_data == NULL)
	return 1;
    if (pxl_no_data->sampleType != sample_type)
	return 0;
    if (pxl_no_data->pixelType != pixel_type)
................................................................................
    return (rl2RasterPtr) rst;
}

RL2_DECLARE rl2RasterPtr
rl2_create_raster (unsigned int width, unsigned int height,
		   unsigned char sample_type, unsigned char pixel_type,
		   unsigned char num_samples, unsigned char *bufpix,
		   int bufpix_size, rl2PalettePtr palette, unsigned char *mask,
		   int mask_size, rl2PixelPtr no_data)
{
/* allocating and initializing a Raster object with an optional Transparency Mask */
    return create_raster_common (width, height, sample_type, pixel_type,
				 num_samples, bufpix, bufpix_size, palette,
				 mask, mask_size, no_data, 0);
}

................................................................................
    rst->minY = cy - vExt;
    rst->maxX = cx + hExt;
    rst->maxY = cy + vExt;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid, double horz_res,

				    double vert_res, double x, double y)
{
/* setting the Raster's georeferencing infos - UpperLeft corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->maxX = x + hExt;
    rst->maxY = y;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_upper_right (rl2RasterPtr ptr, int srid,
				     double horz_res, double vert_res, double x,
				     double y)
{
/* setting the Raster's georeferencing infos - UpperRight corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->minY = y - vExt;
    rst->maxX = x;
    rst->maxY = y;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid, double horz_res,

				    double vert_res, double x, double y)
{
/* setting the Raster's georeferencing infos - LowerLeft corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->maxX = x + hExt;
    rst->maxY = y + vExt;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_lower_right (rl2RasterPtr ptr, int srid,
				     double horz_res, double vert_res, double x,
				     double y)
{
/* setting the Raster's georeferencing infos - LowerRight corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    entry->red = r;
    entry->green = g;
    entry->blue = b;
    return RL2_OK;
}

RL2_DECLARE int
rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index, unsigned char r,
		       unsigned char g, unsigned char b)
{
/* finding the index corresponding to the given color (if any) */
    int i;
    rl2PrivPaletteEntryPtr entry;
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) ptr;
    if (plt == NULL)
	return RL2_ERROR;







|
>
|







 







|
|







 







|
>
|







 







|
|







 







|
>
|







 







|
|







 







|
|







510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
....
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
....
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
....
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
....
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
....
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
....
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
	  return RL2_FALSE;
#endif
      };
    return RL2_ERROR;
}

static int
check_coverage_no_data (rl2PrivPixelPtr pxl_no_data,
			unsigned char sample_type, unsigned char pixel_type,
			unsigned char num_samples)
{
/* checking if the NoData pixel is consistent with the Coverage */
    if (pxl_no_data == NULL)
	return 1;
    if (pxl_no_data->sampleType != sample_type)
	return 0;
    if (pxl_no_data->pixelType != pixel_type)
................................................................................
    return (rl2RasterPtr) rst;
}

RL2_DECLARE rl2RasterPtr
rl2_create_raster (unsigned int width, unsigned int height,
		   unsigned char sample_type, unsigned char pixel_type,
		   unsigned char num_samples, unsigned char *bufpix,
		   int bufpix_size, rl2PalettePtr palette,
		   unsigned char *mask, int mask_size, rl2PixelPtr no_data)
{
/* allocating and initializing a Raster object with an optional Transparency Mask */
    return create_raster_common (width, height, sample_type, pixel_type,
				 num_samples, bufpix, bufpix_size, palette,
				 mask, mask_size, no_data, 0);
}

................................................................................
    rst->minY = cy - vExt;
    rst->maxX = cx + hExt;
    rst->maxY = cy + vExt;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid,
				    double horz_res, double vert_res,
				    double x, double y)
{
/* setting the Raster's georeferencing infos - UpperLeft corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->maxX = x + hExt;
    rst->maxY = y;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_upper_right (rl2RasterPtr ptr, int srid,
				     double horz_res, double vert_res,
				     double x, double y)
{
/* setting the Raster's georeferencing infos - UpperRight corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->minY = y - vExt;
    rst->maxX = x;
    rst->maxY = y;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid,
				    double horz_res, double vert_res,
				    double x, double y)
{
/* setting the Raster's georeferencing infos - LowerLeft corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    rst->maxX = x + hExt;
    rst->maxY = y + vExt;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_georeference_lower_right (rl2RasterPtr ptr, int srid,
				     double horz_res, double vert_res,
				     double x, double y)
{
/* setting the Raster's georeferencing infos - LowerRight corner */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr;
    double hExt;
    double vExt;
    if (rst == NULL)
	return RL2_ERROR;
................................................................................
    entry->red = r;
    entry->green = g;
    entry->blue = b;
    return RL2_OK;
}

RL2_DECLARE int
rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index,
		       unsigned char r, unsigned char g, unsigned char b)
{
/* finding the index corresponding to the given color (if any) */
    int i;
    rl2PrivPaletteEntryPtr entry;
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) ptr;
    if (plt == NULL)
	return RL2_ERROR;

Changes to src/rl2ascii.c.

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
...
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
	 &no_data))
      {
	  fprintf (stderr, "ASCII Origin: invalid Header found on %s\n", path);
	  goto error;
      }

    ascii =
	alloc_ascii_origin (path, srid, sample_type, width, height, minx, miny,
			    maxx, maxy, xres, yres, no_data);
    if (ascii == NULL)
	goto error;

    *buf = '\0';
    col_no = width;
/* creating the helper Temporary File */
    ascii->tmp = tmpfile ();
................................................................................
	return RL2_FALSE;
    if (coverage->Srid != srid)
      {
	  if (verbose)
	      fprintf (stderr, "Mismatching SRID !!!\n");
	  return RL2_FALSE;
      }
    if (rl2_get_ascii_grid_origin_resolution (ascii, &hResolution, &vResolution)
	!= RL2_OK)
	return RL2_FALSE;
    confidence = coverage->hResolution / 100.0;
    if (hResolution < (coverage->hResolution - confidence)
	|| hResolution > (coverage->hResolution + confidence))
      {
	  if (verbose)
	      fprintf (stderr, "Mismatching Horizontal Resolution !!!\n");
................................................................................
	  unsigned short *p_out = pixels + (y * width);
	  if (fseek (origin->tmp, offset, SEEK_SET) != 0)
	      return 0;
	  for (x = 0, col = startCol; x < width && col < origin->width;
	       x++, col++)
	    {
		unsigned short uint16;
		if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp) <=
		    0)
		    return 0;
		*p_out++ = uint16;
	    }
      }
    return 1;
}

................................................................................
		      /* setting opaque pixels */
		      memset (p, 1, shadow_x);
		  }
	    }
      }
    raster =
	rl2_create_raster (coverage->tileWidth, coverage->tileHeight,
			   coverage->sampleType, RL2_PIXEL_DATAGRID, 1, pixels,
			   pixels_sz, NULL, mask, mask_size, NULL);
    if (raster == NULL)
	goto error;
    return raster;
  error:
    if (pixels != NULL)
	free (pixels);
    if (mask != NULL)







|
|







 







|
|







 







|
|







 







|
|







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
...
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
	 &no_data))
      {
	  fprintf (stderr, "ASCII Origin: invalid Header found on %s\n", path);
	  goto error;
      }

    ascii =
	alloc_ascii_origin (path, srid, sample_type, width, height, minx,
			    miny, maxx, maxy, xres, yres, no_data);
    if (ascii == NULL)
	goto error;

    *buf = '\0';
    col_no = width;
/* creating the helper Temporary File */
    ascii->tmp = tmpfile ();
................................................................................
	return RL2_FALSE;
    if (coverage->Srid != srid)
      {
	  if (verbose)
	      fprintf (stderr, "Mismatching SRID !!!\n");
	  return RL2_FALSE;
      }
    if (rl2_get_ascii_grid_origin_resolution
	(ascii, &hResolution, &vResolution) != RL2_OK)
	return RL2_FALSE;
    confidence = coverage->hResolution / 100.0;
    if (hResolution < (coverage->hResolution - confidence)
	|| hResolution > (coverage->hResolution + confidence))
      {
	  if (verbose)
	      fprintf (stderr, "Mismatching Horizontal Resolution !!!\n");
................................................................................
	  unsigned short *p_out = pixels + (y * width);
	  if (fseek (origin->tmp, offset, SEEK_SET) != 0)
	      return 0;
	  for (x = 0, col = startCol; x < width && col < origin->width;
	       x++, col++)
	    {
		unsigned short uint16;
		if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp)
		    <= 0)
		    return 0;
		*p_out++ = uint16;
	    }
      }
    return 1;
}

................................................................................
		      /* setting opaque pixels */
		      memset (p, 1, shadow_x);
		  }
	    }
      }
    raster =
	rl2_create_raster (coverage->tileWidth, coverage->tileHeight,
			   coverage->sampleType, RL2_PIXEL_DATAGRID, 1,
			   pixels, pixels_sz, NULL, mask, mask_size, NULL);
    if (raster == NULL)
	goto error;
    return raster;
  error:
    if (pixels != NULL)
	free (pixels);
    if (mask != NULL)

Changes to src/rl2auxfont.c.

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
...
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
...
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796



797
		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
		      int blob_sz = sqlite3_column_bytes (stmt, 0);
		      if (xfont != NULL)
			{
			    free (xfont);
			    xfont = NULL;
			}
		      if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz) ==
			  RL2_OK)
			{
			    *font = xfont;
			    *font_sz = xfont_sz;
			}
		  }
	    }
	  else
................................................................................
		       unsigned char **font, int *font_sz)
{
/* attempting to fetch a BLOB-encoded TrueType Font */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    unsigned char *xfont = NULL;
    int xfont_sz;
    if (facename == NULL)
	return RL2_ERROR;

    *font = NULL;
    *font_sz = 0;
/* preparing the SQL query statement */
    sql = "SELECT font FROM SE_fonts WHERE Lower(font_facename) = Lower(?)";
................................................................................
}

RL2_DECLARE rl2GraphicsFontPtr
rl2_search_TrueType_font (sqlite3 * handle, const void *priv_data,
			  const char *facename, double size)
{
/* attempting to fetch and create a TrueType Font */

    unsigned char *ttf = NULL;
    int ttf_sz;
    if (facename == NULL)
	return NULL;

    if (rl2_get_TrueType_font (handle, facename, &ttf, &ttf_sz) != RL2_OK)
	return NULL;
    return rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size);



}







|
|







 







<







 







>







|
>
>
>

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
...
723
724
725
726
727
728
729

730
731
732
733
734
735
736
...
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
		      int blob_sz = sqlite3_column_bytes (stmt, 0);
		      if (xfont != NULL)
			{
			    free (xfont);
			    xfont = NULL;
			}
		      if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz)
			  == RL2_OK)
			{
			    *font = xfont;
			    *font_sz = xfont_sz;
			}
		  }
	    }
	  else
................................................................................
		       unsigned char **font, int *font_sz)
{
/* attempting to fetch a BLOB-encoded TrueType Font */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    unsigned char *xfont = NULL;

    if (facename == NULL)
	return RL2_ERROR;

    *font = NULL;
    *font_sz = 0;
/* preparing the SQL query statement */
    sql = "SELECT font FROM SE_fonts WHERE Lower(font_facename) = Lower(?)";
................................................................................
}

RL2_DECLARE rl2GraphicsFontPtr
rl2_search_TrueType_font (sqlite3 * handle, const void *priv_data,
			  const char *facename, double size)
{
/* attempting to fetch and create a TrueType Font */
    rl2GraphicsFontPtr font;
    unsigned char *ttf = NULL;
    int ttf_sz;
    if (facename == NULL)
	return NULL;

    if (rl2_get_TrueType_font (handle, facename, &ttf, &ttf_sz) != RL2_OK)
	return NULL;
    font = rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size);
    if (ttf != NULL)
	free (ttf);
    return font;
}

Changes to src/rl2auxgeom.c.

122
123
124
125
126
127
128




129
130
131
132
133
134
135
136
137
138
139
140
141
142
143




























144
145
146
147
148
149
150
151




152
153
154
155




























156
157
158
159
160
161
162
163
...
181
182
183
184
185
186
187




188
189
190
191
192
193
194
...
622
623
624
625
626
627
628








629
630
631
632
633
634
635
...
648
649
650
651
652
653
654








655
656
657
658
659
660
661
...
674
675
676
677
678
679
680








681
682
683
684
685
686
687
...
700
701
702
703
704
705
706








707
708
709
710
711
712
713
...
765
766
767
768
769
770
771








772
773
774
775
776
777
778
...
807
808
809
810
811
812
813








814
815
816
817
818
819
820
...
849
850
851
852
853
854
855








856
857
858
859
860
861
862
...
891
892
893
894
895
896
897








898
899
900
901
902
903
904
...
936
937
938
939
940
941
942








943
944
945
946
947
948
949
...
982
983
984
985
986
987
988








989
990
991
992
993
994
995
....
1028
1029
1030
1031
1032
1033
1034








1035
1036
1037
1038
1039
1040
1041
....
1074
1075
1076
1077
1078
1079
1080








1081
1082
1083
1084
1085
1086
1087
....
1137
1138
1139
1140
1141
1142
1143








1144
1145
1146
1147
1148
1149
1150
....
1201
1202
1203
1204
1205
1206
1207








1208
1209
1210
1211
1212
1213
1214
....
1265
1266
1267
1268
1269
1270
1271








1272
1273
1274
1275
1276
1277
1278
....
1329
1330
1331
1332
1333
1334
1335








1336
1337
1338
1339
1340
1341
1342
....
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
....
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
....
1719
1720
1721
1722
1723
1724
1725





























































1726
1727
1728
1729
1730
1731
1732
....
1733
1734
1735
1736
1737
1738
1739

1740









1741
1742
1743
1744
1745
1746
1747
....
1850
1851
1852
1853
1854
1855
1856








1857
1858
1859
1860
1861
1862
1863
....
1870
1871
1872
1873
1874
1875
1876








1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897








1898
1899
1900
1901
1902
1903
1904
static rl2LinestringPtr
rl2CreateLinestring (int vert)
{
/* LINESTRING object constructor */
    rl2LinestringPtr p = malloc (sizeof (rl2Linestring));
    p->coords = malloc (sizeof (double) * (vert * 2));
    p->points = vert;




    p->next = NULL;
    return p;
}

static void
rl2DestroyLinestring (rl2LinestringPtr ptr)
{
/* LINESTRING object desctructror */
    if (ptr)
      {
	  if (ptr->coords)
	      free (ptr->coords);
	  free (ptr);
      }
}





























static rl2RingPtr
rl2CreateRing (int vert)
{
/* ring object constructor */
    rl2RingPtr p = malloc (sizeof (rl2Ring));
    p->coords = malloc (sizeof (double) * (vert * 2));
    p->points = vert;




    p->next = NULL;
    return p;
}





























static void
rl2DestroyRing (rl2RingPtr ptr)
{
/* ring object destructor */
    if (ptr)
      {
	  if (ptr->coords)
	      free (ptr->coords);
................................................................................
    else
	p->interiors = malloc (sizeof (rl2Ring) * excl);
    for (ind = 0; ind < p->num_interiors; ind++)
      {
	  pP = p->interiors + ind;
	  pP->points = 0;
	  pP->coords = NULL;




      }
    return p;
}

static void
rl2DestroyPolygon (rl2PolygonPtr p)
{
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);








	  *offset += 16;
      }
}

static void
rl2ParseLineZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
	       int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);








	  *offset += 24;
      }
}

static void
rl2ParseLineM (rl2GeometryPtr geom, const unsigned char *blob, int size,
	       int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);








	  *offset += 24;
      }
}

static void
rl2ParseLineZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);








	  *offset += 32;
      }
}

static rl2PolygonPtr
rl2AddPolygonToGeometry (rl2GeometryPtr p, int vert, int interiors)
{
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 16;
		rl2SetPoint (ring->coords, iv, x, y);








	    }
      }
}

static void
rl2ParsePolygonZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
		  int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 24;
		rl2SetPoint (ring->coords, iv, x, y);








	    }
      }
}

static void
rl2ParsePolygonM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		  int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 24;
		rl2SetPoint (ring->coords, iv, x, y);








	    }
      }
}

static void
rl2ParsePolygonZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		   int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 32;
		rl2SetPoint (ring->coords, iv, x, y);








	    }
      }
}

static void
rl2ParseCompressedLine (rl2GeometryPtr geom, const unsigned char *blob,
			int size, int endian, int endian_arch, int *offset)
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 8;
	    }
	  rl2SetPoint (line->coords, iv, x, y);








	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineZ (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 12;
	    }
	  rl2SetPoint (line->coords, iv, x, y);








	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 16;
	    }
	  rl2SetPoint (line->coords, iv, x, y);








	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineZM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 20;
	    }
	  rl2SetPoint (line->coords, iv, x, y);








	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedPolygon (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 8;
		  }
		rl2SetPoint (ring->coords, iv, x, y);








		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 12;
		  }
		rl2SetPoint (ring->coords, iv, x, y);








		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 16;
		  }
		rl2SetPoint (ring->coords, iv, x, y);








		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 20;
		  }
		rl2SetPoint (ring->coords, iv, x, y);








		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
				   offset);
		break;
	    case GAIA_COMPRESSED_LINESTRING:
		rl2ParseCompressedLine (geom, blob, size, endian, endian_arch,
					offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGZ:
		rl2ParseCompressedLineZ (geom, blob, size, endian, endian_arch,
					 offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGM:
		rl2ParseCompressedLineM (geom, blob, size, endian, endian_arch,
					 offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGZM:
		rl2ParseCompressedLineZM (geom, blob, size, endian, endian_arch,
					  offset);
		break;
	    case GAIA_COMPRESSED_POLYGON:
		rl2ParseCompressedPolygon (geom, blob, size, endian,
					   endian_arch, offset);
		break;
	    case GAIA_COMPRESSED_POLYGONZ:
		rl2ParseCompressedPolygonZ (geom, blob, size, endian,
................................................................................
			    &offset);
	  break;
      case GAIA_POLYGONZM:
	  rl2ParsePolygonZM (geom, blob, size, little_endian, endian_arch,
			     &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRING:
	  rl2ParseCompressedLine (geom, blob, size, little_endian, endian_arch,
				  &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGZ:
	  rl2ParseCompressedLineZ (geom, blob, size, little_endian, endian_arch,
				   &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGM:
	  rl2ParseCompressedLineM (geom, blob, size, little_endian, endian_arch,
				   &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGZM:
	  rl2ParseCompressedLineZM (geom, blob, size, little_endian,
				    endian_arch, &offset);
	  break;
      case GAIA_COMPRESSED_POLYGON:
	  rl2ParseCompressedPolygon (geom, blob, size, little_endian,
................................................................................
	  rl2GeomExport64 (ptr, x, 1, endian_arch);	/* X - exterior ring */
	  rl2GeomExport64 (ptr + 8, y, 1, endian_arch);	/* Y - exterior ring */
	  ptr += 16;
      }
    *ptr = GAIA_MARK_END;	/* END signature */
    return 1;
}






























































RL2_PRIVATE rl2GeometryPtr
rl2_curve_from_XY (int points, double *x, double *y)
{
/* creating a Linestring Geometry from X,Y coordinate arrays */
    rl2GeometryPtr geom = NULL;
    rl2LinestringPtr ln;
................................................................................
    int iv;

    if (points <= 0 || x == NULL || y == NULL)
	return 0;
    geom = rl2CreateGeometry ();
    ln = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)

	rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv));









    return geom;
}

RL2_PRIVATE double
rl2_compute_curve_length (rl2GeometryPtr geom)
{
/* computing the total length of some curve (single linestring expected) */
................................................................................
    ln_out = rl2AddLinestringToGeometry (out, ln_in->points);
    for (iv = 0; iv < ln_in->points; iv++)
      {
	  double x;
	  double y;
	  rl2GetPoint (ln_in->coords, iv, &x, &y);
	  rl2SetPoint (ln_out->coords, iv, x, y);








      }
    return out;
}

RL2_PRIVATE rl2GeometryPtr
rl2_clone_linestring (rl2LinestringPtr in)
{
................................................................................
    ln_out = rl2AddLinestringToGeometry (out, in->points);
    for (iv = 0; iv < in->points; iv++)
      {
	  double x;
	  double y;
	  rl2GetPoint (in->coords, iv, &x, &y);
	  rl2SetPoint (ln_out->coords, iv, x, y);








      }
    return out;
}

RL2_PRIVATE rl2GeometryPtr
rl2_build_circle (double cx, double cy, double radius)
{
/* creating a cicrle */
    int iv = 0;
    double pi = 3.14159265359;
    double rads;
    double x;
    double y;
    rl2LinestringPtr ln;
    rl2GeometryPtr out = rl2CreateGeometry ();
    ln = rl2AddLinestringToGeometry (out, 129);
    for (rads = 0.0; rads <= (pi * 2.0); rads += pi / 64.0)
      {
	  x = cx + (radius * cos (rads));
	  y = cy + (radius * sin (rads));
	  rl2SetPoint (ln->coords, iv, x, y);








	  iv++;
      }
    /* closure */
    rl2GetPoint (ln->coords, 0, &x, &y);
    rl2SetPoint (ln->coords, 128, x, y);
    return out;
}







>
>
>
>




|










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







|
|


|
|


|
|







 







|
|


|
|


|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
|
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







|













>
>
>
>
>
>
>
>







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
...
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
...
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
...
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
...
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
....
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
....
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
....
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
....
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
....
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
....
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
....
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
....
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
....
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
....
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
....
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
....
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
....
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
....
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
static rl2LinestringPtr
rl2CreateLinestring (int vert)
{
/* LINESTRING object constructor */
    rl2LinestringPtr p = malloc (sizeof (rl2Linestring));
    p->coords = malloc (sizeof (double) * (vert * 2));
    p->points = vert;
    p->minx = DBL_MAX;
    p->miny = DBL_MAX;
    p->maxx = 0.0 - DBL_MAX;
    p->maxy = 0.0 - DBL_MAX;
    p->next = NULL;
    return p;
}

RL2_PRIVATE void
rl2DestroyLinestring (rl2LinestringPtr ptr)
{
/* LINESTRING object desctructror */
    if (ptr)
      {
	  if (ptr->coords)
	      free (ptr->coords);
	  free (ptr);
      }
}

RL2_PRIVATE rl2LinestringPtr
rl2_linestring_to_image (rl2LinestringPtr line, int height, double minx,
			 double miny, double x_res, double y_res)
{
/* creating a Linestring in image coordinates */
    rl2LinestringPtr out = NULL;
    int iv;
    double x;
    double y;
    double dx;
    double dy;

    if (line == NULL)
	return NULL;
    out = rl2CreateLinestring (line->points);
    if (out == NULL)
	return out;
    for (iv = 0; iv < line->points; iv++)
      {
	  /* populating the X and Y arrays */
	  rl2GetPoint (line->coords, iv, &x, &y);
	  dx = (x - minx) / x_res;
	  dy = (double) height - ((y - miny) / y_res);
	  rl2SetPoint (out->coords, iv, dx, dy);
      }
    return out;
}

static rl2RingPtr
rl2CreateRing (int vert)
{
/* ring object constructor */
    rl2RingPtr p = malloc (sizeof (rl2Ring));
    p->coords = malloc (sizeof (double) * (vert * 2));
    p->points = vert;
    p->minx = DBL_MAX;
    p->miny = DBL_MAX;
    p->maxx = 0.0 - DBL_MAX;
    p->maxy = 0.0 - DBL_MAX;
    p->next = NULL;
    return p;
}

RL2_PRIVATE rl2RingPtr
rl2_ring_to_image (rl2RingPtr ring, int height, double minx, double miny,
		   double x_res, double y_res)
{
/* creating a Ring in image coordinates */
    rl2RingPtr out = NULL;
    int iv;
    double x;
    double y;
    double dx;
    double dy;

    if (ring == NULL)
	return NULL;
    out = rl2CreateRing (ring->points);
    if (out == NULL)
	return out;
    for (iv = 0; iv < ring->points; iv++)
      {
	  /* populating the X and Y arrays */
	  rl2GetPoint (ring->coords, iv, &x, &y);
	  dx = (x - minx) / x_res;
	  dy = (double) height - ((y - miny) / y_res);
	  rl2SetPoint (out->coords, iv, dx, dy);
      }
    return out;
}

RL2_PRIVATE void
rl2DestroyRing (rl2RingPtr ptr)
{
/* ring object destructor */
    if (ptr)
      {
	  if (ptr->coords)
	      free (ptr->coords);
................................................................................
    else
	p->interiors = malloc (sizeof (rl2Ring) * excl);
    for (ind = 0; ind < p->num_interiors; ind++)
      {
	  pP = p->interiors + ind;
	  pP->points = 0;
	  pP->coords = NULL;
	  pP->minx = DBL_MAX;
	  pP->miny = DBL_MAX;
	  pP->maxx = 0.0 - DBL_MAX;
	  pP->maxy = 0.0 - DBL_MAX;
      }
    return p;
}

static void
rl2DestroyPolygon (rl2PolygonPtr p)
{
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  *offset += 16;
      }
}

static void
rl2ParseLineZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
	       int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  *offset += 24;
      }
}

static void
rl2ParseLineM (rl2GeometryPtr geom, const unsigned char *blob, int size,
	       int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  *offset += 24;
      }
}

static void
rl2ParseLineZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		int endian, int endian_arch, int *offset)
................................................................................
	return;
    line = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
	  y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  *offset += 32;
      }
}

static rl2PolygonPtr
rl2AddPolygonToGeometry (rl2GeometryPtr p, int vert, int interiors)
{
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 16;
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
	    }
      }
}

static void
rl2ParsePolygonZ (rl2GeometryPtr geom, const unsigned char *blob, int size,
		  int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 24;
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
	    }
      }
}

static void
rl2ParsePolygonM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		  int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 24;
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
	    }
      }
}

static void
rl2ParsePolygonZM (rl2GeometryPtr geom, const unsigned char *blob, int size,
		   int endian, int endian_arch, int *offset)
................................................................................
	      ring = rl2AddInteriorRing (polyg, ib - 1, nverts);
	  for (iv = 0; iv < nverts; iv++)
	    {
		x = rl2GeomImport64 (blob + *offset, endian, endian_arch);
		y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch);
		*offset += 32;
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
	    }
      }
}

static void
rl2ParseCompressedLine (rl2GeometryPtr geom, const unsigned char *blob,
			int size, int endian, int endian_arch, int *offset)
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 8;
	    }
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineZ (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 12;
	    }
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 16;
	    }
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedLineZM (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
				       endian_arch);
		x = last_x + fx;
		y = last_y + fy;
		*offset += 20;
	    }
	  rl2SetPoint (line->coords, iv, x, y);
	  if (x < line->minx)
	      line->minx = x;
	  if (x > line->maxx)
	      line->maxx = x;
	  if (y < line->miny)
	      line->miny = y;
	  if (y > line->maxy)
	      line->maxy = y;
	  last_x = x;
	  last_y = y;
      }
}

static void
rl2ParseCompressedPolygon (rl2GeometryPtr geom, const unsigned char *blob,
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 8;
		  }
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 12;
		  }
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 16;
		  }
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
		      fy = rl2GeomImportF32 (blob + (*offset + 4), endian,
					     endian_arch);
		      x = last_x + fx;
		      y = last_y + fy;
		      *offset += 20;
		  }
		rl2SetPoint (ring->coords, iv, x, y);
		if (x < ring->minx)
		    ring->minx = x;
		if (x > ring->maxx)
		    ring->maxx = x;
		if (y < ring->miny)
		    ring->miny = y;
		if (y > ring->maxy)
		    ring->maxy = y;
		last_x = x;
		last_y = y;
	    }
      }
}

static void
................................................................................
				   offset);
		break;
	    case GAIA_COMPRESSED_LINESTRING:
		rl2ParseCompressedLine (geom, blob, size, endian, endian_arch,
					offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGZ:
		rl2ParseCompressedLineZ (geom, blob, size, endian,
					 endian_arch, offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGM:
		rl2ParseCompressedLineM (geom, blob, size, endian,
					 endian_arch, offset);
		break;
	    case GAIA_COMPRESSED_LINESTRINGZM:
		rl2ParseCompressedLineZM (geom, blob, size, endian,
					  endian_arch, offset);
		break;
	    case GAIA_COMPRESSED_POLYGON:
		rl2ParseCompressedPolygon (geom, blob, size, endian,
					   endian_arch, offset);
		break;
	    case GAIA_COMPRESSED_POLYGONZ:
		rl2ParseCompressedPolygonZ (geom, blob, size, endian,
................................................................................
			    &offset);
	  break;
      case GAIA_POLYGONZM:
	  rl2ParsePolygonZM (geom, blob, size, little_endian, endian_arch,
			     &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRING:
	  rl2ParseCompressedLine (geom, blob, size, little_endian,
				  endian_arch, &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGZ:
	  rl2ParseCompressedLineZ (geom, blob, size, little_endian,
				   endian_arch, &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGM:
	  rl2ParseCompressedLineM (geom, blob, size, little_endian,
				   endian_arch, &offset);
	  break;
      case GAIA_COMPRESSED_LINESTRINGZM:
	  rl2ParseCompressedLineZM (geom, blob, size, little_endian,
				    endian_arch, &offset);
	  break;
      case GAIA_COMPRESSED_POLYGON:
	  rl2ParseCompressedPolygon (geom, blob, size, little_endian,
................................................................................
	  rl2GeomExport64 (ptr, x, 1, endian_arch);	/* X - exterior ring */
	  rl2GeomExport64 (ptr + 8, y, 1, endian_arch);	/* Y - exterior ring */
	  ptr += 16;
      }
    *ptr = GAIA_MARK_END;	/* END signature */
    return 1;
}

RL2_PRIVATE int
rl2_serialize_ring_as_linestring (rl2RingPtr ring, unsigned char **result,
				  int *size)
{
/* serializing a BLOB Geometry - polygon ring as linestring */
    int iv;
    unsigned char *ptr;
    int endian_arch = rl2GeomEndianArch ();
    double minx = DBL_MAX;
    double maxx = 0.0 - DBL_MAX;
    double miny = DBL_MAX;
    double maxy = 0.0 - DBL_MAX;
    double x;
    double y;

    *result = NULL;
    *size = 0;
    if (ring == NULL)
	return 0;

/* computing the MBR */
    for (iv = 0; iv < ring->points; iv++)
      {
	  rl2GetPoint (ring->coords, iv, &x, &y);
	  if (x < minx)
	      minx = x;
	  if (x > maxx)
	      maxx = x;
	  if (y < miny)
	      miny = y;
	  if (y > maxy)
	      maxy = y;
      }
/* computing the size of BLOB */
    *size = 44;			/* header size */
    *size += (4 + ((sizeof (double) * 2) * ring->points));	/* # points + [x,y] for each vertex */
    *result = malloc (*size);
    ptr = *result;
/* building the BLOB */
    *ptr = GAIA_MARK_START;	/* START signature */
    *(ptr + 1) = GAIA_LITTLE_ENDIAN;	/* byte ordering */
    rl2GeomExport32 (ptr + 2, 4326, 1, endian_arch);	/* the SRID */
    rl2GeomExport64 (ptr + 6, minx, 1, endian_arch);	/* MBR - minimum X */
    rl2GeomExport64 (ptr + 14, miny, 1, endian_arch);	/* MBR - minimum Y */
    rl2GeomExport64 (ptr + 22, maxx, 1, endian_arch);	/* MBR - maximum X */
    rl2GeomExport64 (ptr + 30, maxy, 1, endian_arch);	/* MBR - maximum Y */
    *(ptr + 38) = GAIA_MARK_MBR;	/* MBR signature */
    rl2GeomExport32 (ptr + 39, GAIA_LINESTRING, 1, endian_arch);	/* class LINESTRING */
    rl2GeomExport32 (ptr + 43, ring->points, 1, endian_arch);	/* # points */
    ptr += 47;
    for (iv = 0; iv < ring->points; iv++)
      {
	  rl2GetPoint (ring->coords, iv, &x, &y);
	  rl2GeomExport64 (ptr, x, 1, endian_arch);
	  rl2GeomExport64 (ptr + 8, y, 1, endian_arch);
	  ptr += 16;
      }
    *ptr = GAIA_MARK_END;	/* END signature */
    return 1;
}

RL2_PRIVATE rl2GeometryPtr
rl2_curve_from_XY (int points, double *x, double *y)
{
/* creating a Linestring Geometry from X,Y coordinate arrays */
    rl2GeometryPtr geom = NULL;
    rl2LinestringPtr ln;
................................................................................
    int iv;

    if (points <= 0 || x == NULL || y == NULL)
	return 0;
    geom = rl2CreateGeometry ();
    ln = rl2AddLinestringToGeometry (geom, points);
    for (iv = 0; iv < points; iv++)
      {
	  rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv));
	  if (*(x + iv) < ln->minx)
	      ln->minx = *(x + iv);
	  if (*(x + iv) > ln->maxx)
	      ln->maxx = *(x + iv);
	  if (*(y + iv) < ln->miny)
	      ln->miny = *(y + iv);
	  if (*(y + iv) > ln->maxy)
	      ln->maxy = *(y + iv);
      }
    return geom;
}

RL2_PRIVATE double
rl2_compute_curve_length (rl2GeometryPtr geom)
{
/* computing the total length of some curve (single linestring expected) */
................................................................................
    ln_out = rl2AddLinestringToGeometry (out, ln_in->points);
    for (iv = 0; iv < ln_in->points; iv++)
      {
	  double x;
	  double y;
	  rl2GetPoint (ln_in->coords, iv, &x, &y);
	  rl2SetPoint (ln_out->coords, iv, x, y);
	  if (x < ln_out->minx)
	      ln_out->minx = x;
	  if (x > ln_out->maxx)
	      ln_out->maxx = x;
	  if (y < ln_out->miny)
	      ln_out->miny = y;
	  if (y > ln_out->maxy)
	      ln_out->maxy = y;
      }
    return out;
}

RL2_PRIVATE rl2GeometryPtr
rl2_clone_linestring (rl2LinestringPtr in)
{
................................................................................
    ln_out = rl2AddLinestringToGeometry (out, in->points);
    for (iv = 0; iv < in->points; iv++)
      {
	  double x;
	  double y;
	  rl2GetPoint (in->coords, iv, &x, &y);
	  rl2SetPoint (ln_out->coords, iv, x, y);
	  if (x < ln_out->minx)
	      ln_out->minx = x;
	  if (x > ln_out->maxx)
	      ln_out->maxx = x;
	  if (y < ln_out->miny)
	      ln_out->miny = y;
	  if (y > ln_out->maxy)
	      ln_out->maxy = y;
      }
    return out;
}

RL2_PRIVATE rl2GeometryPtr
rl2_build_circle (double cx, double cy, double radius)
{
/* creating a circle */
    int iv = 0;
    double pi = 3.14159265359;
    double rads;
    double x;
    double y;
    rl2LinestringPtr ln;
    rl2GeometryPtr out = rl2CreateGeometry ();
    ln = rl2AddLinestringToGeometry (out, 129);
    for (rads = 0.0; rads <= (pi * 2.0); rads += pi / 64.0)
      {
	  x = cx + (radius * cos (rads));
	  y = cy + (radius * sin (rads));
	  rl2SetPoint (ln->coords, iv, x, y);
	  if (x < ln->minx)
	      ln->minx = x;
	  if (x > ln->maxx)
	      ln->maxx = x;
	  if (y < ln->miny)
	      ln->miny = y;
	  if (y > ln->maxy)
	      ln->maxy = y;
	  iv++;
      }
    /* closure */
    rl2GetPoint (ln->coords, 0, &x, &y);
    rl2SetPoint (ln->coords, 128, x, y);
    return out;
}

Changes to src/rl2auxrender.c.

288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303
...
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
...
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
...
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
...
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
...
838
839
840
841
842
843
844
845
846

847
848
849
850
851
852
853
...
862
863
864
865
866
867
868
869
870

871
872
873
874
875
876
877
...
951
952
953
954
955
956
957
958

959
960
961
962
963
964
965
966
...
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
....
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
....
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546
1547
1548
....
1672
1673
1674
1675
1676
1677
1678


1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
....
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
















1718
















1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
....
1745
1746
1747
1748
1749
1750
1751
1752
1753

1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781

1782
1783
1784
1785
1786
1787

1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852

1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941

1942
1943
1944
1945
1946
1947
1948
1949
....
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
....
1985
1986
1987
1988
1989
1990
1991






































1992
1993
1994

1995
1996



































1997
1998
1999
2000










2001
2002
2003
2004
2005
2006
2007
....
2028
2029
2030
2031
2032
2033
2034
2035





































2036
2037
2038










2039


























2040
2041

2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057

2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075

2076
2077
2078
2079
2080
2081
2082
2083

2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096

2097
2098

2099
2100
2101
2102
2103
2104
2105
....
2151
2152
2153
2154
2155
2156
2157

2158

2159

2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178






2179
2180
2181












2182
2183







2184

2185
2186
2187




































2188
2189
2190
2191
2192



2193
2194

2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221

2222
2223

2224
2225

2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239

2240
2241

2242

2243
2244

2245

2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271



2272
2273

2274

2275
2276

2277

2278
2279

2280

2281
2282

2283

2284
2285

2286

2287
2288

2289

2290
2291

2292

2293
2294

2295

2296
2297

2298

2299
2300

2301

2302
2303

2304

2305
2306
2307
2308
2309



2310
2311

2312

2313
2314


2315
2316

2317

2318
2319

2320

2321
2322

2323
2324
2325

2326

2327
2328

2329

2330
2331


2332
2333

2334

2335
2336

2337

2338
2339

2340
2341
2342
2343
2344
2345
2346



2347
2348

2349

2350
2351

2352

2353
2354

2355

2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375







2376











2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
....
2393
2394
2395
2396
2397
2398
2399
















2400
2401
2402
2403

2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
....
2421
2422
2423
2424
2425
2426
2427
2428





2429
2430
2431
2432

2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444



2445
2446
2447
2448
2449
2450
2451
2452



2453
2454
2455





























2456
2457
2458
2459
2460
2461
2462
....
2464
2465
2466
2467
2468
2469
2470





2471
2472
2473
2474
2475
2476
2477
....
2547
2548
2549
2550
2551
2552
2553


2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602

2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622

2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638

2639
2640
2641
2642
2643
















2644
2645
2646
2647

2648
2649
2650
2651
2652
2653
2654
2655
....
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
....
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820















2821
2822
2823
2824
2825
2826
2827
....
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
....
2962
2963
2964
2965
2966
2967
2968







































2969
2970
2971
2972
2973
2974
2975
....
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
....
3061
3062
3063
3064
3065
3066
3067
3068

3069
3070
3071
3072
3073
3074
3075
....
3108
3109
3110
3111
3112
3113
3114
3115

3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
































































































































































































































































































































3126










































































































































































3127
3128

3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142












3143
3144
3145
3146
3147
3148
3149
....
3182
3183
3184
3185
3186
3187
3188




3189









3190
3191

3192
3193
3194
3195
3196
3197
3198
....
3223
3224
3225
3226
3227
3228
3229

3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242

3243
3244
3245
3246























3247
3248
3249
3250





3251
3252
3253
3254
3255




3256
3257
3258
3259
3260
3261
3262
3263



3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278


































3279
3280
3281
3282









3283
3284
3285
3286



3287
3288
3289
3290
3291
3292
3293
3294
3295
3296

































3297
3298
3299
3300
3301
3302
3303






















3304
3305
3306
3307
3308
3309
3310
3311






















































3312
3313
3314
3315
3316
3317

3318
3319








3320





























3321
3322






3323
3324
3325
3326
3327


3328

3329
3330
3331
3332
3333
3334

3335
3336
3337
3338
3339
3340
3341
3342
....
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429

3430
3431

3432
3433
3434
3435
3436
3437
3438
....
3442
3443
3444
3445
3446
3447
3448


3449
3450
3451
3452
3453
3454
3455
3456


3457
3458
3459

3460

3461

3462

3463
3464


3465
3466
3467
3468
3469
3470
3471
















































































		  }
	    }
      }
}

static void
copy_palette (unsigned char *rgba, unsigned int width, unsigned int height,
	      unsigned char *inbuf, rl2PalettePtr palette, unsigned char bg_red,

	      unsigned char bg_green, unsigned char bg_blue)
{
/* copying from Palette to RGBA */
    unsigned int x;
    unsigned int y;
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
    unsigned char *p_in = inbuf;
    unsigned char *p_out = rgba;
................................................................................
	goto error;

    if (aux->base_width == aux->width && aux->base_height == aux->height)
      {
	  if (aux->out_pixel == RL2_PIXEL_MONOCHROME)
	    {
		/* Monochrome */
		copy_monochrome (aggreg_rgba, aux->base_width, aux->base_height,
				 aux->outbuf);
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
	    {
		/* Palette */
		copy_palette (aggreg_rgba, aux->base_width, aux->base_height,
			      aux->outbuf, aux->palette, aux->bg_red,
			      aux->bg_green, aux->bg_blue);
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
	    {
		/* Grayscale */
		copy_grayscale (aggreg_rgba, aux->base_width, aux->base_height,
				aux->outbuf, aux->bg_red);
		aux->outbuf = NULL;
	    }
	  else
	    {
		/* RGB */
		copy_rgb (aggreg_rgba, aux->base_width, aux->base_height,
			  aux->outbuf, aux->bg_red, aux->bg_green,
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_monochrome_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
			   &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_palette_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->palette, aux->format_id,
			   aux->quality, &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_grayscale_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
			   &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_rgb_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id, aux->quality,
			   &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
	    {
		/* Monochrome - upsampled */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_palette_transparent
			  (aux->base_width, aux->base_height, aux->outbuf,
			   aux->palette, rgba, aux->bg_red, aux->bg_green,
			   aux->bg_blue))
			{
................................................................................
	    }
	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
	    {
		/* Grayscale */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_grayscale_transparent
			  (aux->base_width, aux->base_height, aux->outbuf, rgba,
			   aux->bg_red))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		else
		  {
................................................................................
	    }
	  else
	    {
		/* RGB */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_rgb_transparent
			  (aux->base_width, aux->base_height, aux->outbuf, rgba,
			   aux->bg_red, aux->bg_green, aux->bg_blue))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		else
		  {
................................................................................
	    {
		/* Grayscale or Monochrome upsampled */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (alpha == NULL)
			  goto error;
		      if (!get_payload_from_gray_rgba_transparent
			  (aux->width, aux->height, rgb, alpha, aux->format_id,
			   aux->quality, &image, &image_size, aux->opacity))

			  goto error;
		  }
		else
		  {
		      if (alpha != NULL)
			  free (alpha);
		      alpha = NULL;
................................................................................
	    {
		/* RGB */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (alpha == NULL)
			  goto error;
		      if (!get_payload_from_rgb_rgba_transparent
			  (aux->width, aux->height, rgb, alpha, aux->format_id,
			   aux->quality, &image, &image_size, aux->opacity, 0))

			  goto error;
		  }
		else
		  {
		      if (alpha != NULL)
			  free (alpha);
		      alpha = NULL;
................................................................................
	free (rgb);
    if (alpha != NULL)
	free (alpha);
    return 0;
}

static int
aux_shaded_relief_mask (struct aux_renderer *aux, double relief_factor,

			unsigned char **shaded_relief)
{
/* attempting to create a Shaded Relief brightness-only mask */
    rl2GraphicsBitmapPtr base_img = NULL;
    rl2GraphicsContextPtr ctx = NULL;
    float *shr_mask;
    int shr_size;
    const char *coverage;
................................................................................
    *shaded_relief = NULL;
    coverage = rl2_get_coverage_name (aux->coverage);
    if (coverage == NULL)
	return 0;
    scale_factor = rl2_get_shaded_relief_scale_factor (aux->sqlite, coverage);

    if (rl2_build_shaded_relief_mask
	(aux->sqlite, aux->max_threads, aux->coverage, relief_factor,
	 scale_factor, aux->base_width, aux->base_height, aux->minx, aux->miny,
	 aux->maxx, aux->maxy, aux->xx_res, aux->yy_res, &shr_mask,
	 &shr_size) != RL2_OK)
	return 0;

/* allocating the RGBA buffer */
    rgba = malloc (aux->base_width * aux->base_height * 4);
    if (rgba == NULL)
	return 0;

................................................................................
	  aux.out_pixel = out_pixel;
	  if (is_shaded_relief)
	    {
		/* requesting a shaded relief mask */
		if (shaded_relief_mask != NULL)
		    free (shaded_relief_mask);
		if (!aux_shaded_relief_mask
		    (&aux, symbolizer->reliefFactor, &shaded_relief_mask))
		    goto error;
	    }
	  else
	    {
		/* rendering an image */
		if (!aux_render_composed_image (&aux, rgba))
		    goto error;
................................................................................
RL2_DECLARE int
rl2_get_raw_raster_data_mixed_resolutions (sqlite3 * handle, int max_threads,
					   rl2CoveragePtr cvg,
					   unsigned int width,
					   unsigned int height, double minx,
					   double miny, double maxx,
					   double maxy, double x_res,

					   double y_res, unsigned char **buffer,
					   int *buf_size,
					   rl2PalettePtr * palette,
					   unsigned char *out_pixel,
					   unsigned char bg_red,
					   unsigned char bg_green,
					   unsigned char bg_blue,
					   rl2RasterSymbolizerPtr style,
................................................................................
		double xx_res;
		double yy_res;
		int level_id;
		int scale;
		int xscale;
		unsigned int w;
		unsigned int h;


		int base_x;
		int base_y;
		unsigned char *bufpix = NULL;
		int bufpix_size;
		double img_res_x = (maxx - minx) / (double) width;
		double img_res_y = (maxy - miny) / (double) height;
		double mnx = minx;
		double mny = miny;
		double mxx = maxx;
		double mxy = maxy;
		if (section_id > 3)
		    continue;
		/* normalizing the visible portion of the Section */
		if (mnx < section_minx)
		    mnx = section_minx;
		if (mny < section_miny)
		    mny = section_miny;
		if (mxx > section_maxx)
		    mxx = section_maxx;
................................................................................
		if (((double) w * xx_res) < (mxx - mnx))
		    w++;
		h = (unsigned int) ((mxy - mny) / yy_res);
		if (((double) h * yy_res) < (mxy - mny))
		    h++;
		base_x = (int) ((mnx - minx) / img_res_x);
		base_y = (int) ((maxy - mxy) / img_res_y);

		if (rl2_get_raw_raster_data_common
		    (handle, max_threads, cvg, 1, section_id, w, h, mnx, mny,
		     mxx, mxy, xx_res, yy_res, &bufpix, &bufpix_size, palette,
		     *out_pixel, no_data, xstyle, stats) != RL2_OK)
		    goto error;
















		if (*out_pixel == RL2_PIXEL_RGB)
















		    do_copy_rgb (outbuf, bufpix, width, height, w, h, base_x,
				 base_y, bg_red, bg_green, bg_blue);
		else
		    do_copy_gray (outbuf, bufpix, width, height, w, h, base_x,
				  base_y, bg_red);
		free (bufpix);
	    }
	  else
	    {
		fprintf (stderr, "SQL error: %s\n%s\n", sql,
			 sqlite3_errmsg (handle));
................................................................................
    if (no_data != NULL)
	rl2_destroy_pixel (no_data);
    if (outbuf != NULL)
	free (outbuf);
    return RL2_ERROR;
}

static rl2GraphicsPatternPtr
load_external_graphic_from_dbms (sqlite3 * handle, rl2PrivGraphicPtr graphic)

{
/* attempting to load an External Graphic from the DBMS */
    int ret;
    sqlite3_stmt *stmt = NULL;
    const char *sql;
    const char *xlink_href = NULL;
    rl2GraphicsPatternPtr pattern = NULL;
    rl2PrivGraphicItemPtr item;

    if (graphic == NULL)
	return NULL;
    /* searching for an xlink_href pseudo-URL */
    item = graphic->first;
    while (item != NULL)
      {
	  if (item->type == RL2_EXTERNAL_GRAPHIC && item->item != NULL)
	    {
		rl2PrivExternalGraphicPtr ext =
		    (rl2PrivExternalGraphicPtr) (item->item);
		if (ext->xlink_href != NULL)
		  {
		      xlink_href = ext->xlink_href;
		      break;
		  }
	    }
	  item = item->next;
      }
    if (xlink_href == NULL)

	return NULL;

    sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics "
	"WHERE xlink_href = ?";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)

	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		rl2RasterPtr raster = NULL;
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB
		    && sqlite3_column_type (stmt, 1) == SQLITE_TEXT)
		  {
		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
		      int blob_sz = sqlite3_column_bytes (stmt, 0);
		      const char *mime_type =
			  (const char *) sqlite3_column_text (stmt, 1);
		      if (strcmp (mime_type, "image/gif") == 0)
			  raster = rl2_raster_from_gif (blob, blob_sz);
		      if (strcmp (mime_type, "image/png") == 0)
			  raster = rl2_raster_from_png (blob, blob_sz, 1);
		      if (strcmp (mime_type, "image/jpeg") == 0)
			  raster = rl2_raster_from_jpeg (blob, blob_sz);
		      if (strcmp (mime_type, "image/tiff") == 0)
			  raster = rl2_raster_from_tiff (blob, blob_sz);
		  }
		if (raster != NULL)
		  {
		      unsigned char *rgba;
		      int rgba_sz;
		      unsigned int width;
		      unsigned int height;
		      if (rl2_get_raster_size (raster, &width, &height) !=
			  RL2_OK)
			{
			    rl2_destroy_raster (raster);
			    goto error;
			}
		      if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) !=
			  RL2_OK)
			{
			    rl2_destroy_raster (raster);
			    goto error;
			}
		      pattern =
			  rl2_graph_create_pattern (rgba, width, height, 0);
		      rl2_destroy_raster (raster);
		  }
	    }
	  else
	    {
		fprintf (stderr, "SQL error: %s\n%s\n", sql,
			 sqlite3_errmsg (handle));
		goto error;
	    }
      }
    return pattern;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);

    return NULL;
}

static rl2GraphicsBitmapPtr
load_external_bitmap_from_dbms (sqlite3 * handle, const char *xlink_href)
{
/* attempting to load an External Graphic from the DBMS */
    int ret;
    sqlite3_stmt *stmt = NULL;
    const char *sql;
    rl2GraphicsBitmapPtr bitmap = NULL;

    if (xlink_href == NULL)
	return NULL;

    sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics "
	"WHERE xlink_href = ?";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		rl2RasterPtr raster = NULL;
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB
		    && sqlite3_column_type (stmt, 1) == SQLITE_TEXT)
		  {
		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
		      int blob_sz = sqlite3_column_bytes (stmt, 0);
		      const char *mime_type =
			  (const char *) sqlite3_column_text (stmt, 1);
		      if (strcmp (mime_type, "image/gif") == 0)
			  raster = rl2_raster_from_gif (blob, blob_sz);
		      if (strcmp (mime_type, "image/png") == 0)
			  raster = rl2_raster_from_png (blob, blob_sz, 1);
		      if (strcmp (mime_type, "image/jpeg") == 0)
			  raster = rl2_raster_from_jpeg (blob, blob_sz);
		      if (strcmp (mime_type, "image/tiff") == 0)
			  raster = rl2_raster_from_tiff (blob, blob_sz);
		  }
		if (raster != NULL)
		  {
		      unsigned char *rgba;
		      int rgba_sz;
		      unsigned int width;
		      unsigned int height;
		      if (rl2_get_raster_size (raster, &width, &height) !=
			  RL2_OK)
			{
			    rl2_destroy_raster (raster);
			    goto error;
			}
		      if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) !=
			  RL2_OK)
			{
			    rl2_destroy_raster (raster);
			    goto error;
			}
		      bitmap = rl2_graph_create_bitmap (rgba, width, height);
		      rl2_destroy_raster (raster);
		  }
	    }
	  else
	    {
		fprintf (stderr, "SQL error: %s\n%s\n", sql,
			 sqlite3_errmsg (handle));
		goto error;
	    }
      }
    return bitmap;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return NULL;
}

static void
draw_points (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	     rl2PrivVectorSymbolizerPtr sym, int height, double minx,

	     double miny, double x_res, double y_res, rl2GeometryPtr geom)
{
/* drawing Point-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    rl2PointPtr point;

    item = sym->first;
    while (item != NULL)
................................................................................
		      unsigned char well_known_type;
		      int fill = 0;
		      int stroke = 0;
		      int pen_cap;
		      int pen_join;
		      double opacity;
		      unsigned char norm_opacity;
		      rl2GraphicsBitmapPtr pattern = NULL;
		      rl2GraphicsPatternPtr pattern_fill = NULL;
		      rl2GraphicsPatternPtr pattern_stroke = NULL;

		      if (graphic->type == RL2_MARK_GRAPHIC)
			{
			    rl2PrivMarkPtr mark =
				(rl2PrivMarkPtr) (graphic->item);
................................................................................
				  well_known_type = mark->well_known_type;
				  is_mark = 1;
				  if (mark->fill != NULL)
				    {
					if (mark->fill->graphic != NULL)
					  {
					      /* external Graphic fill */






































					      pattern_fill =
						  load_external_graphic_from_dbms
						  (handle, mark->fill->graphic);

					      if (pattern_fill != NULL)
						{



































						    rl2_graph_set_pattern_brush
							(ctx, pattern_fill);
						    fill = 1;
						}










					  }
					else
					  {
					      /* solid RGB fill */
					      if (gr->opacity <= 0.0)
						  norm_opacity = 0;
					      else if (gr->opacity >= 1.0)
................................................................................
					      fill = 1;
					  }
				    }
				  if (mark->stroke != NULL)
				    {
					if (mark->stroke->graphic != NULL)
					  {
					      /* external Graphic stroke */





































					      pattern_stroke =
						  load_external_graphic_from_dbms
						  (handle,










						   mark->stroke->graphic);


























					      if (pattern_stroke != NULL)
						{

						    switch (mark->
							    stroke->linecap)
						      {
						      case RL2_STROKE_LINECAP_ROUND:
							  pen_cap =
							      RL2_PEN_CAP_ROUND;
							  break;
						      case RL2_STROKE_LINECAP_SQUARE:
							  pen_cap =
							      RL2_PEN_CAP_SQUARE;
							  break;
						      default:
							  pen_cap =
							      RL2_PEN_CAP_BUTT;
							  break;
						      };

						    switch (mark->
							    stroke->linejoin)
						      {
						      case RL2_STROKE_LINEJOIN_BEVEL:
							  pen_join =
							      RL2_PEN_JOIN_BEVEL;
							  break;
						      case RL2_STROKE_LINEJOIN_ROUND:
							  pen_join =
							      RL2_PEN_JOIN_ROUND;
							  break;
						      default:
							  pen_join =
							      RL2_PEN_JOIN_MITER;
							  break;
						      };
						    if (mark->
							stroke->dash_count > 0

							&& mark->
							stroke->dash_list !=
							NULL)
							rl2_graph_set_pattern_dashed_pen
							    (ctx,
							     pattern_stroke,
							     mark->
							     stroke->width,

							     pen_cap, pen_join,
							     mark->
							     stroke->dash_count,
							     mark->
							     stroke->dash_list,
							     mark->
							     stroke->dash_offset);
						    else
							rl2_graph_set_pattern_solid_pen
							    (ctx,
							     pattern_stroke,
							     mark->
							     stroke->width,

							     pen_cap, pen_join);
						    stroke = 1;

						}
					  }
					else
					  {
					      /* solid RGB stroke */
					      if (gr->opacity <= 0.0)
						  norm_opacity = 0;
................................................................................
									    mark->stroke->red,
									    mark->stroke->green,
									    mark->stroke->blue,
									    norm_opacity,
									    mark->stroke->width,
									    pen_cap,
									    pen_join,

									    mark->stroke->dash_count,

									    mark->stroke->dash_list,

									    mark->stroke->dash_offset);
					      else
						  rl2_graph_set_solid_pen (ctx,
									   mark->stroke->red,
									   mark->stroke->green,
									   mark->stroke->blue,
									   norm_opacity,
									   mark->stroke->width,
									   pen_cap,
									   pen_join);
					      stroke = 1;
					  }
				    }
			      }
			}
		      if (graphic->type == RL2_EXTERNAL_GRAPHIC)
			{
			    rl2PrivExternalGraphicPtr ext =
				(rl2PrivExternalGraphicPtr) (graphic->item);






			    if (ext != NULL)
			      {
				  is_external = 1;












				  pattern =
				      load_external_bitmap_from_dbms (handle,







								      ext->xlink_href);

			      }
			}





































		      /* actual Point rendering */
		      point = geom->first_point;
		      while (point)
			{
			    /* drawing a POINT */



			    double x = (point->x - minx) / x_res;
			    double y =

				(double) height - ((point->y - miny) / y_res);
			    double size2 = gr->size / 2.0;
			    double size4 = gr->size / 4.0;
			    double size6 = gr->size / 6.0;
			    double size13 = gr->size / 3.0;
			    double size23 = (gr->size / 3.0) * 2.0;
			    int i;
			    double rads;
			    if (size2 <= 0.0)
				size2 = 1.0;
			    if (size4 <= 0.0)
				size4 = 1.0;
			    if (size6 <= 0.0)
				size6 = 1.0;
			    if (size13 <= 0.0)
				size13 = 1.0;
			    if (size23 <= 0.0)
				size23 = 1.0;
			    if (is_mark)
			      {
				  /* drawing a well-known Mark */
				  switch (well_known_type)
				    {
				    case RL2_GRAPHIC_MARK_CIRCLE:
					rads = 0.0;
					for (i = 0; i < 32; i++)
					  {

					      double tic = 6.28318530718 / 32.0;
					      double cx =

						  x + (size2 * sin (rads));
					      double cy =

						  y + (size2 * cos (rads));
					      if (i == 0)
						  rl2_graph_move_to_point (ctx,
									   cx,
									   cy);
					      else
						  rl2_graph_add_line_to_path
						      (ctx, cx, cy);
					      rads += tic;
					  }
					rl2_graph_close_subpath (ctx);
					break;
				    case RL2_GRAPHIC_MARK_TRIANGLE:
					rl2_graph_move_to_point (ctx, x,

								 y - size23);
					rl2_graph_add_line_to_path (ctx,

								    x - size2,

								    y + size13);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y + size13);
					rl2_graph_close_subpath (ctx);
					break;
				    case RL2_GRAPHIC_MARK_STAR:
					rads = 3.14159265359;
					for (i = 0; i < 10; i++)
					  {
					      double tic =
						  (i % 2) ? size6 : size2;
					      double cx =
						  x + (tic * sin (rads));
					      double cy =
						  y + (tic * cos (rads));
					      if (i == 0)
						  rl2_graph_move_to_point (ctx,
									   cx,
									   cy);
					      else
						  rl2_graph_add_line_to_path
						      (ctx, cx, cy);
					      rads += 0.628318530718;
					  }
					rl2_graph_close_subpath (ctx);
					break;
				    case RL2_GRAPHIC_MARK_CROSS:
					rl2_graph_move_to_point (ctx, x - size6,



								 y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size6,

								    y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size6,

								    y - size6);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y - size6);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y + size6);
					rl2_graph_add_line_to_path (ctx,

								    x + size6,

								    y + size6);
					rl2_graph_add_line_to_path (ctx,

								    x + size6,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size6,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size6,

								    y + size6);
					rl2_graph_add_line_to_path (ctx,

								    x - size2,

								    y + size6);
					rl2_graph_add_line_to_path (ctx,

								    x - size2,

								    y - size6);
					rl2_graph_add_line_to_path (ctx,

								    x - size6,

								    y - size6);
					rl2_graph_close_subpath (ctx);
					break;
				    case RL2_GRAPHIC_MARK_X:
					rl2_graph_move_to_point (ctx, x - size2,



								 y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size4,

								    y - size2);
					rl2_graph_add_line_to_path (ctx, x,


								    y - size6);
					rl2_graph_add_line_to_path (ctx,

								    x + size6,

								    y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size4,
								    y);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size4,

								    y + size2);
					rl2_graph_add_line_to_path (ctx, x,


								    y + size6);
					rl2_graph_add_line_to_path (ctx,

								    x - size6,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size2,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size4,
								    y);
					rl2_graph_close_subpath (ctx);
					break;
				    case RL2_GRAPHIC_MARK_SQUARE:
				    default:
					rl2_graph_move_to_point (ctx, x - size2,



								 y - size2);
					rl2_graph_add_line_to_path (ctx,

								    x - size2,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y + size2);
					rl2_graph_add_line_to_path (ctx,

								    x + size2,

								    y - size2);
					rl2_graph_close_subpath (ctx);
					break;
				    };
				  if (fill)
				    {
					if (stroke)
					    rl2_graph_fill_path (ctx,
								 RL2_PRESERVE_PATH);
					else
					    rl2_graph_fill_path (ctx,
								 RL2_CLEAR_PATH);
				    }
				  if (stroke)
				      rl2_graph_stroke_path (ctx,
							     RL2_CLEAR_PATH);
			      }
			    if (is_external && pattern != NULL)
			      {
				  /* drawing an External Graphic bitmap */







				  rl2_graph_draw_bitmap (ctx, pattern, x, y);











			      }
			    point = point->next;
			}

		      /* releasing Patterns */
		      if (pattern != NULL)
			  rl2_graph_destroy_bitmap (pattern);
		      if (pattern_fill != NULL)
			{
			    rl2_graph_release_pattern_pen (ctx);
			    rl2_graph_destroy_pattern (pattern_fill);
			}
		      if (pattern_stroke != NULL)
			{
................................................................................
			}
		      graphic = graphic->next;
		  }
	    }
	  item = item->next;
      }
}

















static void
draw_lines (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	    rl2PrivVectorSymbolizerPtr sym, int height, double minx,

	    double miny, double x_res, double y_res, rl2GeometryPtr geom)
{
/* drawing Linear-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    int pen_cap;
    int pen_join;
    double opacity;
    unsigned char norm_opacity;
    rl2LinestringPtr line;
    rl2GraphicsPatternPtr pattern = NULL;
    rl2PrivMultiStrokePtr multi_stroke = rl2_create_multi_stroke ();

    item = sym->first;
................................................................................
		rl2PrivLineSymbolizerPtr line_sym =
		    (rl2PrivLineSymbolizerPtr) (item->symbolizer);
		if (line_sym->stroke != NULL)
		  {
		      if (line_sym->stroke->graphic != NULL)
			{
			    /* external Graphic stroke */
			    pattern = load_external_graphic_from_dbms (handle,





								       line_sym->stroke->graphic);
			    if (pattern != NULL)
			      {
				  switch (line_sym->stroke->linecap)

				    {
				    case RL2_STROKE_LINECAP_ROUND:
					pen_cap = RL2_PEN_CAP_ROUND;
					break;
				    case RL2_STROKE_LINECAP_SQUARE:
					pen_cap = RL2_PEN_CAP_SQUARE;
					break;
				    default:
					pen_cap = RL2_PEN_CAP_BUTT;
					break;
				    };
				  switch (line_sym->stroke->linejoin)



				    {
				    case RL2_STROKE_LINEJOIN_BEVEL:
					pen_join = RL2_PEN_JOIN_BEVEL;
					break;
				    case RL2_STROKE_LINEJOIN_ROUND:
					pen_join = RL2_PEN_JOIN_ROUND;
					break;
				    default:



					pen_join = RL2_PEN_JOIN_MITER;
					break;
				    };





























				  if (line_sym->stroke->dash_count > 0
				      && line_sym->stroke->dash_list != NULL)
				      rl2_add_pattern_to_multi_stroke_dash
					  (multi_stroke, pattern,
					   line_sym->stroke->width, pen_cap,
					   pen_join,
					   line_sym->stroke->dash_count,
................................................................................
					   line_sym->stroke->dash_offset);
				  else
				      rl2_add_pattern_to_multi_stroke
					  (multi_stroke, pattern,
					   line_sym->stroke->width, pen_cap,
					   pen_join);
			      }





			}
		      else
			{
			    /* solid RGB stroke */
			    if (line_sym->stroke->opacity <= 0.0)
				norm_opacity = 0;
			    else if (line_sym->stroke->opacity >= 1.0)
................................................................................
    if (multi_stroke == NULL)
	return;

    line = geom->first_linestring;
    while (line)
      {
	  /* drawing a LINESTRING */


	  rl2PrivMultiStrokeItemPtr stroke_item;
	  int iv;
	  double dx;
	  double dy;
	  int x;
	  int y;
	  int lastX = 0;
	  int lastY = 0;
	  for (iv = 0; iv < line->points; iv++)
	    {
		rl2GetPoint (line->coords, iv, &dx, &dy);
		x = (int) ((dx - minx) / x_res);
		y = height - (int) ((dy - miny) / y_res);
		if (iv == 0)
		  {
		      rl2_graph_move_to_point (ctx, x, y);
		      lastX = x;
		      lastY = y;
		  }
		else
		  {
		      if (x == lastX && y == lastY)
			  ;
		      else
			{
			    rl2_graph_add_line_to_path (ctx, x, y);
			    lastX = x;
			    lastY = y;
			}
		  }
	    }
	  stroke_item = multi_stroke->first;
	  while (stroke_item != NULL)
	    {
		/* applying all strokes, one after the other */
		if (stroke_item->dash_count > 0
		    && stroke_item->dash_list != NULL)
		  {
		      if (stroke_item->pattern != NULL)
			  rl2_graph_set_pattern_dashed_pen (ctx,
							    stroke_item->pattern,
							    stroke_item->width,
							    stroke_item->pen_cap,
							    stroke_item->pen_join,
							    stroke_item->dash_count,
							    stroke_item->dash_list,
							    stroke_item->dash_offset);
		      else
			  rl2_graph_set_dashed_pen (ctx, stroke_item->red,

						    stroke_item->green,
						    stroke_item->blue,
						    stroke_item->opacity,
						    stroke_item->width,
						    stroke_item->pen_cap,
						    stroke_item->pen_join,
						    stroke_item->dash_count,
						    stroke_item->dash_list,
						    stroke_item->dash_offset);
		  }
		else
		  {
		      if (stroke_item->pattern != NULL)
			  rl2_graph_set_pattern_solid_pen (ctx,
							   stroke_item->pattern,
							   stroke_item->width,
							   stroke_item->pen_cap,
							   stroke_item->pen_join);
		      else
			  rl2_graph_set_solid_pen (ctx, stroke_item->red,

						   stroke_item->green,
						   stroke_item->blue,
						   stroke_item->opacity,
						   stroke_item->width,
						   stroke_item->pen_cap,
						   stroke_item->pen_join);
		  }

		if (stroke_item == multi_stroke->last)
		    rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH);
		else
		    rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH);

		stroke_item = stroke_item->next;
		if (stroke_item == multi_stroke->last)
		    rl2_graph_release_pattern_pen (ctx);

	    }
	  line = line->next;
      }
    rl2_destroy_multi_stroke (multi_stroke);
}

















static void
draw_polygons (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	       rl2PrivVectorSymbolizerPtr sym, int height, double minx,

	       double miny, double x_res, double y_res, rl2GeometryPtr geom)
{
/* drawing Polygonal-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    int stroke = 0;
    int fill = 0;
    int pen_cap;
    int pen_join;
................................................................................
				    rl2_create_pattern_from_external_graphic
				    (handle, xlink_href, 1);
			    if (pattern_fill != NULL)
			      {
				  if (recolor)
				    {
					/* attempting to recolor the External Graphic resource */
					rl2_graph_pattern_recolor (pattern_fill,
								   red, green,
								   blue);
				    }
				  if (polyg_sym->fill->opacity <= 0.0)
				      norm_opacity = 0;
				  else if (polyg_sym->fill->opacity >= 1.0)
				      norm_opacity = 255;
				  else
				    {
................................................................................
			}
		  }
		if (polyg_sym->stroke != NULL)
		  {
		      if (polyg_sym->stroke->graphic != NULL)
			{
			    /* external Graphic stroke */
			    pattern_stroke =
				load_external_graphic_from_dbms (handle,
								 polyg_sym->stroke->graphic);
			    if (pattern_stroke != NULL)
			      {
				  switch (polyg_sym->stroke->linecap)
				    {
				    case RL2_STROKE_LINECAP_ROUND:
					pen_cap = RL2_PEN_CAP_ROUND;
					break;
				    case RL2_STROKE_LINECAP_SQUARE:
					pen_cap = RL2_PEN_CAP_SQUARE;
					break;
				    default:
					pen_cap = RL2_PEN_CAP_BUTT;
					break;
				    };
				  switch (polyg_sym->stroke->linejoin)
				    {
				    case RL2_STROKE_LINEJOIN_BEVEL:
					pen_join = RL2_PEN_JOIN_BEVEL;
					break;
				    case RL2_STROKE_LINEJOIN_ROUND:
					pen_join = RL2_PEN_JOIN_ROUND;
					break;
				    default:
					pen_join = RL2_PEN_JOIN_MITER;
					break;
				    };
				  if (polyg_sym->stroke->dash_count > 0
				      && polyg_sym->stroke->dash_list != NULL)
				      rl2_graph_set_pattern_dashed_pen (ctx,
									pattern_stroke,
									polyg_sym->
									stroke->width,
									pen_cap,
									pen_join,
									polyg_sym->stroke->dash_count,
									polyg_sym->stroke->dash_list,
									polyg_sym->stroke->dash_offset);
				  else
				      rl2_graph_set_pattern_solid_pen (ctx,
								       pattern_stroke,
								       polyg_sym->
								       stroke->width,
								       pen_cap,
								       pen_join);
				  stroke = 1;
			      }















			}
		      else
			{
			    /* solid RGB stroke */
			    if (polyg_sym->stroke->opacity <= 0.0)
				norm_opacity = 0;
			    else if (polyg_sym->stroke->opacity >= 1.0)
................................................................................
		int x;
		int y;
		int lastX = 0;
		int lastY = 0;
		int ib;
		rl2RingPtr ring = polyg->exterior;
		/* exterior border */
		for (iv = 0; iv < ring->points; iv++)
		  {
		      rl2GetPoint (ring->coords, iv, &dx, &dy);
		      x = (int) ((dx - minx) / x_res);
		      y = height - (int) ((dy - miny) / y_res);
		      if (iv == 0)
			{
			    rl2_graph_move_to_point (ctx, x, y);
			    lastX = x;
			    lastY = y;
			}
		      else
			{
			    if (x == lastX && y == lastY)
				;
			    else
			      {
				  rl2_graph_add_line_to_path (ctx, x, y);
				  lastX = x;
				  lastY = y;
			      }
			}
		  }
		rl2_graph_close_subpath (ctx);
		for (ib = 0; ib < polyg->num_interiors; ib++)
		  {
		      /* interior borders */
		      ring = polyg->interiors + ib;
		      for (iv = 0; iv < ring->points; iv++)
			{
			    rl2GetPoint (ring->coords, iv, &dx, &dy);
			    x = (int) ((dx - minx) / x_res);
			    y = height - (int) ((dy - miny) / y_res);
			    if (iv == 0)
			      {
................................................................................
					rl2_graph_add_line_to_path (ctx, x, y);
					lastX = x;
					lastY = y;
				    }
			      }
			}
		      rl2_graph_close_subpath (ctx);







































		  }
		if (fill)
		  {
		      if (stroke)
			  rl2_graph_fill_path (ctx, RL2_PRESERVE_PATH);
		      else
			  rl2_graph_fill_path (ctx, RL2_CLEAR_PATH);
................................................................................
		rl2_graph_destroy_pattern (pattern_stroke);
	    }
	  item = item->next;
      }
}

static int
label_get_xy (sqlite3 * handle, const unsigned char *blob, int size, double *x,
	      double *y)
{
/* resolving Point XY coords */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    int ok = 0;

................................................................................
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt, 0);

		      int g_size = sqlite3_column_bytes (stmt, 0);
		      if (label_get_xy (handle, g_blob, g_size, x, y))
			  ok = 1;
		  }
	    }
      }
    sqlite3_finalize (stmt);
................................................................................
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt, 0);

		      int g_size = sqlite3_column_bytes (stmt, 0);
		      if (label_get_xy (handle, g_blob, g_size, x, y))
			  ok = 1;
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return ok;
}

































































































































































































































































































































static void










































































































































































draw_labels (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	     rl2PrivTextSymbolizerPtr sym, int height, double minx, double miny,

	     double x_res, double y_res, rl2GeometryPtr geom,
	     rl2PrivVariantValuePtr value)
{
/* drawing TextLabels */
    rl2GraphicsFontPtr font = NULL;
    char *dummy = NULL;
    const char *label = NULL;
    int font_style;
    int font_weight;
    double opacity;
    unsigned char norm_opacity;
    rl2PointPtr point;
    rl2LinestringPtr line;
    rl2PolygonPtr polyg;













/* preparing the Text */
    if (value->sqlite3_type == SQLITE_INTEGER)
      {
	  dummy = sqlite3_malloc (1024);
#if defined(_WIN32) && !defined(__MINGW32__)
	  sprintf (dummy, "%I64d", value->int_value);
................................................................................
	  font_weight = RL2_FONTWEIGHT_BOLD;
	  break;
      case RL2_FONT_WEIGHT_NORMAL:
      default:
	  font_weight = RL2_FONTWEIGHT_NORMAL;
	  break;
      };




    font =









	rl2_graph_create_toy_font (NULL, sym->font_size, font_style,
				   font_weight);

    if (font == NULL)
	goto stop;
    if (sym->fill != NULL)
      {
	  if (sym->fill->opacity <= 0.0)
	      norm_opacity = 0;
	  else if (sym->fill->opacity >= 1.0)
................................................................................
		    norm_opacity = 0;
		else if (opacity >= 255.0)
		    norm_opacity = 255;
		else
		    norm_opacity = opacity;
	    }
	  rl2_graph_font_set_halo (font, sym->halo->radius,

				   sym->halo->fill->red, sym->halo->fill->green,
				   sym->halo->fill->blue, norm_opacity);
      }
    rl2_graph_set_font (ctx, font);

    polyg = geom->first_polygon;
    while (polyg)
      {
	  /* drawing a POLYGON-based text label */
	  double pre_x;
	  double pre_y;
	  double lbl_width = 0.0;
	  double lbl_height = 0.0;

	  double post_x;
	  double post_y;
	  double shift_x;
	  double shift_y;























	  double cx;
	  double cy;
	  double x;
	  double y;





	  if (!label_get_centroid (handle, polyg, &cx, &cy))
	    {
		polyg = polyg->next;
		continue;
	    }




	  x = (cx - minx) / x_res;
	  y = (double) height - ((cy - miny) / y_res);
	  rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width,
				     &lbl_height, &post_x, &post_y);
	  shift_x = 0.0 - (lbl_width / 2.0);
	  shift_y = 0.0 + (lbl_height / 2.0);
	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
			       0.0);



	  polyg = polyg->next;
      }

    line = geom->first_linestring;
    while (line)
      {
	  /* drawing a LINESTRING-based text label */
	  double pre_x;
	  double pre_y;
	  double lbl_width = 0.0;
	  double lbl_height = 0.0;
	  double post_x;
	  double post_y;
	  double shift_x;
	  double shift_y;


































	  double cx;
	  double cy;
	  double x;
	  double y;









	  label_get_midpoint (handle, line, &cx, &cy);
	  if (!rl2_graph_get_text_extent
	      (ctx, label, &pre_x, &pre_y, &lbl_width, &lbl_height, &post_x,
	       &post_y))



	    {
		line = line->next;
		continue;
	    }
	  x = (cx - minx) / x_res;
	  y = (double) height - ((cy - miny) / y_res);
	  shift_x = 0.0 - (lbl_width / 2.0);
	  shift_y = 0.0 + (lbl_height / 2.0);
	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
			       0.0);

































	  line = line->next;
      }

    point = geom->first_point;
    while (point)
      {
	  /* drawing a POINT-based text label */






















	  double pre_x;
	  double pre_y;
	  double lbl_width = 0.0;
	  double lbl_height = 0.0;
	  double post_x;
	  double post_y;
	  double shift_x;
	  double shift_y;






















































	  double x = (point->x - minx) / x_res;
	  double y = (double) height - ((point->y - miny) / y_res);
	  rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width,
				     &lbl_height, &post_x, &post_y);
	  shift_x = 0.0 - (lbl_width / 2.0);
	  shift_y = 0.0 + (lbl_height / 2.0);

	  rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0,
			       0.0);








	  point = point->next;





























      }







/* final cleanup - relasing resources */
  stop:
    if (dummy != NULL)
	sqlite3_free (dummy);
    if (font != NULL)


	rl2_graph_destroy_font (font);

}

RL2_PRIVATE void
rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle,
			 rl2VectorSymbolizerPtr symbolizer, int height,
			 double minx, double miny, double x_res, double y_res,

			 rl2GeometryPtr geom, rl2VariantArrayPtr variant)
{
/* drawing a vector feature on the current canvass */
    rl2PrivVectorSymbolizerItemPtr item;
    rl2GraphicsContextPtr ctx = (rl2GraphicsContextPtr) p_ctx;
    rl2PrivVectorSymbolizerPtr sym = (rl2PrivVectorSymbolizerPtr) symbolizer;
    rl2PrivVectorSymbolizerPtr default_symbolizer = NULL;

................................................................................
	      default_symbolizer->last->next = item;
	  default_symbolizer->last = item;
	  sym = default_symbolizer;
      }

/* we'll render all geometries first */
    if (geom->first_polygon != NULL)
	draw_polygons (ctx, handle, sym, height, minx, miny, x_res, y_res,
		       geom);
    if (geom->first_linestring != NULL)
	draw_lines (ctx, handle, sym, height, minx, miny, x_res, y_res, geom);

    if (geom->first_point != NULL)
	draw_points (ctx, handle, sym, height, minx, miny, x_res, y_res, geom);


    if (sym != NULL)
      {
	  /* then we'll render any eventual TextSymbolizer */
	  item = sym->first;
	  while (item != NULL)
	    {
................................................................................
		      rl2PrivTextSymbolizerPtr text =
			  (rl2PrivTextSymbolizerPtr) (item->symbolizer);
		      if (text->label != NULL)
			{
			    int v;
			    rl2PrivVariantArrayPtr var =
				(rl2PrivVariantArrayPtr) variant;


			    for (v = 0; v < var->count; v++)
			      {
				  rl2PrivVariantValuePtr val =
				      *(var->array + v);
				  if (val == NULL)
				      continue;
				  if (val->column_name == NULL)
				      continue;


				  if (strcasecmp (text->label, val->column_name)
				      != 0)
				      continue;

				  draw_labels (ctx, handle, text, height, minx,

					       miny, x_res, y_res, geom, val);

			      }

			}
		  }


		item = item->next;
	    }
      }

    if (default_symbolizer != NULL)
	rl2_destroy_vector_symbolizer (default_symbolizer);
}























































































|
>
|







 







|
|













|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|







 







|
|







 







|
|







 







|
|
>







 







|
|
>







 







|
>
|







 







|
|
|
|







 







|







 







>
|







 







>
>










<
<







 







>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


|







 







|
|
>

<
|
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



>
|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<

>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
>







 







>
|
>
|
>
|

|
|
|
|
|
|
|
<









>
>
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
|
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
>
|
|
>
|
|
|
<
|
|
|
|
|
|
|
|
|
|
>
|
|
>
|
>
|
|
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
>
>
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
|
|
|
>
>
>
|
|
>
|
>
|
|
>
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
|
|
>
|
>
|
|
>
|
>
|
|
>
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
|
|
|
|
|
|
>
>
>
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>






|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
|



|
|







 







|
>
>
>
>
>
|
<

|
>

<
<
<
<
<
|
|
<
<
<
|
>
>
>
|
|
|
|
|
<
<
<
>
>
>
|
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>







 







>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|

|
|
|
|

|
|
|
>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
|







 







|
|
<







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|







 







|
>







 







|
>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
|
<












>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
|
>







 







>
|




<
|

|
|
|
|
<
>
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
>
|
|
|
|
|
>
>
>
>
|
|
<
<
<
<
|
<
>
>
>
|
|

|
|
|
|
<
<
<
<
<
<
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
|
<
<
<
>
>
>
|
<
<
<
|
|
<
<
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|

|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
<
<
<
>
|
<
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>





>
>
|
>



|

|
>
|







 







|
|

|
>

|
>







 







>
>
|
|
|
|
|
|
|
|
>
>
|
<
|
>
|
>
|
>
|
>
|
|
>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
...
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
...
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
...
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
...
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
...
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
...
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
...
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
....
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
....
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
....
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695


1696
1697
1698
1699
1700
1701
1702
....
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
....
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793

1794
1795






1796

















1797
1798





1799
1800
































































1801
1802












1803
1804





1805

































































1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
....
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
....
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899

1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939

1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
....
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
....
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200

2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231

2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327

2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363

2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
....
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
....
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628

2629
2630
2631
2632





2633
2634



2635
2636
2637
2638
2639
2640
2641
2642
2643



2644
2645
2646
2647
2648

2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
....
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
....
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
....
2953
2954
2955
2956
2957
2958
2959
2960
2961

2962
2963
2964
2965
2966
2967
2968
....
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
....
3173
3174
3175
3176
3177
3178
3179
3180
3181


























3182
3183
3184
3185
3186
3187
3188
....
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
....
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
....
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
....
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898

3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
....
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
....
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029

4030
4031
4032
4033
4034
4035

4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083




4084

4085
4086
4087
4088
4089
4090
4091
4092
4093
4094







4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143



4144
4145
4146
4147



4148
4149


4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215






4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271




4272
4273

4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
....
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
....
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464

4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
		  }
	    }
      }
}

static void
copy_palette (unsigned char *rgba, unsigned int width, unsigned int height,
	      unsigned char *inbuf, rl2PalettePtr palette,
	      unsigned char bg_red, unsigned char bg_green,
	      unsigned char bg_blue)
{
/* copying from Palette to RGBA */
    unsigned int x;
    unsigned int y;
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
    unsigned char *p_in = inbuf;
    unsigned char *p_out = rgba;
................................................................................
	goto error;

    if (aux->base_width == aux->width && aux->base_height == aux->height)
      {
	  if (aux->out_pixel == RL2_PIXEL_MONOCHROME)
	    {
		/* Monochrome */
		copy_monochrome (aggreg_rgba, aux->base_width,
				 aux->base_height, aux->outbuf);
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
	    {
		/* Palette */
		copy_palette (aggreg_rgba, aux->base_width, aux->base_height,
			      aux->outbuf, aux->palette, aux->bg_red,
			      aux->bg_green, aux->bg_blue);
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
	    {
		/* Grayscale */
		copy_grayscale (aggreg_rgba, aux->base_width,
				aux->base_height, aux->outbuf, aux->bg_red);
		aux->outbuf = NULL;
	    }
	  else
	    {
		/* RGB */
		copy_rgb (aggreg_rgba, aux->base_width, aux->base_height,
			  aux->outbuf, aux->bg_red, aux->bg_green,
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_monochrome_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id,
			   aux->quality, &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_palette_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->palette,
			   aux->format_id, aux->quality, &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_grayscale_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id,
			   aux->quality, &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			}
		  }
		else
		  {
		      if (!get_payload_from_rgb_opaque
			  (aux->base_width, aux->base_height, aux->sqlite,
			   aux->minx, aux->miny, aux->maxx, aux->maxy,
			   aux->srid, aux->outbuf, aux->format_id,
			   aux->quality, &image, &image_size))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
................................................................................
			    goto error;
			}
		  }
		aux->outbuf = NULL;
	    }
	  else if (aux->out_pixel == RL2_PIXEL_PALETTE)
	    {
		/* Palette - upsampled */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_palette_transparent
			  (aux->base_width, aux->base_height, aux->outbuf,
			   aux->palette, rgba, aux->bg_red, aux->bg_green,
			   aux->bg_blue))
			{
................................................................................
	    }
	  else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE)
	    {
		/* Grayscale */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_grayscale_transparent
			  (aux->base_width, aux->base_height, aux->outbuf,
			   rgba, aux->bg_red))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		else
		  {
................................................................................
	    }
	  else
	    {
		/* RGB */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (!get_rgba_from_rgb_transparent
			  (aux->base_width, aux->base_height, aux->outbuf,
			   rgba, aux->bg_red, aux->bg_green, aux->bg_blue))
			{
			    aux->outbuf = NULL;
			    goto error;
			}
		  }
		else
		  {
................................................................................
	    {
		/* Grayscale or Monochrome upsampled */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (alpha == NULL)
			  goto error;
		      if (!get_payload_from_gray_rgba_transparent
			  (aux->width, aux->height, rgb, alpha,
			   aux->format_id, aux->quality, &image, &image_size,
			   aux->opacity))
			  goto error;
		  }
		else
		  {
		      if (alpha != NULL)
			  free (alpha);
		      alpha = NULL;
................................................................................
	    {
		/* RGB */
		if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG)
		  {
		      if (alpha == NULL)
			  goto error;
		      if (!get_payload_from_rgb_rgba_transparent
			  (aux->width, aux->height, rgb, alpha,
			   aux->format_id, aux->quality, &image, &image_size,
			   aux->opacity, 0))
			  goto error;
		  }
		else
		  {
		      if (alpha != NULL)
			  free (alpha);
		      alpha = NULL;
................................................................................
	free (rgb);
    if (alpha != NULL)
	free (alpha);
    return 0;
}

static int
aux_shaded_relief_mask (struct aux_renderer *aux,
			int by_section, sqlite3_int64 section_id,
			double relief_factor, unsigned char **shaded_relief)
{
/* attempting to create a Shaded Relief brightness-only mask */
    rl2GraphicsBitmapPtr base_img = NULL;
    rl2GraphicsContextPtr ctx = NULL;
    float *shr_mask;
    int shr_size;
    const char *coverage;
................................................................................
    *shaded_relief = NULL;
    coverage = rl2_get_coverage_name (aux->coverage);
    if (coverage == NULL)
	return 0;
    scale_factor = rl2_get_shaded_relief_scale_factor (aux->sqlite, coverage);

    if (rl2_build_shaded_relief_mask
	(aux->sqlite, aux->max_threads, aux->coverage, by_section, section_id,
	 relief_factor, scale_factor, aux->base_width, aux->base_height,
	 aux->minx, aux->miny, aux->maxx, aux->maxy, aux->xx_res, aux->yy_res,
	 &shr_mask, &shr_size) != RL2_OK)
	return 0;

/* allocating the RGBA buffer */
    rgba = malloc (aux->base_width * aux->base_height * 4);
    if (rgba == NULL)
	return 0;

................................................................................
	  aux.out_pixel = out_pixel;
	  if (is_shaded_relief)
	    {
		/* requesting a shaded relief mask */
		if (shaded_relief_mask != NULL)
		    free (shaded_relief_mask);
		if (!aux_shaded_relief_mask
		    (&aux, 0, 0, symbolizer->reliefFactor, &shaded_relief_mask))
		    goto error;
	    }
	  else
	    {
		/* rendering an image */
		if (!aux_render_composed_image (&aux, rgba))
		    goto error;
................................................................................
RL2_DECLARE int
rl2_get_raw_raster_data_mixed_resolutions (sqlite3 * handle, int max_threads,
					   rl2CoveragePtr cvg,
					   unsigned int width,
					   unsigned int height, double minx,
					   double miny, double maxx,
					   double maxy, double x_res,
					   double y_res,
					   unsigned char **buffer,
					   int *buf_size,
					   rl2PalettePtr * palette,
					   unsigned char *out_pixel,
					   unsigned char bg_red,
					   unsigned char bg_green,
					   unsigned char bg_blue,
					   rl2RasterSymbolizerPtr style,
................................................................................
		double xx_res;
		double yy_res;
		int level_id;
		int scale;
		int xscale;
		unsigned int w;
		unsigned int h;
		unsigned int w2;
		unsigned int h2;
		int base_x;
		int base_y;
		unsigned char *bufpix = NULL;
		int bufpix_size;
		double img_res_x = (maxx - minx) / (double) width;
		double img_res_y = (maxy - miny) / (double) height;
		double mnx = minx;
		double mny = miny;
		double mxx = maxx;
		double mxy = maxy;


		/* normalizing the visible portion of the Section */
		if (mnx < section_minx)
		    mnx = section_minx;
		if (mny < section_miny)
		    mny = section_miny;
		if (mxx > section_maxx)
		    mxx = section_maxx;
................................................................................
		if (((double) w * xx_res) < (mxx - mnx))
		    w++;
		h = (unsigned int) ((mxy - mny) / yy_res);
		if (((double) h * yy_res) < (mxy - mny))
		    h++;
		base_x = (int) ((mnx - minx) / img_res_x);
		base_y = (int) ((maxy - mxy) / img_res_y);

		if (rl2_get_raw_raster_data_common
		    (handle, max_threads, cvg, 1, section_id, w, h, mnx, mny,
		     mxx, mxy, xx_res, yy_res, &bufpix, &bufpix_size, palette,
		     *out_pixel, no_data, xstyle, stats) != RL2_OK)
		    goto error;

		w2 = (unsigned int) ((mxx - mnx) / img_res_x);
		if (((double) w2 * img_res_x) < (mxx - mnx))
		    w2++;
		h2 = (unsigned int) ((mxy - mny) / img_res_y);
		if (((double) h2 * img_res_y) < (mxy - mny))
		    h2++;
		if (w == w2 && h == h2)
		  {
		      /* already rescaled */
		  }
		else
		  {
		      /* rescaling the pixbuf */
		      unsigned char *rescaled = NULL;
		      int pix_sz = 1;
		      if (*out_pixel == RL2_PIXEL_RGB)
			  pix_sz = 3;
		      rescaled = malloc (pix_sz * w2 * h2);
		      if (rescaled == NULL)
			{
			    fprintf (stderr,
				     "rl2_get_raw_raster_data_mixed_resolutions: Insufficient Memory !!!\n");
			    goto error;
			}
		      if (!rl2_rescale_pixbuf
			  (bufpix, w, h, *out_pixel, rescaled, w2, h2))
			  goto error;
		      free (bufpix);
		      bufpix = rescaled;
		  }

		if (*out_pixel == RL2_PIXEL_RGB)
		    do_copy_rgb (outbuf, bufpix, width, height, w2, h2, base_x,
				 base_y, bg_red, bg_green, bg_blue);
		else
		    do_copy_gray (outbuf, bufpix, width, height, w2, h2, base_x,
				  base_y, bg_red);
		free (bufpix);
	    }
	  else
	    {
		fprintf (stderr, "SQL error: %s\n%s\n", sql,
			 sqlite3_errmsg (handle));
................................................................................
    if (no_data != NULL)
	rl2_destroy_pixel (no_data);
    if (outbuf != NULL)
	free (outbuf);
    return RL2_ERROR;
}

static int
point_bbox_matches (rl2PointPtr point, double minx, double miny, double maxx,
		    double maxy)
{

/* checks if the Point is visible */
    if (minx > point->x)






	return 0;

















    if (maxx < point->x)
	return 0;





    if (miny > point->y)
	return 0;
































































    if (maxy < point->y)
	return 0;












    return 1;
}







































































static void
draw_points (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	     rl2PrivVectorSymbolizerPtr sym, int height, double minx,
	     double miny, double maxx, double maxy, double x_res,
	     double y_res, rl2GeometryPtr geom)
{
/* drawing Point-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    rl2PointPtr point;

    item = sym->first;
    while (item != NULL)
................................................................................
		      unsigned char well_known_type;
		      int fill = 0;
		      int stroke = 0;
		      int pen_cap;
		      int pen_join;
		      double opacity;
		      unsigned char norm_opacity;
		      rl2GraphicsPatternPtr pattern = NULL;
		      rl2GraphicsPatternPtr pattern_fill = NULL;
		      rl2GraphicsPatternPtr pattern_stroke = NULL;

		      if (graphic->type == RL2_MARK_GRAPHIC)
			{
			    rl2PrivMarkPtr mark =
				(rl2PrivMarkPtr) (graphic->item);
................................................................................
				  well_known_type = mark->well_known_type;
				  is_mark = 1;
				  if (mark->fill != NULL)
				    {
					if (mark->fill->graphic != NULL)
					  {
					      /* external Graphic fill */
					      const char *xlink_href = NULL;
					      int recolor = 0;
					      unsigned char red;
					      unsigned char green;
					      unsigned char blue;
					      pattern_fill = NULL;
					      if (mark->fill->graphic->first !=
						  NULL)
						{
						    if (mark->fill->
							graphic->first->type ==
							RL2_EXTERNAL_GRAPHIC)
						      {
							  rl2PrivExternalGraphicPtr
							      ext =
							      (rl2PrivExternalGraphicPtr)
							      (mark->
							       fill->graphic->
							       first->item);
							  xlink_href =
							      ext->xlink_href;
							  if (ext->first !=
							      NULL)
							    {
								recolor = 1;
								red =
								    ext->
								    first->red;
								green =
								    ext->
								    first->green;
								blue =
								    ext->
								    first->blue;
							    }
						      }
						}
					      if (xlink_href != NULL)
						  pattern_fill =
						      rl2_create_pattern_from_external_graphic

						      (handle, xlink_href, 1);
					      if (pattern_fill != NULL)
						{
						    if (recolor)
						      {
							  /* attempting to recolor the External Graphic resource */
							  rl2_graph_pattern_recolor
							      (pattern_fill,
							       red, green,
							       blue);
						      }
						    if (mark->fill->opacity <=
							0.0)
							norm_opacity = 0;
						    else if (mark->
							     fill->opacity >=
							     1.0)
							norm_opacity = 255;
						    else
						      {
							  opacity =
							      255.0 *
							      mark->
							      fill->opacity;
							  if (opacity <= 0.0)
							      norm_opacity = 0;
							  else if (opacity >=
								   255.0)
							      norm_opacity =
								  255;
							  else
							      norm_opacity =
								  opacity;
						      }
						    if (norm_opacity < 1.0)
							rl2_graph_pattern_transparency
							    (pattern_fill,
							     norm_opacity);
						    rl2_graph_set_pattern_brush
							(ctx, pattern_fill);

						}
					      else
						{
						    /* invalid Pattern: defaulting to a Gray brush */
						    rl2_graph_set_brush (ctx,
									 128,
									 128,
									 128,
									 255);
						}
					      fill = 1;
					  }
					else
					  {
					      /* solid RGB fill */
					      if (gr->opacity <= 0.0)
						  norm_opacity = 0;
					      else if (gr->opacity >= 1.0)
................................................................................
					      fill = 1;
					  }
				    }
				  if (mark->stroke != NULL)
				    {
					if (mark->stroke->graphic != NULL)
					  {
					      const char *xlink_href = NULL;
					      int recolor = 0;
					      unsigned char red;
					      unsigned char green;
					      unsigned char blue;
					      pattern_stroke = NULL;
					      if (mark->stroke->
						  graphic->first != NULL)
						{
						    if (mark->stroke->
							graphic->first->type ==
							RL2_EXTERNAL_GRAPHIC)
						      {
							  rl2PrivExternalGraphicPtr
							      ext =
							      (rl2PrivExternalGraphicPtr)
							      (mark->
							       stroke->graphic->
							       first->item);
							  xlink_href =
							      ext->xlink_href;
							  if (ext->first !=
							      NULL)
							    {
								recolor = 1;
								red =
								    ext->
								    first->red;
								green =
								    ext->
								    first->green;
								blue =
								    ext->
								    first->blue;
							    }
						      }
						}
					      if (xlink_href != NULL)
						  pattern_stroke =
						      rl2_create_pattern_from_external_graphic
						      (handle, xlink_href, 1);
					      if (pattern != NULL)
						{
						    if (recolor)
						      {
							  /* attempting to recolor the External Graphic resource */
							  rl2_graph_pattern_recolor
							      (pattern_stroke,
							       red, green,
							       blue);
						      }
						    if (mark->stroke->opacity <=
							0.0)
							norm_opacity = 0;
						    else if (mark->
							     stroke->opacity >=
							     1.0)
							norm_opacity = 255;
						    else
						      {
							  opacity =
							      255.0 *
							      mark->
							      stroke->opacity;
							  if (opacity <= 0.0)
							      norm_opacity = 0;
							  else if (opacity >=
								   255.0)
							      norm_opacity =
								  255;
							  else
							      norm_opacity =
								  opacity;
						      }
						    if (norm_opacity < 1.0)
							rl2_graph_pattern_transparency
							    (pattern_stroke,
							     norm_opacity);
						    if (pattern_stroke != NULL)
						      {
							  switch
							      (mark->
							       stroke->linecap)
							    {
							    case RL2_STROKE_LINECAP_ROUND:
								pen_cap =
								    RL2_PEN_CAP_ROUND;
								break;
							    case RL2_STROKE_LINECAP_SQUARE:
								pen_cap =
								    RL2_PEN_CAP_SQUARE;
								break;
							    default:
								pen_cap =
								    RL2_PEN_CAP_BUTT;
								break;
							    };
							  switch
							      (mark->
							       stroke->linejoin)
							    {
							    case RL2_STROKE_LINEJOIN_BEVEL:
								pen_join =
								    RL2_PEN_JOIN_BEVEL;
								break;
							    case RL2_STROKE_LINEJOIN_ROUND:
								pen_join =
								    RL2_PEN_JOIN_ROUND;
								break;
							    default:
								pen_join =
								    RL2_PEN_JOIN_MITER;
								break;
							    };
							  if (mark->
							      stroke->dash_count
							      > 0
							      && mark->
							      stroke->dash_list
							      != NULL)
							      rl2_graph_set_pattern_dashed_pen
								  (ctx,
								   pattern_stroke,
								   mark->
								   stroke->width,
								   pen_cap,
								   pen_join,
								   mark->
								   stroke->dash_count,
								   mark->
								   stroke->dash_list,
								   mark->
								   stroke->dash_offset);
							  else
							      rl2_graph_set_pattern_solid_pen
								  (ctx,
								   pattern_stroke,
								   mark->
								   stroke->width,
								   pen_cap,
								   pen_join);
							  stroke = 1;
						      }
						}
					  }
					else
					  {
					      /* solid RGB stroke */
					      if (gr->opacity <= 0.0)
						  norm_opacity = 0;
................................................................................
									    mark->stroke->red,
									    mark->stroke->green,
									    mark->stroke->blue,
									    norm_opacity,
									    mark->stroke->width,
									    pen_cap,
									    pen_join,
									    mark->
									    stroke->dash_count,
									    mark->
									    stroke->dash_list,
									    mark->
									    stroke->dash_offset);
					      else
						  rl2_graph_set_solid_pen
						      (ctx, mark->stroke->red,
						       mark->stroke->green,
						       mark->stroke->blue,
						       norm_opacity,
						       mark->stroke->width,
						       pen_cap, pen_join);

					      stroke = 1;
					  }
				    }
			      }
			}
		      if (graphic->type == RL2_EXTERNAL_GRAPHIC)
			{
			    rl2PrivExternalGraphicPtr ext =
				(rl2PrivExternalGraphicPtr) (graphic->item);
			    const char *xlink_href = NULL;
			    int recolor = 0;
			    unsigned char red;
			    unsigned char green;
			    unsigned char blue;
			    pattern = NULL;
			    if (ext != NULL)
			      {
				  is_external = 1;
				  if (ext->xlink_href != NULL)
				      xlink_href = ext->xlink_href;
				  if (ext->first != NULL)
				    {
					recolor = 1;
					red = ext->first->red;
					green = ext->first->green;
					blue = ext->first->blue;
				    }
				  if (xlink_href != NULL)
				    {
					/* first attempt: Bitmap */
					pattern =

					    rl2_create_pattern_from_external_graphic
					    (handle, xlink_href, 1);
					if (pattern == NULL)
					  {
					      /* second attempt: SVG */
					      pattern =
						  rl2_create_pattern_from_external_svg
						  (handle, xlink_href,
						   point_sym->graphic->size);
					  }
				    }
			      }
			    if (pattern != NULL)
			      {
				  if (recolor)
				    {
					/* attempting to recolor the External Graphic resource */
					rl2_graph_pattern_recolor (pattern,
								   red, green,
								   blue);
				    }
				  if (point_sym->graphic->opacity <= 0.0)
				      norm_opacity = 0;
				  else if (point_sym->graphic->opacity >= 1.0)
				      norm_opacity = 255;
				  else
				    {
					opacity =
					    255.0 * point_sym->graphic->opacity;
					if (opacity <= 0.0)
					    norm_opacity = 0;
					else if (opacity >= 255.0)
					    norm_opacity = 255;
					else
					    norm_opacity = opacity;
				    }
				  if (norm_opacity < 1.0)
				      rl2_graph_pattern_transparency
					  (pattern, norm_opacity);
				  rl2_graph_set_pattern_brush (ctx, pattern);
			      }
			    else
			      {
				  /* invalid Pattern: defaulting to a Gray brush */
				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
			      }
			}

		      /* actual Point rendering */
		      point = geom->first_point;
		      while (point)
			{
			    /* drawing a POINT */
			    if (point_bbox_matches
				(point, minx, miny, maxx, maxy))
			      {
				  double x = (point->x - minx) / x_res;
				  double y =
				      (double) height -
				      ((point->y - miny) / y_res);
				  double size2 = gr->size / 2.0;
				  double size4 = gr->size / 4.0;
				  double size6 = gr->size / 6.0;
				  double size13 = gr->size / 3.0;
				  double size23 = (gr->size / 3.0) * 2.0;
				  int i;
				  double rads;
				  if (size2 <= 0.0)
				      size2 = 1.0;
				  if (size4 <= 0.0)
				      size4 = 1.0;
				  if (size6 <= 0.0)
				      size6 = 1.0;
				  if (size13 <= 0.0)
				      size13 = 1.0;
				  if (size23 <= 0.0)
				      size23 = 1.0;
				  if (is_mark)
				    {
					/* drawing a well-known Mark */
					switch (well_known_type)
					  {
					  case RL2_GRAPHIC_MARK_CIRCLE:
					      rads = 0.0;
					      for (i = 0; i < 32; i++)
						{
						    double tic =
							6.28318530718 / 32.0;
						    double cx =
							x +
							(size2 * sin (rads));
						    double cy =
							y +
							(size2 * cos (rads));
						    if (i == 0)
							rl2_graph_move_to_point

							    (ctx, cx, cy);
						    else
							rl2_graph_add_line_to_path
							    (ctx, cx, cy);
						    rads += tic;
						}
					      rl2_graph_close_subpath (ctx);
					      break;
					  case RL2_GRAPHIC_MARK_TRIANGLE:
					      rl2_graph_move_to_point (ctx, x,
								       y -
								       size23);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size2,
									  y +
									  size13);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y +
									  size13);
					      rl2_graph_close_subpath (ctx);
					      break;
					  case RL2_GRAPHIC_MARK_STAR:
					      rads = 3.14159265359;
					      for (i = 0; i < 10; i++)
						{
						    double tic =
							(i % 2) ? size6 : size2;
						    double cx =
							x + (tic * sin (rads));
						    double cy =
							y + (tic * cos (rads));
						    if (i == 0)
							rl2_graph_move_to_point

							    (ctx, cx, cy);
						    else
							rl2_graph_add_line_to_path
							    (ctx, cx, cy);
						    rads += 0.628318530718;
						}
					      rl2_graph_close_subpath (ctx);
					      break;
					  case RL2_GRAPHIC_MARK_CROSS:
					      rl2_graph_move_to_point (ctx,
								       x -
								       size6,
								       y -
								       size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size6,
									  y -
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size6,
									  y -
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y -
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y +
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size6,
									  y +
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size6,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size6,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size6,
									  y +
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size2,
									  y +
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size2,
									  y -
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size6,
									  y -
									  size6);
					      rl2_graph_close_subpath (ctx);
					      break;
					  case RL2_GRAPHIC_MARK_X:
					      rl2_graph_move_to_point (ctx,
								       x -
								       size2,
								       y -
								       size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size4,
									  y -
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x,
									  y -
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size6,
									  y -
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y -
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size4,
									  y);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size4,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x,
									  y +
									  size6);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size6,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size2,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size4,
									  y);
					      rl2_graph_close_subpath (ctx);
					      break;
					  case RL2_GRAPHIC_MARK_SQUARE:
					  default:
					      rl2_graph_move_to_point (ctx,
								       x -
								       size2,
								       y -
								       size2);
					      rl2_graph_add_line_to_path (ctx,
									  x -
									  size2,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y +
									  size2);
					      rl2_graph_add_line_to_path (ctx,
									  x +
									  size2,
									  y -
									  size2);
					      rl2_graph_close_subpath (ctx);
					      break;
					  };
					if (fill)
					  {
					      if (stroke)
						  rl2_graph_fill_path (ctx,
								       RL2_PRESERVE_PATH);
					      else
						  rl2_graph_fill_path (ctx,
								       RL2_CLEAR_PATH);
					  }
					if (stroke)
					    rl2_graph_stroke_path (ctx,
								   RL2_CLEAR_PATH);
				    }
				  if (is_external && pattern != NULL)
				    {
					/* drawing an External Graphic pattern */
					unsigned int width;
					unsigned int height;
					rl2_graph_get_pattern_size (pattern,
								    &width,
								    &height);
					double out_width = width;
					double out_height = height;
					rl2_graph_draw_graphic_symbol (ctx,
								       pattern,
								       out_width,
								       out_height,
								       x +
								       point_sym->graphic->displacement_x,
								       y -
								       point_sym->graphic->displacement_y,
								       point_sym->graphic->rotation,
								       point_sym->graphic->anchor_point_x,
								       point_sym->graphic->anchor_point_y);
				    }
			      }
			    point = point->next;
			}

		      /* releasing Patterns */
		      if (pattern != NULL)
			  rl2_graph_destroy_pattern (pattern);
		      if (pattern_fill != NULL)
			{
			    rl2_graph_release_pattern_pen (ctx);
			    rl2_graph_destroy_pattern (pattern_fill);
			}
		      if (pattern_stroke != NULL)
			{
................................................................................
			}
		      graphic = graphic->next;
		  }
	    }
	  item = item->next;
      }
}

static int
linestring_bbox_matches (rl2LinestringPtr ring, double minx, double miny,
			 double maxx, double maxy)
{
/* checks if the Linestring BBOX is visible */
    if (minx > ring->maxx)
	return 0;
    if (maxx < ring->minx)
	return 0;
    if (miny > ring->maxy)
	return 0;
    if (maxy < ring->miny)
	return 0;
    return 1;
}

static void
draw_lines (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	    rl2PrivVectorSymbolizerPtr sym, int height, double minx,
	    double miny, double maxx, double maxy, double x_res, double y_res,
	    rl2GeometryPtr geom)
{
/* drawing Linear-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    int pen_cap = RL2_PEN_CAP_BUTT;
    int pen_join = RL2_PEN_JOIN_MITER;
    double opacity;
    unsigned char norm_opacity;
    rl2LinestringPtr line;
    rl2GraphicsPatternPtr pattern = NULL;
    rl2PrivMultiStrokePtr multi_stroke = rl2_create_multi_stroke ();

    item = sym->first;
................................................................................
		rl2PrivLineSymbolizerPtr line_sym =
		    (rl2PrivLineSymbolizerPtr) (item->symbolizer);
		if (line_sym->stroke != NULL)
		  {
		      if (line_sym->stroke->graphic != NULL)
			{
			    /* external Graphic stroke */
			    const char *xlink_href = NULL;
			    int recolor = 0;
			    unsigned char red;
			    unsigned char green;
			    unsigned char blue;
			    pattern = NULL;
			    if (line_sym->stroke->graphic->first != NULL)

			      {
				  if (line_sym->stroke->graphic->first->type ==
				      RL2_EXTERNAL_GRAPHIC)
				    {





					rl2PrivExternalGraphicPtr ext =
					    (rl2PrivExternalGraphicPtr)



					    (line_sym->stroke->graphic->
					     first->item);
					xlink_href = ext->xlink_href;
					if (ext->first != NULL)
					  {
					      recolor = 1;
					      red = ext->first->red;
					      green = ext->first->green;
					      blue = ext->first->blue;



					  }
				    }
			      }
			    if (xlink_href != NULL)
				pattern =

				    rl2_create_pattern_from_external_graphic
				    (handle, xlink_href, 1);
			    if (pattern != NULL)
			      {
				  if (recolor)
				    {
					/* attempting to recolor the External Graphic resource */
					rl2_graph_pattern_recolor (pattern,
								   red, green,
								   blue);
				    }
				  if (line_sym->stroke->opacity <= 0.0)
				      norm_opacity = 0;
				  else if (line_sym->stroke->opacity >= 1.0)
				      norm_opacity = 255;
				  else
				    {
					opacity =
					    255.0 * line_sym->stroke->opacity;
					if (opacity <= 0.0)
					    norm_opacity = 0;
					else if (opacity >= 255.0)
					    norm_opacity = 255;
					else
					    norm_opacity = opacity;
				    }
				  if (norm_opacity < 1.0)
				      rl2_graph_pattern_transparency
					  (pattern, norm_opacity);
				  if (line_sym->stroke->dash_count > 0
				      && line_sym->stroke->dash_list != NULL)
				      rl2_add_pattern_to_multi_stroke_dash
					  (multi_stroke, pattern,
					   line_sym->stroke->width, pen_cap,
					   pen_join,
					   line_sym->stroke->dash_count,
................................................................................
					   line_sym->stroke->dash_offset);
				  else
				      rl2_add_pattern_to_multi_stroke
					  (multi_stroke, pattern,
					   line_sym->stroke->width, pen_cap,
					   pen_join);
			      }
			    else
			      {
				  /* invalid Pattern: defaulting to a Gray brush */
				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
			      }
			}
		      else
			{
			    /* solid RGB stroke */
			    if (line_sym->stroke->opacity <= 0.0)
				norm_opacity = 0;
			    else if (line_sym->stroke->opacity >= 1.0)
................................................................................
    if (multi_stroke == NULL)
	return;

    line = geom->first_linestring;
    while (line)
      {
	  /* drawing a LINESTRING */
	  if (linestring_bbox_matches (line, minx, miny, maxx, maxy))
	    {
		rl2PrivMultiStrokeItemPtr stroke_item;
		int iv;
		double dx;
		double dy;
		int x;
		int y;
		int lastX = 0;
		int lastY = 0;
		for (iv = 0; iv < line->points; iv++)
		  {
		      rl2GetPoint (line->coords, iv, &dx, &dy);
		      x = (int) ((dx - minx) / x_res);
		      y = height - (int) ((dy - miny) / y_res);
		      if (iv == 0)
			{
			    rl2_graph_move_to_point (ctx, x, y);
			    lastX = x;
			    lastY = y;
			}
		      else
			{
			    if (x == lastX && y == lastY)
				;
			    else
			      {
				  rl2_graph_add_line_to_path (ctx, x, y);
				  lastX = x;
				  lastY = y;
			      }
			}
		  }
		stroke_item = multi_stroke->first;
		while (stroke_item != NULL)
		  {
		      /* applying all strokes, one after the other */
		      if (stroke_item->dash_count > 0
			  && stroke_item->dash_list != NULL)
			{
			    if (stroke_item->pattern != NULL)
				rl2_graph_set_pattern_dashed_pen (ctx,
								  stroke_item->pattern,
								  stroke_item->width,
								  stroke_item->pen_cap,
								  stroke_item->pen_join,
								  stroke_item->dash_count,
								  stroke_item->dash_list,
								  stroke_item->dash_offset);
			    else
				rl2_graph_set_dashed_pen (ctx,
							  stroke_item->red,
							  stroke_item->green,
							  stroke_item->blue,
							  stroke_item->opacity,
							  stroke_item->width,
							  stroke_item->pen_cap,
							  stroke_item->pen_join,
							  stroke_item->dash_count,
							  stroke_item->dash_list,
							  stroke_item->dash_offset);
			}
		      else
			{
			    if (stroke_item->pattern != NULL)
				rl2_graph_set_pattern_solid_pen (ctx,
								 stroke_item->pattern,
								 stroke_item->width,
								 stroke_item->pen_cap,
								 stroke_item->pen_join);
			    else
				rl2_graph_set_solid_pen (ctx,
							 stroke_item->red,
							 stroke_item->green,
							 stroke_item->blue,
							 stroke_item->opacity,
							 stroke_item->width,
							 stroke_item->pen_cap,
							 stroke_item->pen_join);
			}

		      if (stroke_item == multi_stroke->last)
			  rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH);
		      else
			  rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH);

		      stroke_item = stroke_item->next;
		      if (stroke_item == multi_stroke->last)
			  rl2_graph_release_pattern_pen (ctx);
		  }
	    }
	  line = line->next;
      }
    rl2_destroy_multi_stroke (multi_stroke);
}

static int
ring_bbox_matches (rl2RingPtr ring, double minx, double miny, double maxx,
		   double maxy)
{
/* checks if the Ring BBOX is visible */
    if (minx > ring->maxx)
	return 0;
    if (maxx < ring->minx)
	return 0;
    if (miny > ring->maxy)
	return 0;
    if (maxy < ring->miny)
	return 0;
    return 1;
}

static void
draw_polygons (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	       rl2PrivVectorSymbolizerPtr sym, int height, double minx,
	       double miny, double maxx, double maxy, double x_res,
	       double y_res, rl2GeometryPtr geom)
{
/* drawing Polygonal-type features */
    rl2PrivVectorSymbolizerItemPtr item;
    int stroke = 0;
    int fill = 0;
    int pen_cap;
    int pen_join;
................................................................................
				    rl2_create_pattern_from_external_graphic
				    (handle, xlink_href, 1);
			    if (pattern_fill != NULL)
			      {
				  if (recolor)
				    {
					/* attempting to recolor the External Graphic resource */
					rl2_graph_pattern_recolor
					    (pattern_fill, red, green, blue);

				    }
				  if (polyg_sym->fill->opacity <= 0.0)
				      norm_opacity = 0;
				  else if (polyg_sym->fill->opacity >= 1.0)
				      norm_opacity = 255;
				  else
				    {
................................................................................
			}
		  }
		if (polyg_sym->stroke != NULL)
		  {
		      if (polyg_sym->stroke->graphic != NULL)
			{
			    /* external Graphic stroke */
			    const char *xlink_href = NULL;
			    int recolor = 0;
			    unsigned char red;
			    unsigned char green;
			    unsigned char blue;
			    pattern_stroke = NULL;
			    if (polyg_sym->stroke->graphic->first != NULL)
			      {
				  if (polyg_sym->stroke->graphic->first->type ==
				      RL2_EXTERNAL_GRAPHIC)
				    {
					rl2PrivExternalGraphicPtr ext =
					    (rl2PrivExternalGraphicPtr)
					    (polyg_sym->stroke->graphic->
					     first->item);
					xlink_href = ext->xlink_href;
					if (ext->first != NULL)
					  {
					      recolor = 1;
					      red = ext->first->red;
					      green = ext->first->green;
					      blue = ext->first->blue;
					  }
				    }
			      }
			    if (xlink_href != NULL)
				pattern_stroke =
				    rl2_create_pattern_from_external_graphic
				    (handle, xlink_href, 1);
			    if (pattern_stroke != NULL)
			      {
				  if (recolor)
				    {
					/* attempting to recolor the External Graphic resource */
					rl2_graph_pattern_recolor
					    (pattern_stroke, red, green, blue);
				    }
				  if (polyg_sym->stroke->opacity <= 0.0)
				      norm_opacity = 0;
				  else if (polyg_sym->stroke->opacity >= 1.0)
				      norm_opacity = 255;
				  else
				    {
					opacity =
					    255.0 * polyg_sym->stroke->opacity;
					if (opacity <= 0.0)
					    norm_opacity = 0;
					else if (opacity >= 255.0)
					    norm_opacity = 255;
					else
					    norm_opacity = opacity;
				    }
				  if (norm_opacity < 1.0)
				      rl2_graph_pattern_transparency
					  (pattern_stroke, norm_opacity);
				  rl2_graph_set_pattern_brush (ctx,
							       pattern_stroke);
			      }
			    else
			      {
				  /* invalid Pattern: defaulting to a Gray brush */
				  rl2_graph_set_brush (ctx, 128, 128, 128, 255);
			      }
			    stroke = 1;
			}
		      else
			{
			    /* solid RGB stroke */
			    if (polyg_sym->stroke->opacity <= 0.0)
				norm_opacity = 0;
			    else if (polyg_sym->stroke->opacity >= 1.0)
................................................................................
		int x;
		int y;
		int lastX = 0;
		int lastY = 0;
		int ib;
		rl2RingPtr ring = polyg->exterior;
		/* exterior border */
		if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
		  {


























		      for (iv = 0; iv < ring->points; iv++)
			{
			    rl2GetPoint (ring->coords, iv, &dx, &dy);
			    x = (int) ((dx - minx) / x_res);
			    y = height - (int) ((dy - miny) / y_res);
			    if (iv == 0)
			      {
................................................................................
					rl2_graph_add_line_to_path (ctx, x, y);
					lastX = x;
					lastY = y;
				    }
			      }
			}
		      rl2_graph_close_subpath (ctx);
		  }
		else
		  {
		      /* if the exterior ring is invisible we'll ignore all internal rings */
		      polyg = polyg->next;
		      continue;
		  }
		for (ib = 0; ib < polyg->num_interiors; ib++)
		  {
		      /* interior borders */
		      ring = polyg->interiors + ib;
		      if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
			{
			    for (iv = 0; iv < ring->points; iv++)
			      {
				  rl2GetPoint (ring->coords, iv, &dx, &dy);
				  x = (int) ((dx - minx) / x_res);
				  y = height - (int) ((dy - miny) / y_res);
				  if (iv == 0)
				    {
					rl2_graph_move_to_point (ctx, x, y);
					lastX = x;
					lastY = y;
				    }
				  else
				    {
					if (x == lastX && y == lastY)
					    ;
					else
					  {
					      rl2_graph_add_line_to_path (ctx,
									  x, y);
					      lastX = x;
					      lastY = y;
					  }
				    }
			      }
			    rl2_graph_close_subpath (ctx);
			}
		  }
		if (fill)
		  {
		      if (stroke)
			  rl2_graph_fill_path (ctx, RL2_PRESERVE_PATH);
		      else
			  rl2_graph_fill_path (ctx, RL2_CLEAR_PATH);
................................................................................
		rl2_graph_destroy_pattern (pattern_stroke);
	    }
	  item = item->next;
      }
}

static int
label_get_xy (sqlite3 * handle, const unsigned char *blob, int size,
	      double *x, double *y)
{
/* resolving Point XY coords */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    int ok = 0;

................................................................................
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_size = sqlite3_column_bytes (stmt, 0);
		      if (label_get_xy (handle, g_blob, g_size, x, y))
			  ok = 1;
		  }
	    }
      }
    sqlite3_finalize (stmt);
................................................................................
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_size = sqlite3_column_bytes (stmt, 0);
		      if (label_get_xy (handle, g_blob, g_size, x, y))
			  ok = 1;
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return ok;
}

static int
label_get_ring_midpoint (sqlite3 * handle, rl2RingPtr ring, double *x,
			 double *y)
{
/* computing a Ring MidPoint */
    unsigned char *blob;
    int blob_sz;
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    int ok = 0;

    if (ring == NULL)
	return 0;
    if (!rl2_serialize_ring_as_linestring (ring, &blob, &blob_sz))
	return 0;

    sql = "SELECT ST_Line_Interpolate_Point(?, 0.5)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return 0;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_size = sqlite3_column_bytes (stmt, 0);
		      if (label_get_xy (handle, g_blob, g_size, x, y))
			  ok = 1;
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return ok;
}

static rl2GeometryPtr
do_generalize_linestring (sqlite3 * handle, rl2LinestringPtr line,
			  double generalize_factor)
{
/* simplifying a Linestring */
    rl2GeometryPtr geom = NULL;
    unsigned char *blob;
    int blob_sz;
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;

    if (line == NULL)
	return NULL;
    if (line->points < 2)
	return NULL;
    if (!rl2_serialize_linestring (line, &blob, &blob_sz))
	return NULL;

    sql = "SELECT ST_Simplify(?, ?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
    sqlite3_bind_double (stmt, 2, generalize_factor);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return geom;
}

static rl2GeometryPtr
do_generalize_ring (sqlite3 * handle, rl2RingPtr ring, double generalize_factor)
{
/* simplifying a Ring */
    rl2GeometryPtr geom = NULL;
    unsigned char *blob;
    int blob_sz;
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;

    if (ring == NULL)
	return NULL;
    if (ring->points < 2)
	return NULL;
    if (!rl2_serialize_ring (ring, &blob, &blob_sz))
	return NULL;

    sql = "SELECT ST_SimplifyPreserveTopology(?, ?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
    sqlite3_bind_double (stmt, 2, generalize_factor);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return geom;
}

static int
check_valid_line (rl2LinestringPtr line)
{
/* testing for a valid linestring */
    int iv;
    int pts = 0;
    double x;
    double y;
    double x0;
    double y0;

    if (line == NULL)
	return 0;
    if (line->points < 2)
	return 0;
    rl2GetPoint (line->coords, 0, &x0, &y0);
    for (iv = 1; iv < line->points; iv++)
      {
	  rl2GetPoint (line->coords, iv, &x, &y);
	  if (x != x0 || y != y0)
	    {
		pts++;
		break;
	    }
      }
    if (pts == 0)
	return 0;
    return 1;
}

static rl2GeometryPtr
do_offset_linestring (sqlite3 * handle, rl2LinestringPtr line,
		      double perpendicular_offset)
{
/* Offest Curve (from Linestring) */
    rl2GeometryPtr geom = NULL;
    unsigned char *blob;
    int blob_sz;
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;

    if (!check_valid_line (line))
	return NULL;
    if (!rl2_serialize_linestring (line, &blob, &blob_sz))
	return NULL;

    sql = "SELECT ST_OffsetCurve(?, ?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
    sqlite3_bind_double (stmt, 2, perpendicular_offset);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return geom;
}

static int
check_valid_ring (rl2RingPtr ring)
{
/* testing for a valid ring */
    int iv;
    int pts = 0;
    int last;
    double x;
    double y;
    double x0;
    double y0;
    double x1;
    double y1;

    if (ring == NULL)
	return 0;
    if (ring->points < 4)
	return 0;
    rl2GetPoint (ring->coords, 0, &x0, &y0);
    for (iv = 1; iv < ring->points; iv++)
      {
	  rl2GetPoint (ring->coords, iv, &x, &y);
	  if (pts == 0)
	    {
		if (x != x0 || y != y0)
		  {
		      pts++;
		      x1 = x;
		      y1 = y;
		  }
	    }
	  else
	    {
		if ((x != x0 || y != y0) && (x != x1 || y != y1))
		  {
		      pts++;
		      break;
		  }
	    }
      }
    last = ring->points - 1;
    rl2GetPoint (ring->coords, last, &x1, &y1);
    if (pts == 2 && x0 == x1 && y0 == y1)
	return 1;
    return 0;
}

static rl2GeometryPtr
do_buffered_ring (sqlite3 * handle, rl2RingPtr ring,
		  double perpendicular_offset)
{
/* Buffer (from Ring) */
    rl2GeometryPtr geom = NULL;
    unsigned char *blob;
    int blob_sz;
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;

    if (!check_valid_ring (ring))
	return NULL;
    if (!rl2_serialize_ring (ring, &blob, &blob_sz))
	return NULL;

    sql = "SELECT ST_Buffer(?, ?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return NULL;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, blob, blob_sz, free);
    sqlite3_bind_double (stmt, 2, perpendicular_offset);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *g_blob =
			  (const unsigned char *) sqlite3_column_blob (stmt,
								       0);
		      int g_blob_sz = sqlite3_column_bytes (stmt, 0);
		      geom = rl2_geometry_from_blob (g_blob, g_blob_sz);
		  }
	    }
      }
    sqlite3_finalize (stmt);
    return geom;
}

static void
create_line_array_from_linestring (sqlite3 * handle, rl2LinestringPtr line,
				   double perpendicular_offset, int *points,
				   double **x_array, double **y_array,
				   int generalize_line,
				   double generalize_factor, int height,
				   double minx, double miny, double x_res,
				   double y_res)
{
/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */
    rl2GeometryPtr geom = NULL;
    rl2GeometryPtr geom2 = NULL;
    rl2LinestringPtr aux_line;
    rl2LinestringPtr in_line;
    double *xx = NULL;
    double *yy = NULL;
    int iv;
    double x;
    double y;

    *points = 0;
    *x_array = NULL;
    *y_array = NULL;
    if (line == NULL)
	goto error;

    aux_line = rl2_linestring_to_image (line, height, minx, miny, x_res, y_res);
    if (aux_line == NULL)
	goto error;
    in_line = aux_line;
    if (generalize_line)
      {
	  geom = do_generalize_linestring (handle, in_line, generalize_factor);
	  if (geom == NULL)
	      goto error;
	  in_line = geom->first_linestring;
	  if (in_line == NULL)
	      goto error;
      }
    if (perpendicular_offset != 0.0)
      {
	  geom2 = do_offset_linestring (handle, in_line, perpendicular_offset);
	  if (geom2 == NULL)
	      goto error;
	  in_line = geom2->first_linestring;
	  if (in_line == NULL)
	      goto error;
      }

/* allocating the X and Y arrays */
    if (in_line->points < 2)
	goto error;
    xx = malloc (sizeof (double) * in_line->points);
    yy = malloc (sizeof (double) * in_line->points);
    if (xx == NULL || yy == NULL)
      {
	  if (xx != NULL)
	      free (xx);
	  if (yy != NULL)
	      free (yy);
	  goto error;
      }
    for (iv = 0; iv < in_line->points; iv++)
      {
	  /* populating the X and Y arrays */
	  rl2GetPoint (in_line->coords, iv, &x, &y);
	  *(xx + iv) = x;
	  *(yy + iv) = y;
      }
    *points = in_line->points;
    *x_array = xx;
    *y_array = yy;

  error:
    if (aux_line)
	rl2DestroyLinestring (aux_line);
    if (geom)
	rl2_destroy_geometry (geom);
    if (geom2)
	rl2_destroy_geometry (geom2);
}

static void
create_line_array_from_ring (sqlite3 * handle, rl2RingPtr ring,
			     double perpendicular_offset, int *points,
			     double **x_array, double **y_array,
			     int generalize_line, double generalize_factor,
			     int height, double minx, double miny, double x_res,
			     double y_res)
{
/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */
    rl2GeometryPtr geom = NULL;
    rl2GeometryPtr geom2 = NULL;
    rl2PolygonPtr pg;
    rl2RingPtr aux_ring;
    rl2RingPtr in_ring;
    double *xx = NULL;
    double *yy = NULL;
    int iv;
    double x;
    double y;

    *points = 0;
    *x_array = NULL;
    *y_array = NULL;
    if (ring == NULL)
	goto error;

    aux_ring = rl2_ring_to_image (ring, height, minx, miny, x_res, y_res);
    if (aux_ring == NULL)
	goto error;
    in_ring = aux_ring;
    if (generalize_line)
      {
	  geom = do_generalize_ring (handle, in_ring, generalize_factor);
	  if (geom == NULL)
	      goto error;
	  pg = geom->first_polygon;
	  if (pg == NULL)
	      goto error;
	  in_ring = pg->exterior;
	  if (in_ring == NULL)
	      goto error;
      }
    if (perpendicular_offset != 0.0)
      {
	  geom2 = do_buffered_ring (handle, in_ring, perpendicular_offset);
	  if (geom2 == NULL)
	      goto error;
	  pg = geom2->first_polygon;
	  if (pg == NULL)
	      goto error;
	  in_ring = pg->exterior;
	  if (in_ring == NULL)
	      goto error;
      }

/* allocating the X and Y arrays */
    if (in_ring->points < 2)
	goto error;
    xx = malloc (sizeof (double) * in_ring->points);
    yy = malloc (sizeof (double) * in_ring->points);
    if (xx == NULL || yy == NULL)
      {
	  if (xx != NULL)
	      free (xx);
	  if (yy != NULL)
	      free (yy);
	  goto error;
      }
    for (iv = 0; iv < in_ring->points; iv++)
      {
	  /* populating the X and Y arrays */
	  rl2GetPoint (in_ring->coords, iv, &x, &y);
	  *(xx + iv) = x;
	  *(yy + iv) = y;
      }
    *points = in_ring->points;
    *x_array = xx;
    *y_array = yy;

  error:
    if (aux_ring)
	rl2DestroyRing (aux_ring);
    if (geom)
	rl2_destroy_geometry (geom);
    if (geom2)
	rl2_destroy_geometry (geom2);
}

static void
draw_labels (rl2GraphicsContextPtr ctx, sqlite3 * handle,
	     const void *priv_data, rl2PrivTextSymbolizerPtr sym, int height,
	     double minx, double miny, double maxx, double maxy, double x_res,
	     double y_res, rl2GeometryPtr geom, rl2PrivVariantValuePtr value)

{
/* drawing TextLabels */
    rl2GraphicsFontPtr font = NULL;
    char *dummy = NULL;
    const char *label = NULL;
    int font_style;
    int font_weight;
    double opacity;
    unsigned char norm_opacity;
    rl2PointPtr point;
    rl2LinestringPtr line;
    rl2PolygonPtr polyg;
    double rotation = 0.0;
    double anchor_point_x = 0.0;
    double anchor_point_y = 0.0;
    double displacement_x = 0.0;
    double displacement_y = 0.0;
    double perpendicular_offset = 0.0;
    int is_repeated = 0;
    double initial_gap = 0.0;
    double gap = 0.0;
    int is_aligned = 0;
    int generalize_line = 0;
    int i;

/* preparing the Text */
    if (value->sqlite3_type == SQLITE_INTEGER)
      {
	  dummy = sqlite3_malloc (1024);
#if defined(_WIN32) && !defined(__MINGW32__)
	  sprintf (dummy, "%I64d", value->int_value);
................................................................................
	  font_weight = RL2_FONTWEIGHT_BOLD;
	  break;
      case RL2_FONT_WEIGHT_NORMAL:
      default:
	  font_weight = RL2_FONTWEIGHT_NORMAL;
	  break;
      };
    for (i = 0; i < RL2_MAX_FONT_FAMILIES; i++)
      {
	  const char *facename = sym->font_families[i];
	  if (facename != NULL)
	      font =
		  rl2_search_TrueType_font (handle, priv_data, facename,
					    sym->font_size);
	  if (font != NULL)
	      break;
      }
    if (font == NULL)
      {
	  /* defaulting to a toy font */
	  font =
	      rl2_graph_create_toy_font (NULL, sym->font_size, font_style,
					 font_weight);
      }
    if (font == NULL)
	goto stop;
    if (sym->fill != NULL)
      {
	  if (sym->fill->opacity <= 0.0)
	      norm_opacity = 0;
	  else if (sym->fill->opacity >= 1.0)
................................................................................
		    norm_opacity = 0;
		else if (opacity >= 255.0)
		    norm_opacity = 255;
		else
		    norm_opacity = opacity;
	    }
	  rl2_graph_font_set_halo (font, sym->halo->radius,
				   sym->halo->fill->red,
				   sym->halo->fill->green,
				   sym->halo->fill->blue, norm_opacity);
      }
    rl2_graph_set_font (ctx, font);


    if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT)
      {
	  /* retrieving eventual Point Placement arguments */
	  rl2PrivPointPlacementPtr ptpl =
	      (rl2PrivPointPlacementPtr) (sym->label_placement);
	  if (ptpl != NULL)

	    {
		anchor_point_x = ptpl->anchor_point_x;
		anchor_point_y = ptpl->anchor_point_y;
		displacement_x = ptpl->displacement_x;
		displacement_y = ptpl->displacement_y;
		rotation = ptpl->rotation;
	    }
      }
    else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE)
      {
	  /* retrieving eventual Lineo Placement arguments */
	  rl2PrivLinePlacementPtr lnpl =
	      (rl2PrivLinePlacementPtr) (sym->label_placement);
	  if (lnpl != NULL)
	    {
		perpendicular_offset = lnpl->perpendicular_offset;
		is_repeated = lnpl->is_repeated;
		initial_gap = lnpl->initial_gap;
		gap = lnpl->gap;
		is_aligned = lnpl->is_aligned;
		generalize_line = lnpl->generalize_line;
	    }
      }

    if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT)
      {
	  /* POINT PLACEMENT */
	  rl2Point pt;
	  double cx;
	  double cy;
	  double x;
	  double y;

	  polyg = geom->first_polygon;
	  while (polyg)
	    {
		/* drawing a POLYGON-based text label */
		if (!label_get_centroid (handle, polyg, &cx, &cy))
		  {
		      polyg = polyg->next;
		      continue;
		  }
		pt.x = cx;
		pt.y = cy;
		if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
		  {
		      x = (cx - minx) / x_res;
		      y = (double) height - ((cy - miny) / y_res);




		      rl2_graph_draw_text (ctx, label, x + displacement_x,

					   y - displacement_y, rotation,
					   anchor_point_x, anchor_point_y);
		  }
		polyg = polyg->next;
	    }

	  line = geom->first_linestring;
	  while (line)
	    {
		/* drawing a LINESTRING-based text label */







		label_get_midpoint (handle, line, &cx, &cy);
		pt.x = cx;
		pt.y = cy;
		if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
		  {
		      x = (cx - minx) / x_res;
		      y = (double) height - ((cy - miny) / y_res);
		      rl2_graph_draw_text (ctx, label, x + displacement_x,
					   y - displacement_y, rotation,
					   anchor_point_x, anchor_point_y);
		  }
		line = line->next;
	    }

	  point = geom->first_point;
	  while (point)
	    {
		/* drawing a POINT-based text label */
		if (point_bbox_matches (point, minx, miny, maxx, maxy))
		  {
		      double x = (point->x - minx) / x_res;
		      double y = (double) height - ((point->y - miny) / y_res);
		      rl2_graph_draw_text (ctx, label, x + displacement_x,
					   y - displacement_y, rotation,
					   anchor_point_x, anchor_point_y);
		  }
		point = point->next;
	    }

      }
    else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE)
      {
	  /* LINE PLACEMENT */
	  rl2Point pt;
	  int ib;
	  double cx;
	  double cy;
	  double x;
	  double y;
	  double generalize_factor = 8.0;

	  line = geom->first_linestring;
	  while (line)
	    {
		/* drawing a LINESTRING-based text label */
		if (!is_aligned)
		  {
		      /* horizontal label aligned to center point */
		      label_get_midpoint (handle, line, &cx, &cy);



		      pt.x = cx;
		      pt.y = cy;
		      if (point_bbox_matches (&pt, minx, miny, maxx, maxy))
			{



			    x = (cx - minx) / x_res;
			    y = (double) height - ((cy - miny) / y_res);


			    rl2_graph_draw_text (ctx, label, x, y, 0.0, 0.5,
						 0.5);
			}
		  }
		else
		  {
		      /* label is warped along the line */
		      double *x_array = NULL;
		      double *y_array = NULL;
		      int points;
		      if (linestring_bbox_matches
			  (line, minx, miny, maxx, maxy))
			{
			    create_line_array_from_linestring (handle, line,
							       perpendicular_offset,
							       &points,
							       &x_array,
							       &y_array,
							       generalize_line,
							       generalize_factor,
							       height, minx,
							       miny, x_res,
							       y_res);
			    if (x_array != NULL && y_array != NULL)
				rl2_graph_draw_warped_text (handle, ctx, label,
							    points, x_array,
							    y_array,
							    initial_gap, gap,
							    is_repeated);
			    if (x_array)
				free (x_array);
			    if (y_array)
				free (y_array);
			}
		  }
		line = line->next;
	    }

	  polyg = geom->first_polygon;
	  while (polyg)
	    {
		/* drawing a POLYGON-based text label */
		rl2RingPtr ring = polyg->exterior;
		/* exterior border */
		if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
		  {
		      if (!is_aligned)
			{
			    /* horizontal label aligned to Ring's center point */
			    label_get_ring_midpoint (handle, ring, &cx, &cy);
			    pt.x = cx;
			    pt.y = cy;
			    if (point_bbox_matches
				(&pt, minx, miny, maxx, maxy))
			      {
				  x = (cx - minx) / x_res;
				  y = (double) height - ((cy - miny) / y_res);
				  rl2_graph_draw_text (ctx, label, x, y, 0.0,
						       0.5, 0.5);
			      }
			}
		      else
			{
			    /* label is warped along the Ring */
			    double *x_array = NULL;
			    double *y_array = NULL;






			    int points;
			    if (ring_bbox_matches
				(ring, minx, miny, maxx, maxy))
			      {
				  create_line_array_from_ring (handle, ring,
							       perpendicular_offset,
							       &points,
							       &x_array,
							       &y_array,
							       generalize_line,
							       generalize_factor,
							       height, minx,
							       miny, x_res,
							       y_res);
				  if (x_array != NULL && y_array != NULL)
				    {
					rl2_graph_draw_warped_text (handle, ctx,
								    label,
								    points,
								    x_array,
								    y_array,
								    initial_gap,
								    gap,
								    is_repeated);
				    }
				  if (x_array)
				      free (x_array);
				  if (y_array)
				      free (y_array);
			      }
			}
		  }
		else
		  {
		      /* if the exterior ring is invisible we'll ignore all internal rings */
		      polyg = polyg->next;
		      continue;
		  }
		for (ib = 0; ib < polyg->num_interiors; ib++)
		  {
		      /* interior borders */
		      ring = polyg->interiors + ib;
		      if (ring_bbox_matches (ring, minx, miny, maxx, maxy))
			{
			    if (!is_aligned)
			      {
				  /* horizontal label aligned to Ring's center point */
				  label_get_ring_midpoint (handle, ring, &cx,
							   &cy);
				  pt.x = cx;
				  pt.y = cy;
				  if (point_bbox_matches
				      (&pt, minx, miny, maxx, maxy))
				    {
					x = (cx - minx) / x_res;
					y = (double) height -




					    ((cy - miny) / y_res);
					rl2_graph_draw_text (ctx, label, x, y,

							     0.0, 0.5, 0.5);
				    }
			      }
			    else
			      {
				  /* label is warped along the Ring */
				  double *x_array = NULL;
				  double *y_array = NULL;
				  int points;
				  if (ring_bbox_matches
				      (ring, minx, miny, maxx, maxy))
				    {
					create_line_array_from_ring (handle,
								     ring,
								     perpendicular_offset,
								     &points,
								     &x_array,
								     &y_array,
								     generalize_line,
								     generalize_factor,
								     height,
								     minx, miny,
								     x_res,
								     y_res);
					if (x_array != NULL && y_array != NULL)
					    rl2_graph_draw_warped_text (handle,
									ctx,
									label,
									points,
									x_array,
									y_array,
									initial_gap,
									gap,
									is_repeated);
					if (x_array)
					    free (x_array);
					if (y_array)
					    free (y_array);
				    }
			      }
			}
		  }
		polyg = polyg->next;
	    }
      }

/* final cleanup - relasing resources */
  stop:
    if (dummy != NULL)
	sqlite3_free (dummy);
    if (font != NULL)
      {
	  rl2_graph_release_font (ctx);
	  rl2_graph_destroy_font (font);
      }
}

RL2_PRIVATE void
rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle, const void *priv_data,
			 rl2VectorSymbolizerPtr symbolizer, int height,
			 double minx, double miny, double maxx, double maxy,
			 double x_res, double y_res, rl2GeometryPtr geom,
			 rl2VariantArrayPtr variant)
{
/* drawing a vector feature on the current canvass */
    rl2PrivVectorSymbolizerItemPtr item;
    rl2GraphicsContextPtr ctx = (rl2GraphicsContextPtr) p_ctx;
    rl2PrivVectorSymbolizerPtr sym = (rl2PrivVectorSymbolizerPtr) symbolizer;
    rl2PrivVectorSymbolizerPtr default_symbolizer = NULL;

................................................................................
	      default_symbolizer->last->next = item;
	  default_symbolizer->last = item;
	  sym = default_symbolizer;
      }

/* we'll render all geometries first */
    if (geom->first_polygon != NULL)
	draw_polygons (ctx, handle, sym, height, minx, miny, maxx, maxy,
		       x_res, y_res, geom);
    if (geom->first_linestring != NULL)
	draw_lines (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res,
		    y_res, geom);
    if (geom->first_point != NULL)
	draw_points (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res,
		     y_res, geom);

    if (sym != NULL)
      {
	  /* then we'll render any eventual TextSymbolizer */
	  item = sym->first;
	  while (item != NULL)
	    {
................................................................................
		      rl2PrivTextSymbolizerPtr text =
			  (rl2PrivTextSymbolizerPtr) (item->symbolizer);
		      if (text->label != NULL)
			{
			    int v;
			    rl2PrivVariantArrayPtr var =
				(rl2PrivVariantArrayPtr) variant;
			    if (var != NULL)
			      {
				  for (v = 0; v < var->count; v++)
				    {
					rl2PrivVariantValuePtr val =
					    *(var->array + v);
					if (val == NULL)
					    continue;
					if (val->column_name == NULL)
					    continue;
					if (strcasecmp
					    (text->label,
					     val->column_name) != 0)

					    continue;
/* to be fixed - sometimes it raises a Cairo exception about Fonts 
					draw_labels (ctx, handle, priv_data,
						     text, height, minx, miny,
						     maxx, maxy, x_res, y_res,
						     geom, val);

*/
				    }
			      }
			}
		  }
		item = item->next;
	    }
      }

    if (default_symbolizer != NULL)
	rl2_destroy_vector_symbolizer (default_symbolizer);
}

RL2_PRIVATE int
rl2_aux_default_image (unsigned int width, unsigned int height,
		       unsigned char red, unsigned char green,
		       unsigned char blue, int format, int transparent,
		       int quality, unsigned char **ximage, int *ximage_sz)
{
/* creating a default image */
    unsigned int x;
    unsigned int y;
    unsigned char *pixels = malloc (width * height * 3);
    unsigned char *po = pixels;
    unsigned char *mask = NULL;
    unsigned char *pm;

    *ximage = NULL;
    *ximage_sz = 0;
    if (pixels == NULL)
	return 0;

    mask = malloc (width * height);
    if (mask == NULL)
	goto error;
    pm = mask;

/* priming the image buffer to background color */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		*po++ = red;
		*po++ = green;
		*po++ = blue;
		if (mask != NULL)
		    *pm++ = 0;
	    }
      }

    if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (transparent)
	    {
		if (rl2_rgb_alpha_to_png
		    (width, height, pixels, mask, ximage, ximage_sz,
		     1.0) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_rgb_to_png (width, height, pixels, ximage, ximage_sz)
		    != RL2_OK)
		    goto error;
	    }
      }
    else if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_rgb_to_jpeg
	      (width, height, pixels, quality, ximage, ximage_sz) != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_TIFF)
      {
	  if (rl2_rgb_to_tiff (width, height, pixels, ximage, ximage_sz) !=
	      RL2_OK)
	      goto error;
      }
    else
	goto error;
    free (pixels);
    if (mask != NULL)
	free (mask);
    return 1;

  error:
    if (pixels != NULL)
	free (pixels);
    if (mask != NULL)
	free (mask);
    return 0;
}

Changes to src/rl2charls.c.

52
53
54
55
56
57
58



59

60
61
62
63
64
65
66
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#endif

#include "rasterlite2/rasterlite2.h"
#include "rasterlite2_private.h"

#ifndef OMIT_CHARLS		/* only if CharLS is enabled */




#include <CharLS/interface.h>


static int
endianness ()
{
/* checking if target CPU is a little-endian one */
    union cvt
    {
................................................................................
		      p_out += num_bands;
		  }
	    }
      }
}

static void
from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width, int height,
		   int num_bands)
{
/* rearranging pixels from separate LINE components - UINT 8 */
    int x;
    int y;
    int ib;
    unsigned char *p_in = in;

................................................................................
      {
	  if (*sample_type == RL2_SAMPLE_UINT16)
	      from_ilv_buffer_16 ((unsigned short *) (*pixels),
				  (unsigned short *) out_buffer, *width,
				  *height, *num_bands);
	  else
	      from_ilv_buffer_8 ((unsigned char *) (*pixels),
				 (unsigned char *) out_buffer, *width, *height,
				 *num_bands);
      }
    free (out_buffer);
    return RL2_OK;

  error:
    if (out_buffer != NULL)
	free (out_buffer);
    return RL2_ERROR;
}

#endif /* end CharLS conditional */







>
>
>

>







 







|
|







 







|
|











52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#endif

#include "rasterlite2/rasterlite2.h"
#include "rasterlite2_private.h"

#ifndef OMIT_CHARLS		/* only if CharLS is enabled */

#ifdef __ANDROID__		/* Android specific */
#include <interface.h>
#else
#include <CharLS/interface.h>
#endif

static int
endianness ()
{
/* checking if target CPU is a little-endian one */
    union cvt
    {
................................................................................
		      p_out += num_bands;
		  }
	    }
      }
}

static void
from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width,
		   int height, int num_bands)
{
/* rearranging pixels from separate LINE components - UINT 8 */
    int x;
    int y;
    int ib;
    unsigned char *p_in = in;

................................................................................
      {
	  if (*sample_type == RL2_SAMPLE_UINT16)
	      from_ilv_buffer_16 ((unsigned short *) (*pixels),
				  (unsigned short *) out_buffer, *width,
				  *height, *num_bands);
	  else
	      from_ilv_buffer_8 ((unsigned char *) (*pixels),
				 (unsigned char *) out_buffer, *width,
				 *height, *num_bands);
      }
    free (out_buffer);
    return RL2_OK;

  error:
    if (out_buffer != NULL)
	free (out_buffer);
    return RL2_ERROR;
}

#endif /* end CharLS conditional */

Changes to src/rl2codec.c.

2018
2019
2020
2021
2022
2023
2024
2025
2026
2027

2028
2029
2030
2031
2032
2033
2034
....
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
....
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
....
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
....
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
....
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
....
3129
3130
3131
3132
3133
3134
3135
3136

3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
....
3214
3215
3216
3217
3218
3219
3220
3221

3222
3223
3224
3225
3226
3227
3228
....
3230
3231
3232
3233
3234
3235
3236


























3237
3238
3239
3240
3241
3242
3243
....
4190
4191
4192
4193
4194
4195
4196
4197

4198
4199
4200
4201
4202
4203
4204
4205
4206
....
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
....
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
....
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
....
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
....
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
....
5380
5381
5382
5383
5384
5385
5386
5387

5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
....
5409
5410
5411
5412
5413
5414
5415
5416

5417
5418
5419
5420
5421
5422
5423
5424
5425
....
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
....
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
....
5609
5610
5611
5612
5613
5614
5615















































































































5616
5617
5618
5619
5620
5621
5622
....
5883
5884
5885
5886
5887
5888
5889
5890

5891
5892
5893
5894
5895
5896
5897
....
6493
6494
6495
6496
6497
6498
6499
6500

6501
6502
6503
6504
6505
6506
6507
    *pixels_even = pix_even;
    *size_odd = o_size;
    *size_even = e_size;
    return 1;
}

RL2_DECLARE int
rl2_raster_encode (rl2RasterPtr rst, int compression, unsigned char **blob_odd,
		   int *blob_odd_sz, unsigned char **blob_even,
		   int *blob_even_sz, int quality, int little_endian)

{
/* encoding a Raster into the internal RL2 binary format */
    rl2PrivRasterPtr raster = (rl2PrivRasterPtr) rst;
    int odd_rows;
    unsigned char *pixels_odd = NULL;
    int size_odd;
    int even_rows = 0;
................................................................................
	|| compression == RL2_COMPRESSION_LZMA_NO)
      {
	  /* preparing the pixels buffers */
	  if (raster->sampleType == RL2_SAMPLE_1_BIT)
	    {
		/* packing 1-BIT data */
		if (!pack_1bit_rows
		    (raster, raster->rasterBuffer, &row_stride_odd, &pixels_odd,
		     &size_odd))
		    return RL2_ERROR;
		odd_rows = raster->height;
	    }
	  else if (raster->sampleType == RL2_SAMPLE_2_BIT)
	    {
		/* packing 2-BIT data */
		if (!pack_2bit_rows
................................................................................
		    return RL2_ERROR;
		odd_rows = raster->height;
	    }
	  else
	    {
		/* Odd/Even raster */
		if (!odd_even_rows
		    (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd,
		     &even_rows, &row_stride_even, &pixels_even, &size_even,
		     little_endian))
		    return RL2_ERROR;
	    }
      }
    else if (compression == RL2_COMPRESSION_PNG)
      {
	  if (raster->sampleType == RL2_SAMPLE_1_BIT
	      || raster->sampleType == RL2_SAMPLE_2_BIT
................................................................................
	    {
		/* no special action is required */
	    }
	  else
	    {
		/* Odd/Even raster */
		if (!odd_even_rows
		    (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd,
		     &even_rows, &row_stride_even, &pixels_even, &size_even,
		     little_endian))
		    return RL2_ERROR;
	    }
      }
    else if (compression == RL2_COMPRESSION_CHARLS)
      {
	  /* Odd/Even raster */
	  if (!odd_even_rows
................................................................................
	  goto error;
#endif /* end WebP conditional */
      }
    else if (compression == RL2_COMPRESSION_LOSSY_WEBP)
      {
#ifndef OMIT_WEBP		/* only if WebP is enabled */
	  /* compressing as lossy WEBP */
	  if (rl2_raster_to_lossy_webp (rst, &compr_data, &compressed, quality)
	      == RL2_OK)
	    {
		/* ok, lossy WEBP compression was successful */
		uncompressed = raster->width * raster->height * raster->nBands;
		to_clean1 = compr_data;
	    }
	  else
	      goto error;
................................................................................
	  else
	      goto error;
      }
    else if (compression == RL2_COMPRESSION_LOSSLESS_JP2)
      {
#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
	  /* compressing as lossless Jpeg2000 */
	  if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed) ==
	      RL2_OK)
	    {
		/* ok, lossless Jpeg2000 compression was successful */
		uncompressed = raster->width * raster->height * raster->nBands;
		to_clean1 = compr_data;
	    }
	  else
	      goto error;
................................................................................
		      compressed = (int) zLen;
		      compr_data = zip_buf;
		      to_clean2 = zip_buf;
		  }
		else if (ret == Z_BUF_ERROR)
		  {
		      /* ZIP compression actually causes inflation: saving uncompressed data */
		      if (rl2_delta_decode (pixels_even, size_even, delta_dist)
			  != RL2_OK)
			  goto error;
		      uncompressed = size_even;
		      compressed = size_even;
		      compr_data = pixels_even;
		      free (zip_buf);
		      zip_buf = NULL;
		  }
................................................................................
    *xnum_bands = num_bands;
    *xcompression = compression;
    *xcrc = crc;
    return 1;
}

static int
check_blob_even (const unsigned char *blob, int blob_sz, unsigned short xwidth,

		 unsigned short xheight, unsigned char xsample_type,
		 unsigned char xpixel_type, unsigned char xnum_bands,
		 unsigned char xcompression, uLong xcrc)
{
/* checking the EvenBlock for validity */
    const unsigned char *ptr;
    unsigned short width;
    unsigned short height;
    unsigned char sample_type;
    unsigned char pixel_type;
................................................................................
check_scale (int scale, unsigned char sample_type, unsigned char compression,
	     const unsigned char *blob_even)
{
/* checking if the encoded raster could be decoded at given scale */
    switch (scale)
      {
      case RL2_SCALE_1:
	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT

	      || sample_type == RL2_SAMPLE_4_BIT)
	      ;
	  else if (compression == RL2_COMPRESSION_JPEG
		   || compression == RL2_COMPRESSION_LOSSY_WEBP
		   || compression == RL2_COMPRESSION_LOSSLESS_WEBP
		   || compression == RL2_COMPRESSION_CCITTFAX4
		   || compression == RL2_COMPRESSION_LOSSY_JP2
................................................................................
	    {
		if (blob_even != NULL)
		    return 0;
	    }
	  else if (blob_even == NULL)
	      return 0;
	  break;


























      case RL2_SCALE_2:
      case RL2_SCALE_4:
      case RL2_SCALE_8:
	  break;
      default:
	  return 0;
      };
................................................................................
		else
		    *p_out++ = *p_even++;
	    }
      }
}

static void
do_copy_uint32 (int swap, const unsigned int *p_odd, const unsigned int *p_even,

		unsigned int *buf, unsigned short width,
		unsigned short odd_rows, unsigned short even_rows)
{
/* reassembling an UINT32 raster - scale 1:1 */
    int row;
    int col;
    unsigned int *p_out;

    p_out = buf;
................................................................................
    return 1;
}

RL2_DECLARE int
rl2_is_valid_dbms_raster_tile (unsigned short level, unsigned int tile_width,
			       unsigned int tile_height,
			       const unsigned char *blob_odd, int blob_odd_sz,
			       const unsigned char *blob_even, int blob_even_sz,
			       unsigned char sample_type,
			       unsigned char pixel_type,
			       unsigned char num_bands,
			       unsigned char compression)
{
/* testing a serialized Raster Tile object for validity */
    unsigned int width;
    unsigned int height;
................................................................................
	    {
		/* small-PALETTE: expecting an RGB/PNG Pyramid tile */
		if (xsample_type == RL2_SAMPLE_UINT8
		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
		    && xcompression == RL2_COMPRESSION_PNG)
		    return RL2_OK;
	    }
	  if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE
	      && num_bands == 1)
	    {
		/* PALETTE 8bits: expecting an RGB/PNG Pyramid tile */
		if (xsample_type == RL2_SAMPLE_UINT8
		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
		    && xcompression == RL2_COMPRESSION_PNG)
		    return RL2_OK;
	    }
................................................................................
    if (!check_blob_odd
	(blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type,
	 &num_bands, &compression, &crc))
	return NULL;
    if (blob_even != NULL)
      {
	  if (!check_blob_even
	      (blob_even, blob_even_sz, width, height, sample_type, pixel_type,
	       num_bands, compression, crc))
	      return NULL;
      }
    if (!check_scale (scale, sample_type, compression, blob_even))
	return NULL;

    switch (pixel_type)
      {
................................................................................
		const Bytef *in = pixels_even;
		even_data = malloc (uncompressed_even);
		if (even_data == NULL)
		    goto error;
		if (uncompress (even_data, &refLen, in, compressed_even) !=
		    Z_OK)
		    goto error;
		if (rl2_delta_decode (even_data, uncompressed_even, delta_dist)
		    != RL2_OK)
		    goto error;
		pixels_even = even_data;
	    }
      }
    if (compression == RL2_COMPRESSION_DEFLATE_NO
	&& uncompressed_odd != compressed_odd)
      {
................................................................................
	  int ret = RL2_ERROR;
	  unsigned char pix_typ;
	  switch (scale)
	    {
	    case RL2_SCALE_1:
		ret =
		    rl2_decode_jpeg_scaled (1, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ, &pixels,
					    &pixels_sz);
		break;
	    case RL2_SCALE_2:
		ret =
		    rl2_decode_jpeg_scaled (2, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ, &pixels,
					    &pixels_sz);
		break;
	    case RL2_SCALE_4:
		ret =
		    rl2_decode_jpeg_scaled (4, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ, &pixels,
					    &pixels_sz);
		break;
	    case RL2_SCALE_8:
		ret =
		    rl2_decode_jpeg_scaled (8, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ, &pixels,
					    &pixels_sz);
		break;
	    };
	  if (ret != RL2_OK)
	      goto error;
	  goto done;
      }
    if (compression == RL2_COMPRESSION_LOSSY_WEBP
................................................................................
	  goto error;
#endif /* end WebP conditional */
      }
    if (compression == RL2_COMPRESSION_PNG)
      {
	  /* decompressing from PNG */
	  int ret;
	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT

	      || sample_type == RL2_SAMPLE_4_BIT)
	    {
		/* Palette or Grayscale - 1,2 or 4 bit isn't scalable */
		if (scale != RL2_SCALE_1)
		    goto error;
		ret =
		    rl2_decode_png (pixels_odd, compressed_odd,
				    &width, &height, &sample_type, &pixel_type,
				    &num_bands, &pixels, &pixels_sz, &mask,
				    &mask_sz, &palette, 0);
		if (ret != RL2_OK)
		    goto error;
		goto done;
	    }
	  else
	    {
		ret = rl2_decode_png (pixels_odd, compressed_odd,
................................................................................
		if (ret != RL2_OK)
		    goto error;
		pixels_odd = odd_data;
		if (scale == RL2_SCALE_1)
		  {
		      ret = rl2_decode_png (pixels_even, compressed_even,
					    &width, &even_rows, &sample_type,
					    &pixel_type, &num_bands, &even_data,

					    &pixels_sz, &even_mask,
					    &even_mask_sz, &palette2, 0);
		      if (ret != RL2_OK)
			  goto error;
		      rl2_destroy_palette (palette2);
		  }
		pixels_even = even_data;
		if (odd_mask != NULL)
		    free (odd_mask);
................................................................................
	  int ret = RL2_ERROR;
	  switch (scale)
	    {
	    case RL2_SCALE_1:
		ret =
		    rl2_decode_jpeg2000_scaled (1, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands, &pixels,
						&pixels_sz);
		break;
	    case RL2_SCALE_2:
		ret =
		    rl2_decode_jpeg2000_scaled (2, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands, &pixels,
						&pixels_sz);
		break;
	    case RL2_SCALE_4:
		ret =
		    rl2_decode_jpeg2000_scaled (4, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands, &pixels,
						&pixels_sz);
		break;
	    case RL2_SCALE_8:
		ret =
		    rl2_decode_jpeg2000_scaled (8, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands, &pixels,
						&pixels_sz);
		break;
	    };
	  if (ret != RL2_OK)
	      goto error;
	  goto done;
#else /* OpenJpeg is disabled */
	  fprintf (stderr,
................................................................................
      {
	  /* unpacking the mask */
	  unsigned char *mask_pix;
	  int mask_pix_sz;
	  if (uncompressed_mask != (mask_width * mask_height))
	      goto error;
	  if (!unpack_rle
	      (mask_width, mask_height, pixels_mask, compressed_mask, &mask_pix,
	       &mask_pix_sz))
	      goto error;
	  if (!rescale_mask
	      (scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz))
	    {
		free (mask_pix);
		goto error;
	    }
................................................................................
	free (mask);
    if (palette != NULL)
	rl2_destroy_palette (palette);
    if (ext_palette != NULL)
	rl2_destroy_palette (ext_palette);
    return NULL;
}
















































































































static void
add_pooled_variance (rl2PrivBandStatisticsPtr band_in,
		     rl2PrivBandStatisticsPtr band_out, double count)
{
/* adding a Pooled Variance item */
    rl2PoolVariancePtr pool = malloc (sizeof (rl2PoolVariance));
................................................................................
      {
	  ignore_no_data = 0;
	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
	      != RL2_OK)
	      ignore_no_data = 1;
	  if (nbands != num_bands)
	      ignore_no_data = 1;
	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT

	      || sample_type == RL2_SAMPLE_4_BIT
	      || sample_type == RL2_SAMPLE_UINT8)
	      ;
	  else
	      ignore_no_data = 1;
      }

................................................................................
	    }
      }
    compute_int32_histogram (width, height, pixels, mask, st, no_data);
}

static void
compute_uint32_histogram (unsigned short width, unsigned short height,
			  const unsigned int *pixels, const unsigned char *mask,

			  rl2PrivRasterStatisticsPtr st, rl2PixelPtr no_data)
{
/* computing INT16 tile histogram */
    int x;
    int y;
    const unsigned int *p_in = pixels;
    const unsigned char *p_msk = mask;







|
|
|
>







 







|
|







 







|
|
|







 







|
|
|







 







|
|







 







|
|







 







|
|







 







|
>
|
|
|







 







|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|




|
|




|
|




|
|







 







|
>







|
|
|







 







|
>
|
|







 







|
|





|
|





|
|





|
|







 







|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>







 







|
>







2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
....
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
....
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
....
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
....
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
....
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
....
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
....
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
....
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
....
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
....
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
....
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
....
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
....
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
....
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
....
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
....
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
....
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
....
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
....
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
....
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
....
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
....
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
    *pixels_even = pix_even;
    *size_odd = o_size;
    *size_even = e_size;
    return 1;
}

RL2_DECLARE int
rl2_raster_encode (rl2RasterPtr rst, int compression,
		   unsigned char **blob_odd, int *blob_odd_sz,
		   unsigned char **blob_even, int *blob_even_sz, int quality,
		   int little_endian)
{
/* encoding a Raster into the internal RL2 binary format */
    rl2PrivRasterPtr raster = (rl2PrivRasterPtr) rst;
    int odd_rows;
    unsigned char *pixels_odd = NULL;
    int size_odd;
    int even_rows = 0;
................................................................................
	|| compression == RL2_COMPRESSION_LZMA_NO)
      {
	  /* preparing the pixels buffers */
	  if (raster->sampleType == RL2_SAMPLE_1_BIT)
	    {
		/* packing 1-BIT data */
		if (!pack_1bit_rows
		    (raster, raster->rasterBuffer, &row_stride_odd,
		     &pixels_odd, &size_odd))
		    return RL2_ERROR;
		odd_rows = raster->height;
	    }
	  else if (raster->sampleType == RL2_SAMPLE_2_BIT)
	    {
		/* packing 2-BIT data */
		if (!pack_2bit_rows
................................................................................
		    return RL2_ERROR;
		odd_rows = raster->height;
	    }
	  else
	    {
		/* Odd/Even raster */
		if (!odd_even_rows
		    (raster, &odd_rows, &row_stride_odd, &pixels_odd,
		     &size_odd, &even_rows, &row_stride_even, &pixels_even,
		     &size_even, little_endian))
		    return RL2_ERROR;
	    }
      }
    else if (compression == RL2_COMPRESSION_PNG)
      {
	  if (raster->sampleType == RL2_SAMPLE_1_BIT
	      || raster->sampleType == RL2_SAMPLE_2_BIT
................................................................................
	    {
		/* no special action is required */
	    }
	  else
	    {
		/* Odd/Even raster */
		if (!odd_even_rows
		    (raster, &odd_rows, &row_stride_odd, &pixels_odd,
		     &size_odd, &even_rows, &row_stride_even, &pixels_even,
		     &size_even, little_endian))
		    return RL2_ERROR;
	    }
      }
    else if (compression == RL2_COMPRESSION_CHARLS)
      {
	  /* Odd/Even raster */
	  if (!odd_even_rows
................................................................................
	  goto error;
#endif /* end WebP conditional */
      }
    else if (compression == RL2_COMPRESSION_LOSSY_WEBP)
      {
#ifndef OMIT_WEBP		/* only if WebP is enabled */
	  /* compressing as lossy WEBP */
	  if (rl2_raster_to_lossy_webp
	      (rst, &compr_data, &compressed, quality) == RL2_OK)
	    {
		/* ok, lossy WEBP compression was successful */
		uncompressed = raster->width * raster->height * raster->nBands;
		to_clean1 = compr_data;
	    }
	  else
	      goto error;
................................................................................
	  else
	      goto error;
      }
    else if (compression == RL2_COMPRESSION_LOSSLESS_JP2)
      {
#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
	  /* compressing as lossless Jpeg2000 */
	  if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed)
	      == RL2_OK)
	    {
		/* ok, lossless Jpeg2000 compression was successful */
		uncompressed = raster->width * raster->height * raster->nBands;
		to_clean1 = compr_data;
	    }
	  else
	      goto error;
................................................................................
		      compressed = (int) zLen;
		      compr_data = zip_buf;
		      to_clean2 = zip_buf;
		  }
		else if (ret == Z_BUF_ERROR)
		  {
		      /* ZIP compression actually causes inflation: saving uncompressed data */
		      if (rl2_delta_decode
			  (pixels_even, size_even, delta_dist) != RL2_OK)
			  goto error;
		      uncompressed = size_even;
		      compressed = size_even;
		      compr_data = pixels_even;
		      free (zip_buf);
		      zip_buf = NULL;
		  }
................................................................................
    *xnum_bands = num_bands;
    *xcompression = compression;
    *xcrc = crc;
    return 1;
}

static int
check_blob_even (const unsigned char *blob, int blob_sz,
		 unsigned short xwidth, unsigned short xheight,
		 unsigned char xsample_type, unsigned char xpixel_type,
		 unsigned char xnum_bands, unsigned char xcompression,
		 uLong xcrc)
{
/* checking the EvenBlock for validity */
    const unsigned char *ptr;
    unsigned short width;
    unsigned short height;
    unsigned char sample_type;
    unsigned char pixel_type;
................................................................................
check_scale (int scale, unsigned char sample_type, unsigned char compression,
	     const unsigned char *blob_even)
{
/* checking if the encoded raster could be decoded at given scale */
    switch (scale)
      {
      case RL2_SCALE_1:
	  if (sample_type == RL2_SAMPLE_1_BIT
	      || sample_type == RL2_SAMPLE_2_BIT
	      || sample_type == RL2_SAMPLE_4_BIT)
	      ;
	  else if (compression == RL2_COMPRESSION_JPEG
		   || compression == RL2_COMPRESSION_LOSSY_WEBP
		   || compression == RL2_COMPRESSION_LOSSLESS_WEBP
		   || compression == RL2_COMPRESSION_CCITTFAX4
		   || compression == RL2_COMPRESSION_LOSSY_JP2
................................................................................
	    {
		if (blob_even != NULL)
		    return 0;
	    }
	  else if (blob_even == NULL)
	      return 0;
	  break;
      case RL2_SCALE_2:
      case RL2_SCALE_4:
      case RL2_SCALE_8:
	  break;
      default:
	  return 0;
      };
    switch (sample_type)
      {
      case RL2_SAMPLE_1_BIT:
      case RL2_SAMPLE_2_BIT:
      case RL2_SAMPLE_4_BIT:
	  if (scale != RL2_SCALE_1)
	      return 0;
	  break;
      };
    return 1;
}

static int
check_scale2 (int scale, unsigned char sample_type)
{
/* checking if the encoded raster could be decoded at given scale */
    switch (scale)
      {
      case RL2_SCALE_1:
      case RL2_SCALE_2:
      case RL2_SCALE_4:
      case RL2_SCALE_8:
	  break;
      default:
	  return 0;
      };
................................................................................
		else
		    *p_out++ = *p_even++;
	    }
      }
}

static void
do_copy_uint32 (int swap, const unsigned int *p_odd,
		const unsigned int *p_even, unsigned int *buf,
		unsigned short width, unsigned short odd_rows,
		unsigned short even_rows)
{
/* reassembling an UINT32 raster - scale 1:1 */
    int row;
    int col;
    unsigned int *p_out;

    p_out = buf;
................................................................................
    return 1;
}

RL2_DECLARE int
rl2_is_valid_dbms_raster_tile (unsigned short level, unsigned int tile_width,
			       unsigned int tile_height,
			       const unsigned char *blob_odd, int blob_odd_sz,
			       const unsigned char *blob_even,
			       int blob_even_sz, unsigned char sample_type,
			       unsigned char pixel_type,
			       unsigned char num_bands,
			       unsigned char compression)
{
/* testing a serialized Raster Tile object for validity */
    unsigned int width;
    unsigned int height;
................................................................................
	    {
		/* small-PALETTE: expecting an RGB/PNG Pyramid tile */
		if (xsample_type == RL2_SAMPLE_UINT8
		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
		    && xcompression == RL2_COMPRESSION_PNG)
		    return RL2_OK;
	    }
	  if (sample_type == RL2_SAMPLE_UINT8
	      && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1)
	    {
		/* PALETTE 8bits: expecting an RGB/PNG Pyramid tile */
		if (xsample_type == RL2_SAMPLE_UINT8
		    && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3
		    && xcompression == RL2_COMPRESSION_PNG)
		    return RL2_OK;
	    }
................................................................................
    if (!check_blob_odd
	(blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type,
	 &num_bands, &compression, &crc))
	return NULL;
    if (blob_even != NULL)
      {
	  if (!check_blob_even
	      (blob_even, blob_even_sz, width, height, sample_type,
	       pixel_type, num_bands, compression, crc))
	      return NULL;
      }
    if (!check_scale (scale, sample_type, compression, blob_even))
	return NULL;

    switch (pixel_type)
      {
................................................................................
		const Bytef *in = pixels_even;
		even_data = malloc (uncompressed_even);
		if (even_data == NULL)
		    goto error;
		if (uncompress (even_data, &refLen, in, compressed_even) !=
		    Z_OK)
		    goto error;
		if (rl2_delta_decode
		    (even_data, uncompressed_even, delta_dist) != RL2_OK)
		    goto error;
		pixels_even = even_data;
	    }
      }
    if (compression == RL2_COMPRESSION_DEFLATE_NO
	&& uncompressed_odd != compressed_odd)
      {
................................................................................
	  int ret = RL2_ERROR;
	  unsigned char pix_typ;
	  switch (scale)
	    {
	    case RL2_SCALE_1:
		ret =
		    rl2_decode_jpeg_scaled (1, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ,
					    &pixels, &pixels_sz);
		break;
	    case RL2_SCALE_2:
		ret =
		    rl2_decode_jpeg_scaled (2, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ,
					    &pixels, &pixels_sz);
		break;
	    case RL2_SCALE_4:
		ret =
		    rl2_decode_jpeg_scaled (4, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ,
					    &pixels, &pixels_sz);
		break;
	    case RL2_SCALE_8:
		ret =
		    rl2_decode_jpeg_scaled (8, pixels_odd, compressed_odd,
					    &width, &height, &pix_typ,
					    &pixels, &pixels_sz);
		break;
	    };
	  if (ret != RL2_OK)
	      goto error;
	  goto done;
      }
    if (compression == RL2_COMPRESSION_LOSSY_WEBP
................................................................................
	  goto error;
#endif /* end WebP conditional */
      }
    if (compression == RL2_COMPRESSION_PNG)
      {
	  /* decompressing from PNG */
	  int ret;
	  if (sample_type == RL2_SAMPLE_1_BIT
	      || sample_type == RL2_SAMPLE_2_BIT
	      || sample_type == RL2_SAMPLE_4_BIT)
	    {
		/* Palette or Grayscale - 1,2 or 4 bit isn't scalable */
		if (scale != RL2_SCALE_1)
		    goto error;
		ret =
		    rl2_decode_png (pixels_odd, compressed_odd,
				    &width, &height, &sample_type,
				    &pixel_type, &num_bands, &pixels,
				    &pixels_sz, &mask, &mask_sz, &palette, 0);
		if (ret != RL2_OK)
		    goto error;
		goto done;
	    }
	  else
	    {
		ret = rl2_decode_png (pixels_odd, compressed_odd,
................................................................................
		if (ret != RL2_OK)
		    goto error;
		pixels_odd = odd_data;
		if (scale == RL2_SCALE_1)
		  {
		      ret = rl2_decode_png (pixels_even, compressed_even,
					    &width, &even_rows, &sample_type,
					    &pixel_type, &num_bands,
					    &even_data, &pixels_sz,
					    &even_mask, &even_mask_sz,
					    &palette2, 0);
		      if (ret != RL2_OK)
			  goto error;
		      rl2_destroy_palette (palette2);
		  }
		pixels_even = even_data;
		if (odd_mask != NULL)
		    free (odd_mask);
................................................................................
	  int ret = RL2_ERROR;
	  switch (scale)
	    {
	    case RL2_SCALE_1:
		ret =
		    rl2_decode_jpeg2000_scaled (1, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands,
						&pixels, &pixels_sz);
		break;
	    case RL2_SCALE_2:
		ret =
		    rl2_decode_jpeg2000_scaled (2, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands,
						&pixels, &pixels_sz);
		break;
	    case RL2_SCALE_4:
		ret =
		    rl2_decode_jpeg2000_scaled (4, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands,
						&pixels, &pixels_sz);
		break;
	    case RL2_SCALE_8:
		ret =
		    rl2_decode_jpeg2000_scaled (8, pixels_odd, compressed_odd,
						&width, &height, sample_type,
						pixel_type, num_bands,
						&pixels, &pixels_sz);
		break;
	    };
	  if (ret != RL2_OK)
	      goto error;
	  goto done;
#else /* OpenJpeg is disabled */
	  fprintf (stderr,
................................................................................
      {
	  /* unpacking the mask */
	  unsigned char *mask_pix;
	  int mask_pix_sz;
	  if (uncompressed_mask != (mask_width * mask_height))
	      goto error;
	  if (!unpack_rle
	      (mask_width, mask_height, pixels_mask, compressed_mask,
	       &mask_pix, &mask_pix_sz))
	      goto error;
	  if (!rescale_mask
	      (scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz))
	    {
		free (mask_pix);
		goto error;
	    }
................................................................................
	free (mask);
    if (palette != NULL)
	rl2_destroy_palette (palette);
    if (ext_palette != NULL)
	rl2_destroy_palette (ext_palette);
    return NULL;
}

RL2_PRIVATE rl2RasterPtr
rl2_raster_decode_mask (int scale, const unsigned char *blob_odd,
			int blob_odd_sz, int *status)
{
/* decoding from internal RL2 binary format to Raster - transparency mask only */
    rl2RasterPtr raster;
    unsigned int width;
    unsigned int height;
    unsigned short mask_width = 0;
    unsigned short mask_height = 0;
    unsigned char sample_type;
    unsigned char pixel_type;
    unsigned char num_bands;
    unsigned char compression;
    int compressed_odd;
    int uncompressed_mask;
    int compressed_mask;
    uLong crc;
    const unsigned char *pixels_mask = NULL;
    unsigned char *pixels = NULL;
    int pixels_sz;
    unsigned char *mask = NULL;
    int mask_sz = 0;
    const unsigned char *ptr;
    int endian;
    int endian_arch = endianArch ();

    *status = RL2_ERROR;
    if (blob_odd == NULL)
	return NULL;
    if (!check_blob_odd
	(blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type,
	 &num_bands, &compression, &crc))
	return NULL;
    if (!check_scale2 (scale, sample_type))
	return NULL;

    endian = *(blob_odd + 2);
    num_bands = *(blob_odd + 6);
    ptr = blob_odd + 11;
    ptr += 2;
    ptr += 2;
    ptr += 4;
    compressed_odd = importU32 (ptr, endian, endian_arch);
    ptr += 4;
    uncompressed_mask = importU32 (ptr, endian, endian_arch);
    ptr += 4;
    compressed_mask = importU32 (ptr, endian, endian_arch);
    ptr += 4;
    if (*ptr++ != RL2_DATA_START)
	return NULL;
    if (uncompressed_mask > 0)
      {
	  /* retrieving the mask */
	  ptr += compressed_odd;
	  if (*ptr++ != RL2_DATA_END)
	      return NULL;
	  if (*ptr++ != RL2_MASK_START)
	      return NULL;
	  pixels_mask = ptr;
	  mask_width = width;
	  mask_height = height;
	  ptr += compressed_mask;
	  if (*ptr++ != RL2_MASK_END)
	      return NULL;
      }

    if (pixels_mask == NULL)
      {
	  /* not existing Mask - not an error */
	  *status = RL2_OK;
	  return NULL;
      }

    /* unpacking the mask */
    unsigned char *mask_pix;
    int mask_pix_sz;
    if (uncompressed_mask != (mask_width * mask_height))
	goto error;
    if (!unpack_rle
	(mask_width, mask_height, pixels_mask, compressed_mask,
	 &mask_pix, &mask_pix_sz))
	goto error;
    if (!rescale_mask
	(scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz))
      {
	  free (mask_pix);
	  goto error;
      }
    free (mask_pix);

    /* will always return a full BLACK grayscale UINT8 raster */
    pixels_sz = width * height;
    pixels = malloc (pixels_sz);
    memset (pixels, 0, pixels_sz);
    raster =
	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
			   1, pixels, pixels_sz, NULL, mask, mask_sz, NULL);
    if (raster == NULL)
	goto error;
    *status = RL2_OK;
    return raster;
  error:
    if (pixels != NULL)
	free (pixels);
    if (mask != NULL)
	free (mask);
    *status = RL2_ERROR;
    return NULL;
}

static void
add_pooled_variance (rl2PrivBandStatisticsPtr band_in,
		     rl2PrivBandStatisticsPtr band_out, double count)
{
/* adding a Pooled Variance item */
    rl2PoolVariancePtr pool = malloc (sizeof (rl2PoolVariance));
................................................................................
      {
	  ignore_no_data = 0;
	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
	      != RL2_OK)
	      ignore_no_data = 1;
	  if (nbands != num_bands)
	      ignore_no_data = 1;
	  if (sample_type == RL2_SAMPLE_1_BIT
	      || sample_type == RL2_SAMPLE_2_BIT
	      || sample_type == RL2_SAMPLE_4_BIT
	      || sample_type == RL2_SAMPLE_UINT8)
	      ;
	  else
	      ignore_no_data = 1;
      }

................................................................................
	    }
      }
    compute_int32_histogram (width, height, pixels, mask, st, no_data);
}

static void
compute_uint32_histogram (unsigned short width, unsigned short height,
			  const unsigned int *pixels,
			  const unsigned char *mask,
			  rl2PrivRasterStatisticsPtr st, rl2PixelPtr no_data)
{
/* computing INT16 tile histogram */
    int x;
    int y;
    const unsigned int *p_in = pixels;
    const unsigned char *p_msk = mask;

Changes to src/rl2dbms.c.

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
....
1244
1245
1246
1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258
....
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
....
2386
2387
2388
2389
2390
2391
2392
2393
2394

2395
2396
2397
2398
2399
2400
2401
2402
....
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
....
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
....
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
....
2888
2889
2890
2891
2892
2893
2894
2895

2896
2897
2898
2899
2900
2901
2902
....
2923
2924
2925
2926
2927
2928
2929
































2930
2931
2932
2933
2934
2935
2936
....
2937
2938
2939
2940
2941
2942
2943


















2944
2945
2946
2947
2948
2949
2950
....
2986
2987
2988
2989
2990
2991
2992


















































2993
2994
2995
2996
2997
2998
2999
....
3070
3071
3072
3073
3074
3075
3076
3077
3078












































































































































































































































































3079
3080
3081

3082
3083
3084
3085
3086
3087
3088
3089
....
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
....
3866
3867
3868
3869
3870
3871
3872
3873
3874

3875
3876
3877
3878
3879
3880
3881
3882
....
3999
4000
4001
4002
4003
4004
4005
4006
4007

4008
4009
4010
4011
4012
4013
4014
4015
....
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
....
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107

4108
4109
4110
4111
4112
4113
4114
4115
....
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137

4138
4139
4140
4141
4142
4143





4144
4145
4146
4147
4148
4149
4150
....
4431
4432
4433
4434
4435
4436
4437























































































































































4438
4439
4440
4441
4442
4443
4444
....
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
....
4677
4678
4679
4680
4681
4682
4683
4684

4685
4686
4687
4688
4689
4690
4691
4692
4693
....
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
....
4809
4810
4811
4812
4813
4814
4815













4816
4817
4818
4819

4820

4821
4822
4823
4824
4825
4826
4827
....
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
....
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912

4913
4914
4915
4916
4917
4918
4919
4920
4921
....
5072
5073
5074
5075
5076
5077
5078
5079
5080

5081
5082
5083
5084
5085
5086
5087
5088
....
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
....
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276

5277
5278
5279
5280
5281
5282
5283
....
5291
5292
5293
5294
5295
5296
5297
5298
5299

5300
5301
5302

5303
5304
5305
5306
5307
5308
5309
5310
....
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
....
5703
5704
5705
5706
5707
5708
5709

5710
5711
5712
5713
5714
5715
5716
5717
5718
....
6231
6232
6233
6234
6235
6236
6237
6238

6239
6240
6241
6242
6243
6244
6245
....
6375
6376
6377
6378
6379
6380
6381

6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
....
7001
7002
7003
7004
7005
7006
7007

7008
7009
7010
7011
7012
7013
7014
....
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
....
7481
7482
7483
7484
7485
7486
7487
7488
7489

7490
7491


7492
7493
7494
7495
7496
7497
7498
7499
....
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
....
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561










7562
7563
7564
7565
7566
7567
7568
....
7587
7588
7589
7590
7591
7592
7593
7594

7595
7596
7597
7598
7599
7600
7601
....
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623

7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689














































































































			      unsigned char sample, unsigned char pixel,
			      unsigned char num_bands,
			      unsigned char compression, int quality,
			      unsigned int tile_width,
			      unsigned int tile_height, int srid,
			      double x_res, double y_res,
			      unsigned char *blob, int blob_sz,
			      unsigned char *blob_no_data, int blob_no_data_sz,
			      int strict_resolution, int mixed_resolutions,
			      int section_paths, int section_md5,
			      int section_summary)
{
/* inserting into "raster_coverages" */
    int ret;
    char *sql;
    sqlite3_stmt *stmt;
    const char *xsample = "UNKNOWN";
    const char *xpixel = "UNKNOWN";
................................................................................
			   "\ty_resolution_1_4 DOUBLE,\n"
			   "\tx_resolution_1_8 DOUBLE,\n"
			   "\ty_resolution_1_8 DOUBLE)\n", xxcoverage);
    ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage,
		   sql_err);
	  sqlite3_free (sql_err);
	  free (xxcoverage);
	  return 0;
      }
    free (xxcoverage);
    return 1;
}
................................................................................
    ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
    sqlite3_free (sql);
    free (xpk_name);
    free (xfk_name);
    free (xmother);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage,
		   sql_err);
	  sqlite3_free (sql_err);
	  free (xxcoverage);
	  return 0;
      }
    free (xxcoverage);
    return 1;
}
................................................................................
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_resolve_base_resolution_from_dbms (sqlite3 * handle, const char *coverage,

				       int by_section, sqlite3_int64 section_id,
				       double *x_res, double *y_res)
{
/* resolving the Base Resolution */
    int ret;
    char *sql;
    double xres;
    double yres;
................................................................................
    sqlite3_stmt *stmt = NULL;

    *duplicate = 0;
    table = sqlite3_mprintf ("%s_sections", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf ("SELECT section_id FROM \"%s\" WHERE section_name = ?",
			 xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT section_id SQL error: %s\n", sqlite3_errmsg (handle));
	  goto error;
................................................................................
		  }
		if (sqlite3_column_type (stmt, 15) == SQLITE_INTEGER)
		  {
		      section_summary = sqlite3_column_int (stmt, 15);
		      ok_summary = 1;
		  }
		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
		    && ok_quality && ok_tile_width && ok_tile_height && ok_x_res
		    && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed

		    && ok_paths && ok_md5 && ok_summary)
		    ok = 1;
	    }
      }
    sqlite3_finalize (stmt);

    if (!ok)
      {
................................................................................
	  fprintf (stderr,
		   "ERROR: unable to Georeference a Coverage Object supporting \"%s\"\n",
		   coverage);
	  rl2_destroy_coverage (cvg);
	  return NULL;
      }
    if (rl2_set_coverage_policies
	(cvg, strict_resolution, mixed_resolutions, section_paths, section_md5,
	 section_summary) != RL2_OK)
      {
	  fprintf (stderr,
		   "ERROR: unable to set the Policies on the Coverage Object supporting \"%s\"\n",
		   coverage);
	  rl2_destroy_coverage (cvg);
	  return NULL;
      }
................................................................................
	      free (f_table_name);
	  if (f_geometry_column != NULL)
	      free (f_geometry_column);
	  return NULL;
      }

    vector =
	rl2_create_vector_layer (f_table_name, f_geometry_column, geometry_type,
				 srid, spatial_index);
    free (f_table_name);
    free (f_geometry_column);
    if (vector == NULL)
      {
	  fprintf (stderr,
		   "ERROR: unable to create a Vector Layer Object supporting \"%s\"\n",
		   coverage);
................................................................................
    if (!has_nodata)
      {
	  for (y = 0; y < height; y++)
	    {
		for (x = 0; x < width; x++)
		  {
		      for (b = 0; b < num_bands; b++)
			  *p++ = 0;
		  }
	    }
      }
    else
      {
	  for (y = 0; y < height; y++)
	    {
................................................................................
}

static void
do_decode_tile (rl2AuxDecoderPtr decoder)
{
/* servicing an AuxDecoder Tile request */
    decoder->raster =
	(rl2PrivRasterPtr) rl2_raster_decode (decoder->scale, decoder->blob_odd,

					      decoder->blob_odd_sz,
					      decoder->blob_even,
					      decoder->blob_even_sz,
					      (rl2PalettePtr)
					      (decoder->palette));
    if (decoder->blob_odd != NULL)
	free (decoder->blob_odd);
................................................................................
	  decoder->retcode = RL2_ERROR;
	  return;
      }
    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
    decoder->raster = NULL;
    decoder->retcode = RL2_OK;
}

































#ifdef _WIN32
DWORD WINAPI
doRunDecoderThread (void *arg)
#else
void *
doRunDecoderThread (void *arg)
................................................................................
#endif
{
/* threaded function: decoding a Tile */
    rl2AuxDecoderPtr decoder = (rl2AuxDecoderPtr) arg;
    do_decode_tile (decoder);
#ifdef _WIN32
    return 0;


















#else
    pthread_exit (NULL);
#endif
}

static void
start_decoder_thread (rl2AuxDecoderPtr decoder)
................................................................................
	    }
      }
    if (!ok_prior)
      {
	  /* failure: using standard priority */
	  pthread_create (&thread_id, NULL, doRunDecoderThread, decoder);
      }


















































    p_thread = malloc (sizeof (pthread_t));
    *p_thread = thread_id;
    decoder->opaque_thread_id = p_thread;
#endif
}

static int
................................................................................
	    }
      }
    return 1;

  error:
    return 0;
}

static int












































































































































































































































































rl2_load_dbms_tiles_common (sqlite3 * handle, int max_threads,
			    sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data,
			    unsigned char *outbuf, unsigned int width,

			    unsigned int height, unsigned char sample_type,
			    unsigned char num_bands, unsigned char auto_ndvi,
			    unsigned char red_band_index,
			    unsigned char nir_band_index, double x_res,
			    double y_res, double minx, double maxy, int scale,
			    rl2PalettePtr palette, rl2PixelPtr no_data,
			    rl2RasterSymbolizerPtr style,
			    rl2RasterStatisticsPtr stats)
................................................................................
		  {
		      fprintf (stderr,
			       "SELECT tiles data; sqlite3_step() error: %s\n",
			       sqlite3_errmsg (handle));
		      goto error;
		  }
		raster =
		    rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even,
				       blob_even_sz, NULL);
		if (raster == NULL)
		  {
		      fprintf (stderr, ERR_FRMT64, tile_id);
		      goto error;
		  }
		if (!copy_triple_band_raw_pixels
		    (raster, outbuf, width, height, red_band, green_band,
		     blue_band, x_res, y_res, minx, maxy, tile_minx, tile_maxy,
		     no_data))
		    goto error;
		rl2_destroy_raster (raster);
		raster = NULL;
	    }
	  else
	    {
		fprintf (stderr,
................................................................................

    return 1;
}

static int
copy_mono_band_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
			   unsigned int width, unsigned int height,
			   unsigned char mono_band, double x_res, double y_res,
			   double minx, double maxy, double tile_minx,

			   double tile_maxy, rl2PixelPtr no_data)
{
/* copying raw pixels into the output buffer */
    unsigned int tile_width;
    unsigned int tile_height;
    unsigned int x;
    unsigned int y;
    int out_x;
................................................................................
    return 1;
}

static int
load_mono_band_dbms_tiles (sqlite3 * handle, sqlite3_stmt * stmt_tiles,
			   sqlite3_stmt * stmt_data, unsigned char *outbuf,
			   unsigned int width, unsigned int height,
			   unsigned char mono_band, double x_res, double y_res,
			   double minx, double miny, double maxx, double maxy,

			   int level, int scale, rl2PixelPtr no_data)
{
/* retrieving a full image from DBMS tiles */
    rl2RasterPtr raster = NULL;
    int ret;

/* binding the query args */
    sqlite3_reset (stmt_tiles);
................................................................................
		  {
		      fprintf (stderr,
			       "SELECT tiles data; sqlite3_step() error: %s\n",
			       sqlite3_errmsg (handle));
		      goto error;
		  }
		raster =
		    rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even,
				       blob_even_sz, NULL);
		if (raster == NULL)
		  {
		      fprintf (stderr, ERR_FRMT64, tile_id);
		      goto error;
		  }
		if (!copy_mono_band_raw_pixels
		    (raster, outbuf, width, height, mono_band, x_res, y_res,
................................................................................

RL2_PRIVATE int
rl2_load_dbms_tiles (sqlite3 * handle, int max_threads,
		     sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data,
		     unsigned char *outbuf, unsigned int width,
		     unsigned int height, unsigned char sample_type,
		     unsigned char num_bands, unsigned char auto_ndvi,
		     unsigned char red_band_index, unsigned char nir_band_index,
		     double x_res, double y_res, double minx, double miny,
		     double maxx, double maxy, int level, int scale,
		     rl2PalettePtr palette, rl2PixelPtr no_data,

		     rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats)
{
/* binding the query args */
    sqlite3_reset (stmt_tiles);
    sqlite3_clear_bindings (stmt_tiles);
    sqlite3_bind_int (stmt_tiles, 1, level);
    sqlite3_bind_double (stmt_tiles, 2, minx);
    sqlite3_bind_double (stmt_tiles, 3, miny);
................................................................................

RL2_PRIVATE int
rl2_load_dbms_tiles_section (sqlite3 * handle, int max_threads,
			     sqlite3_int64 section_id,
			     sqlite3_stmt * stmt_tiles,
			     sqlite3_stmt * stmt_data, unsigned char *outbuf,
			     unsigned int width, unsigned int height,
			     unsigned char sample_type, unsigned char num_bands,
			     unsigned char auto_ndvi,
			     unsigned char red_band_index,
			     unsigned char nir_band_index, double x_res,
			     double y_res, double minx, double maxy, int scale,

			     rl2PalettePtr palette, rl2PixelPtr no_data)
{
/* binding the query args */
    sqlite3_reset (stmt_tiles);
    sqlite3_clear_bindings (stmt_tiles);
    sqlite3_bind_int (stmt_tiles, 1, section_id);






    if (!rl2_load_dbms_tiles_common
	(handle, max_threads, stmt_tiles, stmt_data, outbuf, width, height,
	 sample_type, num_bands, auto_ndvi, red_band_index, nir_band_index,
	 x_res, y_res, minx, maxy, scale, palette, no_data, NULL, NULL))
	return 0;
    return 1;
................................................................................
    if (ret != SQLITE_OK)
	return scale_factor;
    for (i = 1; i <= rows; i++)
	scale_factor = 11.1120;
    sqlite3_free_table (results);
    return scale_factor;
}
























































































































































RL2_PRIVATE int
rl2_get_raw_raster_data_common (sqlite3 * handle, int max_threads,
				rl2CoveragePtr cvg, int by_section,
				sqlite3_int64 section_id, unsigned int width,
				unsigned int height, double minx, double miny,
				double maxx, double maxy, double x_res,
................................................................................
			    free (blue);
			}
		      if (!ok)
			{
			    /* default: white */
			    rl2_set_pixel_sample_uint8 (no_data, RL2_RED_BAND,
							255);
			    rl2_set_pixel_sample_uint8 (no_data, RL2_GREEN_BAND,
							255);
			    rl2_set_pixel_sample_uint8 (no_data, RL2_BLUE_BAND,
							255);
			}
		  }
	    }
	  if (plt != NULL)
	      rl2_destroy_palette (plt);
	  plt = NULL;
	  sample_type = RL2_SAMPLE_UINT8;
................................................................................
		/* preparing a Shaded Relief mask */
		double scale_factor =
		    rl2_get_shaded_relief_scale_factor (handle, coverage);
		if (rl2_get_raster_symbolizer_shaded_relief
		    (style, &brightness_only, &relief_factor) != RL2_OK)
		    goto error;
		if (rl2_build_shaded_relief_mask
		    (handle, max_threads, cvg, relief_factor, scale_factor,

		     width, height, minx, miny, maxx, maxy, x_res, y_res,
		     &shaded_relief, &shaded_relief_sz) != RL2_OK)
		    goto error;

		if (brightness_only || !rl2_has_styled_rgb_colors (style))
		  {
		      /* returning a Grayscale ShadedRelief (BrightnessOnly) */
		      unsigned int row;
		      unsigned int col;
................................................................................

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    if (by_section)
      {
	  /* only from a single Section */
	  char sctn[1024];
#if defined(_WIN32) && !defined(__MINGW32__)
	  sprintf (sctn, "%I64d", section_id);
#else
	  sprintf (sctn, "%lld", section_id);
#endif
	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
	       "FROM \"%s\" "
	       "WHERE section_id = %s AND pyramid_level = ? AND ROWID IN ( "
	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, sctn,
	       xtiles);
      }
    else
      {
	  /* whole Coverage */
	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
................................................................................
	  if (bgcolor != NULL)
	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			       bgcolor);
	  else
	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			       no_data);
      }













    if (!rl2_load_dbms_tiles
	(handle, max_threads, stmt_tiles, stmt_data, bufpix, width, height,
	 sample_type, num_bands, auto_ndvi, red_band, nir_band, xx_res, yy_res,
	 minx, miny, maxx, maxy, level, scale, plt, no_data, style, stats))

	goto error;

    if (kill_no_data != NULL)
	rl2_destroy_pixel (kill_no_data);
    sqlite3_finalize (stmt_tiles);
    sqlite3_finalize (stmt_data);
    if (shaded_relief != NULL)
      {
	  /* applying the Shaded Relief */
................................................................................
	rl2_destroy_pixel (kill_no_data);
    if (shaded_relief != NULL)
	free (shaded_relief);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg,
			 unsigned int width, unsigned int height,
			 double minx, double miny, double maxx, double maxy,
			 double x_res, double y_res, unsigned char **buffer,
			 int *buf_size, rl2PalettePtr * palette,
			 unsigned char out_pixel)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 0, 0,
					   width, height, minx, miny, maxx,
					   maxy, x_res, y_res, buffer, buf_size,
					   palette, out_pixel, NULL, NULL,
					   NULL);
}

RL2_DECLARE int
rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, sqlite3_int64 section_id,
				 unsigned int width, unsigned int height,
				 double minx, double miny, double maxx,
................................................................................
				 rl2PalettePtr * palette,
				 unsigned char out_pixel)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage/Section */
    return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 1,
					   section_id, width, height, minx,
					   miny, maxx, maxy, x_res, y_res,
					   buffer, buf_size, palette, out_pixel,
					   NULL, NULL, NULL);
}

static int
get_triple_band_raw_raster_data_common (int by_section, sqlite3 * handle,
					rl2CoveragePtr cvg,
					sqlite3_int64 section_id,
					unsigned int width, unsigned int height,

					double minx, double miny, double maxx,
					double maxy, double x_res, double y_res,
					unsigned char red_band,
					unsigned char green_band,
					unsigned char blue_band,
					unsigned char **buffer, int *buf_size,
					rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
................................................................................
				     unsigned char blue_band,
				     unsigned char **buffer, int *buf_size,
				     rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return get_triple_band_raw_raster_data_common (0, handle, cvg, 0, width,
						   height, minx, miny, maxx,
						   maxy, x_res, y_res, red_band,
						   green_band, blue_band,

						   buffer, buf_size, bgcolor);
}

RL2_DECLARE int
rl2_get_section_triple_band_raw_raster_data (sqlite3 * handle,
					     rl2CoveragePtr cvg,
					     sqlite3_int64 section_id,
					     unsigned int width,
................................................................................
					     int *buf_size, rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels - Section */
    return get_triple_band_raw_raster_data_common (1, handle, cvg, section_id,
						   width, height, minx, miny,
						   maxx, maxy, x_res, y_res,
						   red_band, green_band,
						   blue_band, buffer, buf_size,
						   bgcolor);
}

static int
get_mono_band_raw_raster_data_common (int by_section, sqlite3 * handle,
				      rl2CoveragePtr cvg,
				      sqlite3_int64 section_id,
				      unsigned int width, unsigned int height,
................................................................................
				   double x_res, double y_res,
				   unsigned char mono_band,
				   unsigned char **buffer, int *buf_size,
				   rl2PixelPtr no_data)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return get_mono_band_raw_raster_data_common (0, handle, cvg, 0, width,
						 height, minx, miny, maxx, maxy,
						 x_res, y_res, buffer, buf_size,
						 mono_band, no_data);
}

RL2_DECLARE int
rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle, rl2CoveragePtr cvg,

					   sqlite3_int64 section_id,
					   unsigned int width,
					   unsigned int height, double minx,
					   double miny, double maxx,
					   double maxy, double x_res,
					   double y_res,
					   unsigned char mono_band,
................................................................................
						 buffer, buf_size, mono_band,
						 no_data);
}

RL2_DECLARE int
rl2_get_raw_raster_data_bgcolor (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, unsigned int width,
				 unsigned int height, double minx, double miny,
				 double maxx, double maxy, double x_res,

				 double y_res, unsigned char **buffer,
				 int *buf_size, rl2PalettePtr * palette,
				 unsigned char *out_pixel, unsigned char bg_red,

				 unsigned char bg_green, unsigned char bg_blue,
				 rl2RasterSymbolizerPtr style,
				 rl2RasterStatisticsPtr stats)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage + bgcolor */
    int ret;
    rl2PixelPtr no_data = NULL;
    const char *coverage;
................................................................................
	  if (index < 0)
	    {
		/* palette color found */
		switch (sample_type)
		  {
		  case RL2_SAMPLE_1_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_1_BIT, RL2_PIXEL_PALETTE,
					    1);
		      rl2_set_pixel_sample_1bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_2_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_2_BIT, RL2_PIXEL_PALETTE,
					    1);
		      rl2_set_pixel_sample_2bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_4_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_4_BIT, RL2_PIXEL_PALETTE,
					    1);
		      rl2_set_pixel_sample_4bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_UINT8:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE,
					    1);
		      rl2_set_pixel_sample_uint8 (no_data, RL2_PALETTE_BAND,
						  (unsigned char) index);
		      break;

		  };
	    }
      }
................................................................................
    sqlite3_stmt *stmt = NULL;
    char *sql;
    int ret;
    if (handle == NULL || coverage == NULL || palette == NULL)
	return RL2_ERROR;

    sql =

	sqlite3_mprintf ("SELECT sample_type, pixel_type FROM raster_coverages "
			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
	  goto error;
      }
................................................................................
	sqlite3_finalize (stmt);
    if (stl != NULL)
	rl2_destroy_coverage_style (stl);
    return NULL;
}

RL2_DECLARE rl2FeatureTypeStylePtr
rl2_create_feature_type_style_from_dbms (sqlite3 * handle, const char *coverage,

					 const char *style)
{
/* attempting to load and parse a Feature Type Style */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    rl2FeatureTypeStylePtr stl = NULL;
................................................................................
    char **results;
    int rows;
    int columns;
    int i;
    int ok = 0;
/* testing if the Layer Style exists */
    char *sql =

	sqlite3_mprintf ("SELECT style_name FROM SE_raster_styled_layers AS r "
			 "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) "
			 "WHERE Lower(r.coverage_name) = Lower(%Q) AND "
			 "Lower(s.style_name) = Lower(%Q)", namedLayer,
			 namedStyle);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 0;
    for (i = 1; i <= rows; i++)
	ok = 1;
    sqlite3_free_table (results);
................................................................................
    int section_summary = 0;
    rl2PixelPtr no_data = NULL;
    rl2PalettePtr palette = NULL;
    char *title = NULL;
    char *abstract = NULL;
    unsigned char *statistics = NULL;
    int statistics_sz;

    int ok_bbox = 0;
    double geo_minx;
    double geo_miny;
    double geo_maxx;
    double geo_maxy;
    double ext_minx;
    double ext_miny;
................................................................................
		      strcpy (abstract, value);
		  }
		if (sqlite3_column_type (stmt, 18) == SQLITE_BLOB)
		  {
		      statistics_sz = sqlite3_column_bytes (stmt, 18);
		      statistics = malloc (statistics_sz);
		      memcpy (statistics,
			      (const unsigned char *) sqlite3_column_blob (stmt,
									   18),
			      statistics_sz);
		  }
		if (sqlite3_column_type (stmt, 19) == SQLITE_FLOAT)
		  {
		      geo_minx = sqlite3_column_double (stmt, 19);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 20) == SQLITE_FLOAT)
		  {
		      geo_miny = sqlite3_column_double (stmt, 20);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 21) == SQLITE_FLOAT)
		  {
		      geo_maxx = sqlite3_column_double (stmt, 21);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 22) == SQLITE_FLOAT)
		  {
		      geo_maxy = sqlite3_column_double (stmt, 22);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 23) == SQLITE_FLOAT)
		  {
		      ext_minx = sqlite3_column_double (stmt, 23);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 24) == SQLITE_FLOAT)
................................................................................
		  {
		      const unsigned char *blob =
			  sqlite3_column_blob (stmt, 33);
		      int blob_sz = sqlite3_column_bytes (stmt, 33);
		      palette = rl2_deserialize_dbms_palette (blob, blob_sz);
		  }
		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
		    && ok_quality && ok_tile_width && ok_tile_height && ok_x_res
		    && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed

		    && ok_paths && ok_md5 && ok_summary)
		    ok = 1;


		if (ok_bbox != 8)
		    ok_bbox = 0;
	    }
      }
    sqlite3_finalize (stmt);
    stmt = NULL;
    if (!ok)
	goto error;
................................................................................
				    compr, quality,
				    (unsigned short) tile_width,
				    (unsigned short) tile_height, srid,
				    horz_res, vert_res, no_data, palette,
				    strict_resolution, mixed_resolutions,
				    section_paths, section_md5,
				    section_summary);
	if (no_data != NULL)
	rl2_destroy_pixel(no_data);
	if (palette != NULL)
	rl2_destroy_palette(palette);
    if (ret != RL2_OK)
	goto error;

/* completing the destination coverage */
    sql = "UPDATE main.raster_coverages SET title = ?, "
	"abstract = ?, statistics = ?, geo_minx = ?, geo_miny = ?, geo_maxx = ?, "
	"geo_maxy = ?, extent_minx = ?, extent_miny = ?, extent_maxx = ?, "
................................................................................
	sqlite3_bind_null (stmt, 2);
    else
	sqlite3_bind_text (stmt, 2, abstract, strlen (abstract), free);
    if (statistics == NULL)
	sqlite3_bind_null (stmt, 3);
    else
	sqlite3_bind_blob (stmt, 3, statistics, statistics_sz, free);
    if (ok_bbox)
      {
	  sqlite3_bind_double (stmt, 4, geo_minx);
	  sqlite3_bind_double (stmt, 5, geo_miny);
	  sqlite3_bind_double (stmt, 6, geo_maxx);
	  sqlite3_bind_double (stmt, 7, geo_maxy);
	  sqlite3_bind_double (stmt, 8, ext_minx);
	  sqlite3_bind_double (stmt, 9, ext_miny);
	  sqlite3_bind_double (stmt, 10, ext_maxx);
	  sqlite3_bind_double (stmt, 11, ext_maxy);
      }
    else
      {
	  sqlite3_bind_null (stmt, 4);
	  sqlite3_bind_null (stmt, 5);
	  sqlite3_bind_null (stmt, 6);
	  sqlite3_bind_null (stmt, 7);










	  sqlite3_bind_null (stmt, 8);
	  sqlite3_bind_null (stmt, 9);
	  sqlite3_bind_null (stmt, 10);
	  sqlite3_bind_null (stmt, 11);
      }
    if (!ok_is_queryable)
	sqlite3_bind_null (stmt, 12);
................................................................................
    if (!ok_enable_auto_ndvi)
	sqlite3_bind_null (stmt, 17);
    else
	sqlite3_bind_int (stmt, 17, enable_auto_ndvi);
    sqlite3_bind_text (stmt, 18, coverage_name, strlen (coverage_name),
		       SQLITE_STATIC);
    ret = sqlite3_step (stmt);
    sqlite3_finalize(stmt);

    if (ret == SQLITE_DONE || ret == SQLITE_ROW)
	goto ok_continue;
    fprintf (stderr,
	     "sqlite3_step() error: UPDATE raster_coverages \"%s\"\n",
	     sqlite3_errmsg (sqlite));
    goto error;

................................................................................
			   "x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
			   "SELECT pyramid_level, x_resolution_1_1, y_resolution_1_1, x_resolution_1_2, "
			   "y_resolution_1_2, x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, "
			   "y_resolution_1_8 FROM \"%s\".\"%s\"", xxcoverage,
			   xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-SECTIONS */
    xcoverage = sqlite3_mprintf ("%s_sections", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);

    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, "
			   "width, height, file_path, md5_checksum, summary, statistics, geometry) "
			   "SELECT section_id, section_name, width, height, file_path, md5_checksum, "
			   "summary, statistics, geometry FROM \"%s\".\"%s\"",
			   xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-TILES */
    xcoverage = sqlite3_mprintf ("%s_tiles", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, pyramid_level, "
			   "section_id, geometry) SELECT tile_id, pyramid_level, section_id, geometry "
			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-TILE_DATA */
    xcoverage = sqlite3_mprintf ("%s_tile_data", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, tile_data_odd, "
			   "tile_data_even) SELECT tile_id, tile_data_odd, tile_data_even "
			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying KEYWORDS */
    sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_keyword "
			   "(coverage_name, keyword) SELECT coverage_name, keyword "
			   "FROM \"%s\".raster_coverages_keyword", xdb);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying SRID */
    sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_srid "
			   "(coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx) "
			   "SELECT coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx "
			   "FROM \"%s\".raster_coverages_srid", xdb);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free(sql);
    if (ret != SQLITE_OK)
	goto error;

    free (xdb);
    return RL2_OK;

  error:
    if (xdb != NULL)
	free (xdb);
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}





















































































































|
|
|
|







 







|
|







 







|
|







 







>
|







 







|
|







 







|
|
>
|







 







|
|







 







|
|







 







|







 







|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|
>
|







 







|
|







|
|







 







|
|
>
|







 







|
|
>
|







 







|
|







 







|
|
|
|
>
|







 







|
|


|
>






>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|







 







|
>
|
|







 







<
<
<
<
<
<




|

|
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>
|
>







 







|
|
|
|
|
|




|
|
|







 







|
|






|
>
|
|







 







|
|
>
|







 







|
|







 







|
|
|



|
>







 







|
|
>
|
|
|
>
|







 







|
|





|
|





|
|





|
|







 







>
|
|







 







|
>







 







>
|
|
|
|
|







 







>







 







|
<
|




|




|




|




|







 







|
|
>
|

>
>
|







 







|
|
|
|







 







|





<
<
<
<







>
>
>
>
>
>
>
>
>
>







 







|
>







 







|







>
|
|
|
|
|


|












|












|








|









|













>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
....
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
....
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
....
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
....
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
....
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
....
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
....
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
....
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
....
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
....
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
....
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
....
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
....
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
....
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
....
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
....
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
....
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
....
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
....
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
....
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
....
5256
5257
5258
5259
5260
5261
5262






5263
5264
5265
5266
5267
5268
5269

5270
5271
5272
5273
5274
5275
5276
....
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
....
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
....
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
....
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
....
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
....
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
....
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
....
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
....
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
....
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
....
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
....
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
....
7949
7950
7951
7952
7953
7954
7955
7956

7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
....
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
....
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
....
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102




8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
....
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
....
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
			      unsigned char sample, unsigned char pixel,
			      unsigned char num_bands,
			      unsigned char compression, int quality,
			      unsigned int tile_width,
			      unsigned int tile_height, int srid,
			      double x_res, double y_res,
			      unsigned char *blob, int blob_sz,
			      unsigned char *blob_no_data,
			      int blob_no_data_sz, int strict_resolution,
			      int mixed_resolutions, int section_paths,
			      int section_md5, int section_summary)
{
/* inserting into "raster_coverages" */
    int ret;
    char *sql;
    sqlite3_stmt *stmt;
    const char *xsample = "UNKNOWN";
    const char *xpixel = "UNKNOWN";
................................................................................
			   "\ty_resolution_1_4 DOUBLE,\n"
			   "\tx_resolution_1_8 DOUBLE,\n"
			   "\ty_resolution_1_8 DOUBLE)\n", xxcoverage);
    ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n",
		   xxcoverage, sql_err);
	  sqlite3_free (sql_err);
	  free (xxcoverage);
	  return 0;
      }
    free (xxcoverage);
    return 1;
}
................................................................................
    ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err);
    sqlite3_free (sql);
    free (xpk_name);
    free (xfk_name);
    free (xmother);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n",
		   xxcoverage, sql_err);
	  sqlite3_free (sql_err);
	  free (xxcoverage);
	  return 0;
      }
    free (xxcoverage);
    return 1;
}
................................................................................
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_resolve_base_resolution_from_dbms (sqlite3 * handle, const char *coverage,
				       int by_section,
				       sqlite3_int64 section_id,
				       double *x_res, double *y_res)
{
/* resolving the Base Resolution */
    int ret;
    char *sql;
    double xres;
    double yres;
................................................................................
    sqlite3_stmt *stmt = NULL;

    *duplicate = 0;
    table = sqlite3_mprintf ("%s_sections", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf
	("SELECT section_id FROM \"%s\" WHERE section_name = ?", xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT section_id SQL error: %s\n", sqlite3_errmsg (handle));
	  goto error;
................................................................................
		  }
		if (sqlite3_column_type (stmt, 15) == SQLITE_INTEGER)
		  {
		      section_summary = sqlite3_column_int (stmt, 15);
		      ok_summary = 1;
		  }
		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
		    && ok_quality && ok_tile_width && ok_tile_height
		    && ok_x_res && ok_y_res && ok_srid && ok_nodata
		    && ok_strict && ok_mixed && ok_paths && ok_md5
		    && ok_summary)
		    ok = 1;
	    }
      }
    sqlite3_finalize (stmt);

    if (!ok)
      {
................................................................................
	  fprintf (stderr,
		   "ERROR: unable to Georeference a Coverage Object supporting \"%s\"\n",
		   coverage);
	  rl2_destroy_coverage (cvg);
	  return NULL;
      }
    if (rl2_set_coverage_policies
	(cvg, strict_resolution, mixed_resolutions, section_paths,
	 section_md5, section_summary) != RL2_OK)
      {
	  fprintf (stderr,
		   "ERROR: unable to set the Policies on the Coverage Object supporting \"%s\"\n",
		   coverage);
	  rl2_destroy_coverage (cvg);
	  return NULL;
      }
................................................................................
	      free (f_table_name);
	  if (f_geometry_column != NULL)
	      free (f_geometry_column);
	  return NULL;
      }

    vector =
	rl2_create_vector_layer (f_table_name, f_geometry_column,
				 geometry_type, srid, spatial_index);
    free (f_table_name);
    free (f_geometry_column);
    if (vector == NULL)
      {
	  fprintf (stderr,
		   "ERROR: unable to create a Vector Layer Object supporting \"%s\"\n",
		   coverage);
................................................................................
    if (!has_nodata)
      {
	  for (y = 0; y < height; y++)
	    {
		for (x = 0; x < width; x++)
		  {
		      for (b = 0; b < num_bands; b++)
			  *p++ = 255;
		  }
	    }
      }
    else
      {
	  for (y = 0; y < height; y++)
	    {
................................................................................
}

static void
do_decode_tile (rl2AuxDecoderPtr decoder)
{
/* servicing an AuxDecoder Tile request */
    decoder->raster =
	(rl2PrivRasterPtr) rl2_raster_decode (decoder->scale,
					      decoder->blob_odd,
					      decoder->blob_odd_sz,
					      decoder->blob_even,
					      decoder->blob_even_sz,
					      (rl2PalettePtr)
					      (decoder->palette));
    if (decoder->blob_odd != NULL)
	free (decoder->blob_odd);
................................................................................
	  decoder->retcode = RL2_ERROR;
	  return;
      }
    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
    decoder->raster = NULL;
    decoder->retcode = RL2_OK;
}

static void
do_decode_masktile (rl2AuxMaskDecoderPtr decoder)
{
/* servicing an AuxMaskDecoder Tile request */
    int status;
    decoder->raster =
	(rl2PrivRasterPtr) rl2_raster_decode_mask (decoder->scale,
						   decoder->blob_odd,
						   decoder->blob_odd_sz,
						   &status);
    if (decoder->blob_odd != NULL)
	free (decoder->blob_odd);
    decoder->blob_odd = NULL;
    if (decoder->raster == NULL)
      {
	  decoder->retcode = status;
	  return;
      }
    if (!rl2_copy_raw_mask
	((rl2RasterPtr) (decoder->raster), decoder->maskbuf, decoder->width,
	 decoder->height, decoder->x_res, decoder->y_res, decoder->minx,
	 decoder->maxy, decoder->tile_minx, decoder->tile_maxy))
      {
	  decoder->retcode = RL2_ERROR;
	  return;
      }

    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
    decoder->raster = NULL;
    decoder->retcode = RL2_OK;
}

#ifdef _WIN32
DWORD WINAPI
doRunDecoderThread (void *arg)
#else
void *
doRunDecoderThread (void *arg)
................................................................................
#endif
{
/* threaded function: decoding a Tile */
    rl2AuxDecoderPtr decoder = (rl2AuxDecoderPtr) arg;
    do_decode_tile (decoder);
#ifdef _WIN32
    return 0;
#else
    pthread_exit (NULL);
#endif
}

#ifdef _WIN32
DWORD WINAPI
doRunMaskDecoderThread (void *arg)
#else
void *
doRunMaskDecoderThread (void *arg)
#endif
{
/* threaded function: decoding a Tile */
    rl2AuxMaskDecoderPtr decoder = (rl2AuxMaskDecoderPtr) arg;
    do_decode_masktile (decoder);
#ifdef _WIN32
    return 0;
#else
    pthread_exit (NULL);
#endif
}

static void
start_decoder_thread (rl2AuxDecoderPtr decoder)
................................................................................
	    }
      }
    if (!ok_prior)
      {
	  /* failure: using standard priority */
	  pthread_create (&thread_id, NULL, doRunDecoderThread, decoder);
      }
    p_thread = malloc (sizeof (pthread_t));
    *p_thread = thread_id;
    decoder->opaque_thread_id = p_thread;
#endif
}

static void
start_mask_decoder_thread (rl2AuxMaskDecoderPtr decoder)
{
/* starting a concurrent thread */
#ifdef _WIN32
    HANDLE thread_handle;
    HANDLE *p_thread;
    DWORD dwThreadId;
    thread_handle =
	CreateThread (NULL, 0, doRunMaskDecoderThread, decoder, 0, &dwThreadId);
    SetThreadPriority (thread_handle, THREAD_PRIORITY_IDLE);
    p_thread = malloc (sizeof (HANDLE));
    *p_thread = thread_handle;
    decoder->opaque_thread_id = p_thread;
#else
    pthread_t thread_id;
    pthread_t *p_thread;
    int ok_prior = 0;
    int policy;
    int min_prio;
    pthread_attr_t attr;
    struct sched_param sp;
    pthread_attr_init (&attr);
    if (pthread_attr_setschedpolicy (&attr, SCHED_RR) == 0)
      {
	  /* attempting to set the lowest priority */
	  if (pthread_attr_getschedpolicy (&attr, &policy) == 0)
	    {
		min_prio = sched_get_priority_min (policy);
		sp.sched_priority = min_prio;
		if (pthread_attr_setschedparam (&attr, &sp) == 0)
		  {
		      /* ok, setting the lowest priority */
		      ok_prior = 1;
		      pthread_create (&thread_id, &attr, doRunMaskDecoderThread,
				      decoder);
		  }
	    }
      }
    if (!ok_prior)
      {
	  /* failure: using standard priority */
	  pthread_create (&thread_id, NULL, doRunMaskDecoderThread, decoder);
      }
    p_thread = malloc (sizeof (pthread_t));
    *p_thread = thread_id;
    decoder->opaque_thread_id = p_thread;
#endif
}

static int
................................................................................
	    }
      }
    return 1;

  error:
    return 0;
}

static int
do_run_mask_decoder_children (rl2AuxMaskDecoderPtr * thread_slots,
			      int thread_count)
{
/* concurrent execution of all mask decoder children threads */
    rl2AuxMaskDecoderPtr decoder;
    int i;
#ifdef _WIN32
    HANDLE *handles;
#endif

    for (i = 0; i < thread_count; i++)
      {
	  /* starting all children threads */
	  decoder = *(thread_slots + i);
	  start_mask_decoder_thread (decoder);
      }

/* waiting until all child threads exit */
#ifdef _WIN32
    handles = malloc (sizeof (HANDLE) * thread_count);
    for (i = 0; i < thread_count; i++)
      {
	  /* initializing the HANDLEs array */
	  HANDLE *pOpaque;
	  decoder = *(thread_slots + i);
	  pOpaque = (HANDLE *) (decoder->opaque_thread_id);
	  *(handles + i) = *pOpaque;
      }
    WaitForMultipleObjects (thread_count, handles, TRUE, INFINITE);
    free (handles);
#else
    for (i = 0; i < thread_count; i++)
      {
	  pthread_t *pOpaque;
	  decoder = *(thread_slots + i);
	  pOpaque = (pthread_t *) (decoder->opaque_thread_id);
	  pthread_join (*pOpaque, NULL);
      }
#endif

/* all children threads have now finished: resuming the main thread */
    for (i = 0; i < thread_count; i++)
      {
	  /* cleaning up a request slot */
	  decoder = *(thread_slots + i);
	  if (decoder->blob_odd != NULL)
	      free (decoder->blob_odd);
	  if (decoder->raster != NULL)
	      rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
	  if (decoder->opaque_thread_id != NULL)
	      free (decoder->opaque_thread_id);
	  decoder->blob_odd = NULL;
	  decoder->blob_odd_sz = 0;
	  decoder->raster = NULL;
	  decoder->opaque_thread_id = NULL;
      }
    for (i = 0; i < thread_count; i++)
      {
	  /* checking for eventual errors */
	  decoder = *(thread_slots + i);
	  if (decoder->retcode != RL2_OK)
	    {
		fprintf (stderr, ERR_FRMT64, decoder->tile_id);
		goto error;
	    }
      }
    return 1;

  error:
    return 0;
}

static int
rl2_load_dbms_masktiles (sqlite3 * handle, int max_threads, int by_section,
			 sqlite3_int64 section_id, sqlite3_stmt * stmt_tiles,
			 sqlite3_stmt * stmt_data, unsigned char *maskbuf,
			 unsigned int width, unsigned int height, double x_res,
			 double y_res, double minx, double miny, double maxx,
			 double maxy, int level, int scale)
{
/* retrieving a transparenct mask from DBMS tiles */
    rl2RasterPtr raster = NULL;
    int ret;
    rl2AuxMaskDecoderPtr aux = NULL;
    rl2AuxMaskDecoderPtr decoder;
    rl2AuxMaskDecoderPtr *thread_slots = NULL;
    int thread_count;
    int iaux;

    if (max_threads < 1)
	max_threads = 1;
    if (max_threads > 64)
	max_threads = 64;
/* allocating the AuxDecoder array */
    aux = malloc (sizeof (rl2AuxMaskDecoder) * max_threads);
    if (aux == NULL)
	return 0;
    for (iaux = 0; iaux < max_threads; iaux++)
      {
	  /* initializing an empty AuxDecoder */
	  decoder = aux + iaux;
	  decoder->opaque_thread_id = NULL;
	  decoder->blob_odd = NULL;
	  decoder->blob_odd_sz = 0;
	  decoder->maskbuf = maskbuf;
	  decoder->width = width;
	  decoder->height = height;
	  decoder->x_res = x_res;
	  decoder->y_res = y_res;
	  decoder->scale = scale;
	  decoder->minx = minx;
	  decoder->maxy = maxy;
	  decoder->raster = NULL;
      }

/* preparing the thread_slots stuct */
    thread_slots = malloc (sizeof (rl2AuxMaskDecoderPtr) * max_threads);
    for (thread_count = 0; thread_count < max_threads; thread_count++)
	*(thread_slots + thread_count) = NULL;
    thread_count = 0;

/* binding the query args */
    sqlite3_reset (stmt_tiles);
    sqlite3_clear_bindings (stmt_tiles);
    if (by_section)
      {
	  sqlite3_bind_int (stmt_tiles, 1, section_id);
	  sqlite3_bind_int (stmt_tiles, 2, level);
	  sqlite3_bind_double (stmt_tiles, 3, minx);
	  sqlite3_bind_double (stmt_tiles, 4, miny);
	  sqlite3_bind_double (stmt_tiles, 5, maxx);
	  sqlite3_bind_double (stmt_tiles, 6, maxy);
      }
    else
      {
	  sqlite3_bind_int (stmt_tiles, 1, level);
	  sqlite3_bind_double (stmt_tiles, 2, minx);
	  sqlite3_bind_double (stmt_tiles, 3, miny);
	  sqlite3_bind_double (stmt_tiles, 4, maxx);
	  sqlite3_bind_double (stmt_tiles, 5, maxy);
      }

/* querying the tiles */
    while (1)
      {
	  ret = sqlite3_step (stmt_tiles);
	  if (ret == SQLITE_DONE)
	      break;
	  if (ret == SQLITE_ROW)
	    {
		int ok = 0;
		const unsigned char *blob_odd = NULL;
		int blob_odd_sz = 0;
		sqlite3_int64 tile_id = sqlite3_column_int64 (stmt_tiles, 0);
		double tile_minx = sqlite3_column_double (stmt_tiles, 1);
		double tile_maxy = sqlite3_column_double (stmt_tiles, 2);
		decoder = aux + thread_count;
		decoder->tile_id = tile_id;
		decoder->tile_minx = tile_minx;
		decoder->tile_maxy = tile_maxy;

		/* retrieving tile raw data from BLOBs */
		sqlite3_reset (stmt_data);
		sqlite3_clear_bindings (stmt_data);
		sqlite3_bind_int64 (stmt_data, 1, tile_id);
		ret = sqlite3_step (stmt_data);
		if (ret == SQLITE_DONE)
		    break;
		if (ret == SQLITE_ROW)
		  {
		      /* decoding a Tile - may be by using concurrent multithreading */
		      if (sqlite3_column_type (stmt_data, 0) == SQLITE_BLOB)
			{
			    blob_odd = sqlite3_column_blob (stmt_data, 0);
			    blob_odd_sz = sqlite3_column_bytes (stmt_data, 0);
			    decoder->blob_odd = malloc (blob_odd_sz);
			    if (decoder->blob_odd == NULL)
				goto error;
			    memcpy (decoder->blob_odd, blob_odd, blob_odd_sz);
			    decoder->blob_odd_sz = blob_odd_sz;
			    ok = 1;
			}
		  }
		else
		  {
		      fprintf (stderr,
			       "SELECT tiles data; sqlite3_step() error: %s\n",
			       sqlite3_errmsg (handle));
		      goto error;
		  }
		if (!ok)
		  {
		      if (decoder->blob_odd != NULL)
			  free (decoder->blob_odd);
		      decoder->blob_odd = NULL;
		      decoder->blob_odd_sz = 0;
		  }
		else
		  {
		      /* processing a Tile request (may be under parallel execution) */
		      if (max_threads > 1)
			{
			    /* adopting a multithreaded strategy */
			    *(thread_slots + thread_count) = decoder;
			    thread_count++;
			    if (thread_count == max_threads)
			      {
				  if (!do_run_mask_decoder_children
				      (thread_slots, thread_count))
				      goto error;
				  thread_count = 0;
			      }
			}
		      else
			{
			    /* single thread execution */
			    do_decode_masktile (decoder);
			    if (decoder->retcode != RL2_OK)
			      {
				  fprintf (stderr, ERR_FRMT64, tile_id);
				  goto error;
			      }
			}
		  }
	    }
	  else
	    {
		fprintf (stderr,
			 "SELECT tiles; sqlite3_step() error: %s\n",
			 sqlite3_errmsg (handle));
		goto error;
	    }
      }
    if (max_threads > 1 && thread_count > 0)
      {
	  /* launching the last multithreaded burst */
	  if (!do_run_mask_decoder_children (thread_slots, thread_count))
	      goto error;
      }

    free (aux);
    free (thread_slots);
    return 1;

  error:
    if (aux != NULL)
      {
	  /* AuxMaskDecoder cleanup */
	  for (iaux = 0; iaux < max_threads; iaux++)
	    {
		decoder = aux + iaux;
		if (decoder->blob_odd != NULL)
		    free (decoder->blob_odd);
		if (decoder->raster != NULL)
		    rl2_destroy_raster ((rl2RasterPtr) (decoder->raster));
		if (decoder->opaque_thread_id != NULL)
		    free (decoder->opaque_thread_id);
	    }
	  free (aux);
      }
    if (thread_slots != NULL)
	free (thread_slots);
    if (raster != NULL)
	rl2_destroy_raster (raster);
    return 0;
}

static int
rl2_load_dbms_tiles_common (sqlite3 * handle, int max_threads,
			    sqlite3_stmt * stmt_tiles,
			    sqlite3_stmt * stmt_data, unsigned char *outbuf,
			    unsigned int width, unsigned int height,
			    unsigned char sample_type,
			    unsigned char num_bands, unsigned char auto_ndvi,
			    unsigned char red_band_index,
			    unsigned char nir_band_index, double x_res,
			    double y_res, double minx, double maxy, int scale,
			    rl2PalettePtr palette, rl2PixelPtr no_data,
			    rl2RasterSymbolizerPtr style,
			    rl2RasterStatisticsPtr stats)
................................................................................
		  {
		      fprintf (stderr,
			       "SELECT tiles data; sqlite3_step() error: %s\n",
			       sqlite3_errmsg (handle));
		      goto error;
		  }
		raster =
		    rl2_raster_decode (scale, blob_odd, blob_odd_sz,
				       blob_even, blob_even_sz, NULL);
		if (raster == NULL)
		  {
		      fprintf (stderr, ERR_FRMT64, tile_id);
		      goto error;
		  }
		if (!copy_triple_band_raw_pixels
		    (raster, outbuf, width, height, red_band, green_band,
		     blue_band, x_res, y_res, minx, maxy, tile_minx,
		     tile_maxy, no_data))
		    goto error;
		rl2_destroy_raster (raster);
		raster = NULL;
	    }
	  else
	    {
		fprintf (stderr,
................................................................................

    return 1;
}

static int
copy_mono_band_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
			   unsigned int width, unsigned int height,
			   unsigned char mono_band, double x_res,
			   double y_res, double minx, double maxy,
			   double tile_minx, double tile_maxy,
			   rl2PixelPtr no_data)
{
/* copying raw pixels into the output buffer */
    unsigned int tile_width;
    unsigned int tile_height;
    unsigned int x;
    unsigned int y;
    int out_x;
................................................................................
    return 1;
}

static int
load_mono_band_dbms_tiles (sqlite3 * handle, sqlite3_stmt * stmt_tiles,
			   sqlite3_stmt * stmt_data, unsigned char *outbuf,
			   unsigned int width, unsigned int height,
			   unsigned char mono_band, double x_res,
			   double y_res, double minx, double miny,
			   double maxx, double maxy, int level, int scale,
			   rl2PixelPtr no_data)
{
/* retrieving a full image from DBMS tiles */
    rl2RasterPtr raster = NULL;
    int ret;

/* binding the query args */
    sqlite3_reset (stmt_tiles);
................................................................................
		  {
		      fprintf (stderr,
			       "SELECT tiles data; sqlite3_step() error: %s\n",
			       sqlite3_errmsg (handle));
		      goto error;
		  }
		raster =
		    rl2_raster_decode (scale, blob_odd, blob_odd_sz,
				       blob_even, blob_even_sz, NULL);
		if (raster == NULL)
		  {
		      fprintf (stderr, ERR_FRMT64, tile_id);
		      goto error;
		  }
		if (!copy_mono_band_raw_pixels
		    (raster, outbuf, width, height, mono_band, x_res, y_res,
................................................................................

RL2_PRIVATE int
rl2_load_dbms_tiles (sqlite3 * handle, int max_threads,
		     sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data,
		     unsigned char *outbuf, unsigned int width,
		     unsigned int height, unsigned char sample_type,
		     unsigned char num_bands, unsigned char auto_ndvi,
		     unsigned char red_band_index,
		     unsigned char nir_band_index, double x_res, double y_res,
		     double minx, double miny, double maxx, double maxy,
		     int level, int scale, rl2PalettePtr palette,
		     rl2PixelPtr no_data, rl2RasterSymbolizerPtr style,
		     rl2RasterStatisticsPtr stats)
{
/* binding the query args */
    sqlite3_reset (stmt_tiles);
    sqlite3_clear_bindings (stmt_tiles);
    sqlite3_bind_int (stmt_tiles, 1, level);
    sqlite3_bind_double (stmt_tiles, 2, minx);
    sqlite3_bind_double (stmt_tiles, 3, miny);
................................................................................

RL2_PRIVATE int
rl2_load_dbms_tiles_section (sqlite3 * handle, int max_threads,
			     sqlite3_int64 section_id,
			     sqlite3_stmt * stmt_tiles,
			     sqlite3_stmt * stmt_data, unsigned char *outbuf,
			     unsigned int width, unsigned int height,
			     unsigned char sample_type,
			     unsigned char num_bands, unsigned char auto_ndvi,
			     unsigned char red_band_index,
			     unsigned char nir_band_index, double x_res,
			     double y_res, double minx, double miny,
			     double maxx, double maxy, int level, int scale,
			     rl2PalettePtr palette, rl2PixelPtr no_data)
{
/* binding the query args */
    sqlite3_reset (stmt_tiles);
    sqlite3_clear_bindings (stmt_tiles);
    sqlite3_bind_int (stmt_tiles, 1, section_id);
    sqlite3_bind_int (stmt_tiles, 2, level);
    sqlite3_bind_double (stmt_tiles, 3, minx);
    sqlite3_bind_double (stmt_tiles, 4, miny);
    sqlite3_bind_double (stmt_tiles, 5, maxx);
    sqlite3_bind_double (stmt_tiles, 6, maxy);

    if (!rl2_load_dbms_tiles_common
	(handle, max_threads, stmt_tiles, stmt_data, outbuf, width, height,
	 sample_type, num_bands, auto_ndvi, red_band_index, nir_band_index,
	 x_res, y_res, minx, maxy, scale, palette, no_data, NULL, NULL))
	return 0;
    return 1;
................................................................................
    if (ret != SQLITE_OK)
	return scale_factor;
    for (i = 1; i <= rows; i++)
	scale_factor = 11.1120;
    sqlite3_free_table (results);
    return scale_factor;
}

RL2_DECLARE int
rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads,
			 rl2CoveragePtr cvg, unsigned int width,
			 unsigned int height, double minx, double miny,
			 double maxx, double maxy, double x_res,
			 double y_res, unsigned char **mask, int *mask_size)
{
/* attempting to return a transparency mask from the DBMS Coverage */
    return rl2_get_raw_raster_mask_common (handle, max_threads,
					   cvg, 0, 0, width, height, minx, miny,
					   maxx, maxy, x_res, y_res, mask,
					   mask_size);
}

RL2_DECLARE int
rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg,
				 sqlite3_int64 section_id,
				 unsigned int width,
				 unsigned int height, double minx,
				 double miny, double maxx, double maxy,
				 double x_res, double y_res,
				 unsigned char **mask, int *mask_size)
{
/* attempting to return a transparency mask from the DBMS Coverage */
    return rl2_get_raw_raster_mask_common (handle, max_threads,
					   cvg, 1, section_id, width, height,
					   minx, miny, maxx, maxy, x_res, y_res,
					   mask, mask_size);
}

RL2_PRIVATE int
rl2_get_raw_raster_mask_common (sqlite3 * handle, int max_threads,
				rl2CoveragePtr cvg, int by_section,
				sqlite3_int64 section_id, unsigned int width,
				unsigned int height, double minx, double miny,
				double maxx, double maxy, double x_res,
				double y_res, unsigned char **mask,
				int *mask_size)
{
/* attempting to return a transparency mask from the DBMS Coverage */
    const char *coverage;
    unsigned char level;
    unsigned char scale;
    double xx_res = x_res;
    double yy_res = y_res;
    unsigned char *bufpix = NULL;
    int bufpix_size;
    char *xtiles;
    char *xxtiles;
    char *xdata;
    char *xxdata;
    char *sql;
    sqlite3_stmt *stmt_tiles = NULL;
    sqlite3_stmt *stmt_data = NULL;
    int ret;

    if (cvg == NULL || handle == NULL)
	goto error;
    coverage = rl2_get_coverage_name (cvg);
    if (coverage == NULL)
	goto error;
    if (rl2_find_matching_resolution
	(handle, cvg, by_section, section_id, &xx_res, &yy_res, &level,
	 &scale) != RL2_OK)
	goto error;

    bufpix_size = width * height;
    bufpix = malloc (bufpix_size);
    if (bufpix == NULL)
      {
	  fprintf (stderr,
		   "rl2_get_raw_raster_mask: Insufficient Memory !!!\n");
	  goto error;
      }

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    if (by_section)
      {
	  /* only from a single Section */
	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
	       "FROM \"%s\" "
	       "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
      }
    else
      {
	  /* whole Coverage */
	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
	       "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( "
	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);
      }
    sqlite3_free (xtiles);
    free (xxtiles);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT raw tiles SQL error: %s\n", sqlite3_errmsg (handle));
	  goto error;
      }

    /* preparing the data SQL query - only ODD */
    xdata = sqlite3_mprintf ("%s_tile_data", coverage);
    xxdata = rl2_double_quoted_sql (xdata);
    sqlite3_free (xdata);
    sql = sqlite3_mprintf ("SELECT tile_data_odd "
			   "FROM \"%s\" WHERE tile_id = ?", xxdata);
    free (xxdata);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT raw tiles data(1) SQL error: %s\n",
		  sqlite3_errmsg (handle));
	  goto error;
      }

/* preparing a fully opaque mask */
    memset (bufpix, 0, bufpix_size);

    if (!rl2_load_dbms_masktiles
	(handle, max_threads, by_section, section_id, stmt_tiles, stmt_data,
	 bufpix, width, height, xx_res, yy_res, minx, miny, maxx, maxy, level,
	 scale))
	goto error;
    sqlite3_finalize (stmt_tiles);
    sqlite3_finalize (stmt_data);
    *mask = bufpix;
    *mask_size = bufpix_size;

    return RL2_OK;

  error:
    if (stmt_tiles != NULL)
	sqlite3_finalize (stmt_tiles);
    if (stmt_data != NULL)
	sqlite3_finalize (stmt_data);
    if (bufpix != NULL)
	free (bufpix);
    return RL2_ERROR;
}

RL2_PRIVATE int
rl2_get_raw_raster_data_common (sqlite3 * handle, int max_threads,
				rl2CoveragePtr cvg, int by_section,
				sqlite3_int64 section_id, unsigned int width,
				unsigned int height, double minx, double miny,
				double maxx, double maxy, double x_res,
................................................................................
			    free (blue);
			}
		      if (!ok)
			{
			    /* default: white */
			    rl2_set_pixel_sample_uint8 (no_data, RL2_RED_BAND,
							255);
			    rl2_set_pixel_sample_uint8 (no_data,
							RL2_GREEN_BAND, 255);
			    rl2_set_pixel_sample_uint8 (no_data,
							RL2_BLUE_BAND, 255);
			}
		  }
	    }
	  if (plt != NULL)
	      rl2_destroy_palette (plt);
	  plt = NULL;
	  sample_type = RL2_SAMPLE_UINT8;
................................................................................
		/* preparing a Shaded Relief mask */
		double scale_factor =
		    rl2_get_shaded_relief_scale_factor (handle, coverage);
		if (rl2_get_raster_symbolizer_shaded_relief
		    (style, &brightness_only, &relief_factor) != RL2_OK)
		    goto error;
		if (rl2_build_shaded_relief_mask
		    (handle, max_threads, cvg, by_section, section_id,
		     relief_factor, scale_factor, width, height, minx, miny,
		     maxx, maxy, x_res, y_res, &shaded_relief,
		     &shaded_relief_sz) != RL2_OK)
		    goto error;

		if (brightness_only || !rl2_has_styled_rgb_colors (style))
		  {
		      /* returning a Grayscale ShadedRelief (BrightnessOnly) */
		      unsigned int row;
		      unsigned int col;
................................................................................

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    if (by_section)
      {
	  /* only from a single Section */






	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
	       "FROM \"%s\" "
	       "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
	       "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
	       "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);

      }
    else
      {
	  /* whole Coverage */
	  sql =
	      sqlite3_mprintf
	      ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
................................................................................
	  if (bgcolor != NULL)
	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			       bgcolor);
	  else
	      void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			       no_data);
      }
    if (by_section)
      {
	  /* only from a single Section */
	  if (!rl2_load_dbms_tiles_section
	      (handle, max_threads, section_id, stmt_tiles, stmt_data, bufpix,
	       width, height, sample_type, num_bands, auto_ndvi, red_band,
	       nir_band, xx_res, yy_res, minx, miny, maxx, maxy, level, scale,
	       plt, no_data))
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (!rl2_load_dbms_tiles
	      (handle, max_threads, stmt_tiles, stmt_data, bufpix, width,
	       height, sample_type, num_bands, auto_ndvi, red_band, nir_band,
	       xx_res, yy_res, minx, miny, maxx, maxy, level, scale, plt,
	       no_data, style, stats))
	      goto error;
      }
    if (kill_no_data != NULL)
	rl2_destroy_pixel (kill_no_data);
    sqlite3_finalize (stmt_tiles);
    sqlite3_finalize (stmt_data);
    if (shaded_relief != NULL)
      {
	  /* applying the Shaded Relief */
................................................................................
	rl2_destroy_pixel (kill_no_data);
    if (shaded_relief != NULL)
	free (shaded_relief);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raw_raster_data (sqlite3 * handle, int max_threads,
			 rl2CoveragePtr cvg, unsigned int width,
			 unsigned int height, double minx, double miny,
			 double maxx, double maxy, double x_res, double y_res,
			 unsigned char **buffer, int *buf_size,
			 rl2PalettePtr * palette, unsigned char out_pixel)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 0, 0,
					   width, height, minx, miny, maxx,
					   maxy, x_res, y_res, buffer,
					   buf_size, palette, out_pixel, NULL,
					   NULL, NULL);
}

RL2_DECLARE int
rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, sqlite3_int64 section_id,
				 unsigned int width, unsigned int height,
				 double minx, double miny, double maxx,
................................................................................
				 rl2PalettePtr * palette,
				 unsigned char out_pixel)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage/Section */
    return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 1,
					   section_id, width, height, minx,
					   miny, maxx, maxy, x_res, y_res,
					   buffer, buf_size, palette,
					   out_pixel, NULL, NULL, NULL);
}

static int
get_triple_band_raw_raster_data_common (int by_section, sqlite3 * handle,
					rl2CoveragePtr cvg,
					sqlite3_int64 section_id,
					unsigned int width,
					unsigned int height, double minx,
					double miny, double maxx, double maxy,
					double x_res, double y_res,
					unsigned char red_band,
					unsigned char green_band,
					unsigned char blue_band,
					unsigned char **buffer, int *buf_size,
					rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
................................................................................
				     unsigned char blue_band,
				     unsigned char **buffer, int *buf_size,
				     rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return get_triple_band_raw_raster_data_common (0, handle, cvg, 0, width,
						   height, minx, miny, maxx,
						   maxy, x_res, y_res,
						   red_band, green_band,
						   blue_band, buffer,
						   buf_size, bgcolor);
}

RL2_DECLARE int
rl2_get_section_triple_band_raw_raster_data (sqlite3 * handle,
					     rl2CoveragePtr cvg,
					     sqlite3_int64 section_id,
					     unsigned int width,
................................................................................
					     int *buf_size, rl2PixelPtr bgcolor)
{
/* attempting to return a buffer containing raw pixels - Section */
    return get_triple_band_raw_raster_data_common (1, handle, cvg, section_id,
						   width, height, minx, miny,
						   maxx, maxy, x_res, y_res,
						   red_band, green_band,
						   blue_band, buffer,
						   buf_size, bgcolor);
}

static int
get_mono_band_raw_raster_data_common (int by_section, sqlite3 * handle,
				      rl2CoveragePtr cvg,
				      sqlite3_int64 section_id,
				      unsigned int width, unsigned int height,
................................................................................
				   double x_res, double y_res,
				   unsigned char mono_band,
				   unsigned char **buffer, int *buf_size,
				   rl2PixelPtr no_data)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage */
    return get_mono_band_raw_raster_data_common (0, handle, cvg, 0, width,
						 height, minx, miny, maxx,
						 maxy, x_res, y_res, buffer,
						 buf_size, mono_band, no_data);
}

RL2_DECLARE int
rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle,
					   rl2CoveragePtr cvg,
					   sqlite3_int64 section_id,
					   unsigned int width,
					   unsigned int height, double minx,
					   double miny, double maxx,
					   double maxy, double x_res,
					   double y_res,
					   unsigned char mono_band,
................................................................................
						 buffer, buf_size, mono_band,
						 no_data);
}

RL2_DECLARE int
rl2_get_raw_raster_data_bgcolor (sqlite3 * handle, int max_threads,
				 rl2CoveragePtr cvg, unsigned int width,
				 unsigned int height, double minx,
				 double miny, double maxx, double maxy,
				 double x_res, double y_res,
				 unsigned char **buffer, int *buf_size,
				 rl2PalettePtr * palette,
				 unsigned char *out_pixel,
				 unsigned char bg_red, unsigned char bg_green,
				 unsigned char bg_blue,
				 rl2RasterSymbolizerPtr style,
				 rl2RasterStatisticsPtr stats)
{
/* attempting to return a buffer containing raw pixels from the DBMS Coverage + bgcolor */
    int ret;
    rl2PixelPtr no_data = NULL;
    const char *coverage;
................................................................................
	  if (index < 0)
	    {
		/* palette color found */
		switch (sample_type)
		  {
		  case RL2_SAMPLE_1_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_1_BIT,
					    RL2_PIXEL_PALETTE, 1);
		      rl2_set_pixel_sample_1bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_2_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_2_BIT,
					    RL2_PIXEL_PALETTE, 1);
		      rl2_set_pixel_sample_2bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_4_BIT:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_4_BIT,
					    RL2_PIXEL_PALETTE, 1);
		      rl2_set_pixel_sample_4bit (no_data,
						 (unsigned char) index);
		      break;
		  case RL2_SAMPLE_UINT8:
		      no_data =
			  rl2_create_pixel (RL2_SAMPLE_UINT8,
					    RL2_PIXEL_PALETTE, 1);
		      rl2_set_pixel_sample_uint8 (no_data, RL2_PALETTE_BAND,
						  (unsigned char) index);
		      break;

		  };
	    }
      }
................................................................................
    sqlite3_stmt *stmt = NULL;
    char *sql;
    int ret;
    if (handle == NULL || coverage == NULL || palette == NULL)
	return RL2_ERROR;

    sql =
	sqlite3_mprintf
	("SELECT sample_type, pixel_type FROM raster_coverages "
	 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
	  goto error;
      }
................................................................................
	sqlite3_finalize (stmt);
    if (stl != NULL)
	rl2_destroy_coverage_style (stl);
    return NULL;
}

RL2_DECLARE rl2FeatureTypeStylePtr
rl2_create_feature_type_style_from_dbms (sqlite3 * handle,
					 const char *coverage,
					 const char *style)
{
/* attempting to load and parse a Feature Type Style */
    const char *sql;
    int ret;
    sqlite3_stmt *stmt = NULL;
    rl2FeatureTypeStylePtr stl = NULL;
................................................................................
    char **results;
    int rows;
    int columns;
    int i;
    int ok = 0;
/* testing if the Layer Style exists */
    char *sql =
	sqlite3_mprintf
	("SELECT style_name FROM SE_raster_styled_layers AS r "
	 "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) "
	 "WHERE Lower(r.coverage_name) = Lower(%Q) AND "
	 "Lower(s.style_name) = Lower(%Q)", namedLayer,
	 namedStyle);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 0;
    for (i = 1; i <= rows; i++)
	ok = 1;
    sqlite3_free_table (results);
................................................................................
    int section_summary = 0;
    rl2PixelPtr no_data = NULL;
    rl2PalettePtr palette = NULL;
    char *title = NULL;
    char *abstract = NULL;
    unsigned char *statistics = NULL;
    int statistics_sz;
    int ok_geo = 0;
    int ok_bbox = 0;
    double geo_minx;
    double geo_miny;
    double geo_maxx;
    double geo_maxy;
    double ext_minx;
    double ext_miny;
................................................................................
		      strcpy (abstract, value);
		  }
		if (sqlite3_column_type (stmt, 18) == SQLITE_BLOB)
		  {
		      statistics_sz = sqlite3_column_bytes (stmt, 18);
		      statistics = malloc (statistics_sz);
		      memcpy (statistics,
			      (const unsigned char *)

			      sqlite3_column_blob (stmt, 18), statistics_sz);
		  }
		if (sqlite3_column_type (stmt, 19) == SQLITE_FLOAT)
		  {
		      geo_minx = sqlite3_column_double (stmt, 19);
		      ok_geo++;
		  }
		if (sqlite3_column_type (stmt, 20) == SQLITE_FLOAT)
		  {
		      geo_miny = sqlite3_column_double (stmt, 20);
		      ok_geo++;
		  }
		if (sqlite3_column_type (stmt, 21) == SQLITE_FLOAT)
		  {
		      geo_maxx = sqlite3_column_double (stmt, 21);
		      ok_geo++;
		  }
		if (sqlite3_column_type (stmt, 22) == SQLITE_FLOAT)
		  {
		      geo_maxy = sqlite3_column_double (stmt, 22);
		      ok_geo++;
		  }
		if (sqlite3_column_type (stmt, 23) == SQLITE_FLOAT)
		  {
		      ext_minx = sqlite3_column_double (stmt, 23);
		      ok_bbox++;
		  }
		if (sqlite3_column_type (stmt, 24) == SQLITE_FLOAT)
................................................................................
		  {
		      const unsigned char *blob =
			  sqlite3_column_blob (stmt, 33);
		      int blob_sz = sqlite3_column_bytes (stmt, 33);
		      palette = rl2_deserialize_dbms_palette (blob, blob_sz);
		  }
		if (ok_sample && ok_pixel && ok_num_bands && ok_compression
		    && ok_quality && ok_tile_width && ok_tile_height
		    && ok_x_res && ok_y_res && ok_srid && ok_nodata
		    && ok_strict && ok_mixed && ok_paths && ok_md5
		    && ok_summary)
		    ok = 1;
		if (ok_geo != 4)
		    ok_geo = 0;
		if (ok_bbox != 4)
		    ok_bbox = 0;
	    }
      }
    sqlite3_finalize (stmt);
    stmt = NULL;
    if (!ok)
	goto error;
................................................................................
				    compr, quality,
				    (unsigned short) tile_width,
				    (unsigned short) tile_height, srid,
				    horz_res, vert_res, no_data, palette,
				    strict_resolution, mixed_resolutions,
				    section_paths, section_md5,
				    section_summary);
    if (no_data != NULL)
	rl2_destroy_pixel (no_data);
    if (palette != NULL)
	rl2_destroy_palette (palette);
    if (ret != RL2_OK)
	goto error;

/* completing the destination coverage */
    sql = "UPDATE main.raster_coverages SET title = ?, "
	"abstract = ?, statistics = ?, geo_minx = ?, geo_miny = ?, geo_maxx = ?, "
	"geo_maxy = ?, extent_minx = ?, extent_miny = ?, extent_maxx = ?, "
................................................................................
	sqlite3_bind_null (stmt, 2);
    else
	sqlite3_bind_text (stmt, 2, abstract, strlen (abstract), free);
    if (statistics == NULL)
	sqlite3_bind_null (stmt, 3);
    else
	sqlite3_bind_blob (stmt, 3, statistics, statistics_sz, free);
    if (ok_geo)
      {
	  sqlite3_bind_double (stmt, 4, geo_minx);
	  sqlite3_bind_double (stmt, 5, geo_miny);
	  sqlite3_bind_double (stmt, 6, geo_maxx);
	  sqlite3_bind_double (stmt, 7, geo_maxy);




      }
    else
      {
	  sqlite3_bind_null (stmt, 4);
	  sqlite3_bind_null (stmt, 5);
	  sqlite3_bind_null (stmt, 6);
	  sqlite3_bind_null (stmt, 7);
      }
    if (ok_bbox)
      {
	  sqlite3_bind_double (stmt, 8, ext_minx);
	  sqlite3_bind_double (stmt, 9, ext_miny);
	  sqlite3_bind_double (stmt, 10, ext_maxx);
	  sqlite3_bind_double (stmt, 11, ext_maxy);
      }
    else
      {
	  sqlite3_bind_null (stmt, 8);
	  sqlite3_bind_null (stmt, 9);
	  sqlite3_bind_null (stmt, 10);
	  sqlite3_bind_null (stmt, 11);
      }
    if (!ok_is_queryable)
	sqlite3_bind_null (stmt, 12);
................................................................................
    if (!ok_enable_auto_ndvi)
	sqlite3_bind_null (stmt, 17);
    else
	sqlite3_bind_int (stmt, 17, enable_auto_ndvi);
    sqlite3_bind_text (stmt, 18, coverage_name, strlen (coverage_name),
		       SQLITE_STATIC);
    ret = sqlite3_step (stmt);
    sqlite3_finalize (stmt);
    stmt = NULL;
    if (ret == SQLITE_DONE || ret == SQLITE_ROW)
	goto ok_continue;
    fprintf (stderr,
	     "sqlite3_step() error: UPDATE raster_coverages \"%s\"\n",
	     sqlite3_errmsg (sqlite));
    goto error;

................................................................................
			   "x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
			   "SELECT pyramid_level, x_resolution_1_1, y_resolution_1_1, x_resolution_1_2, "
			   "y_resolution_1_2, x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, "
			   "y_resolution_1_8 FROM \"%s\".\"%s\"", xxcoverage,
			   xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-SECTIONS */
    xcoverage = sqlite3_mprintf ("%s_sections", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    sql =
	sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, "
			 "width, height, file_path, md5_checksum, summary, statistics, geometry) "
			 "SELECT section_id, section_name, width, height, file_path, md5_checksum, "
			 "summary, statistics, geometry FROM \"%s\".\"%s\"",
			 xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-TILES */
    xcoverage = sqlite3_mprintf ("%s_tiles", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, pyramid_level, "
			   "section_id, geometry) SELECT tile_id, pyramid_level, section_id, geometry "
			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying  coverage-TILE_DATA */
    xcoverage = sqlite3_mprintf ("%s_tile_data", coverage_name);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, tile_data_odd, "
			   "tile_data_even) SELECT tile_id, tile_data_odd, tile_data_even "
			   "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage);
    free (xxcoverage);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying KEYWORDS */
    sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_keyword "
			   "(coverage_name, keyword) SELECT coverage_name, keyword "
			   "FROM \"%s\".raster_coverages_keyword", xdb);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

/* copying SRID */
    sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_srid "
			   "(coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx) "
			   "SELECT coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx "
			   "FROM \"%s\".raster_coverages_srid", xdb);
    ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	goto error;

    free (xdb);
    return RL2_OK;

  error:
    if (xdb != NULL)
	free (xdb);
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}

RL2_PRIVATE int
do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg)
{
/* testing for an empty Palette Coverage */
    rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg;
    int ret;
    char **results;
    int rows;
    int columns;
    int i;
    int initial = 0;
    char *xcoverage;
    char *xxcoverage;

    if (coverage == NULL)
	return RL2_ERROR;
    if (coverage->coverageName == NULL)
	return RL2_ERROR;

    xcoverage = sqlite3_mprintf ("%s_tiles", coverage->coverageName);
    xxcoverage = rl2_double_quoted_sql (xcoverage);
    sqlite3_free (xcoverage);
    char *sql = sqlite3_mprintf ("SELECT Count(*) FROM \"%s\"",
				 xxcoverage);
    free (xxcoverage);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return RL2_ERROR;
    for (i = 1; i <= rows; i++)
      {
	  if (atoi (results[(i * columns) + 0]) == 0)
	      initial = 1;
      }
    sqlite3_free_table (results);
    if (initial)
	return RL2_TRUE;
    return RL2_FALSE;
}

RL2_DECLARE int
rl2_install_dbms_palette_from_tiff (sqlite3 * handle, rl2CoveragePtr coverage,
				    rl2TiffOriginPtr tiff)
{
/*attempting to merge/update a Coverage's Palette */
    int i;
    int j;
    int changed = 0;
    int maxPalette = 0;
    unsigned char red[256];
    unsigned char green[256];
    unsigned char blue[256];
    int ok;
    rl2PalettePtr palette = NULL;
    rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage;
    rl2PrivTiffOriginPtr origin = (rl2PrivTiffOriginPtr) tiff;
    if (cvg == NULL || origin == NULL)
	return RL2_ERROR;

    for (i = 0; i < origin->maxPalette; i++)
      {
	  /* checking TIFF palette entries */
	  unsigned char tiff_red = origin->red[i];
	  unsigned char tiff_green = origin->green[i];
	  unsigned char tiff_blue = origin->blue[i];
	  ok = 0;
	  for (j = 0; j < maxPalette; j++)
	    {
		if (tiff_red == red[j] && tiff_green == green[j]
		    && tiff_blue == blue[j])
		  {
		      /* found a matching color */
		      ok = 1;
		      break;
		  }
	    }
	  if (!ok)
	    {
		/* attempting to insert a new color into the pseudo-Palette */
		if (maxPalette == 256)
		    goto error;
		red[maxPalette] = tiff_red;
		green[maxPalette] = tiff_green;
		blue[maxPalette] = tiff_blue;
		maxPalette++;
		changed = 1;
	    }
      }
    if (changed)
      {
	  /* updating the DBMS Palette */
	  palette = rl2_create_palette (maxPalette);
	  if (palette == NULL)
	      goto error;
	  for (j = 0; j < maxPalette; j++)
	      rl2_set_palette_color (palette, j, red[j], green[j], blue[j]);
	  if (rl2_update_dbms_palette (handle, cvg->coverageName, palette) !=
	      RL2_OK)
	      goto error;
      }
    set_remapped_palette (origin, palette);
    rl2_destroy_palette (palette);
    return RL2_OK;

  error:
    if (palette != NULL)
	rl2_destroy_palette (palette);
    return RL2_ERROR;
}

Changes to src/rl2gif.c.

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
	rl2_destroy_palette (palette);
    return NULL;
}

RL2_PRIVATE int
rl2_decode_gif (const unsigned char *gif, int gif_size, unsigned int *xwidth,
		unsigned int *xheight, unsigned char *xsample_type,
		unsigned char *xpixel_type, unsigned char **blob, int *blob_sz,
		rl2PalettePtr * palette)
{
/* attempting to create a raster from a GIF image - raw block */
    struct gif_memory_buffer membuf;
#ifdef GIFLIB_MAJOR
    int ErrorCode;
#endif
    GifFileType *GifFile = NULL;







|
|







602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
	rl2_destroy_palette (palette);
    return NULL;
}

RL2_PRIVATE int
rl2_decode_gif (const unsigned char *gif, int gif_size, unsigned int *xwidth,
		unsigned int *xheight, unsigned char *xsample_type,
		unsigned char *xpixel_type, unsigned char **blob,
		int *blob_sz, rl2PalettePtr * palette)
{
/* attempting to create a raster from a GIF image - raw block */
    struct gif_memory_buffer membuf;
#ifdef GIFLIB_MAJOR
    int ErrorCode;
#endif
    GifFileType *GifFile = NULL;

Changes to src/rl2import.c.

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360

361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
...
588
589
590
591
592
593
594
595
596




597
598
599
600
601
602
603
604
605
606
607
608
609
610
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
...
908
909
910
911
912
913
914

915
916
917
918
919
920
921
922
...
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
....
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
....
1266
1267
1268
1269
1270
1271
1272
1273
1274




1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
....
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
....
1717
1718
1719
1720
1721
1722
1723


1724


1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
....
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
....
2070
2071
2072
2073
2074
2075
2076
2077
2078

2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
....
2171
2172
2173
2174
2175
2176
2177


2178


2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
....
2212
2213
2214
2215
2216
2217
2218










2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
....
2534
2535
2536
2537
2538
2539
2540
2541
2542

2543
2544
2545
2546

2547
2548
2549
2550
2551
2552
2553
2554
2555
....
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
....
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
....
2922
2923
2924
2925
2926
2927
2928


















2929
2930

2931
2932
2933
2934
2935
2936
2937
....
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
....
3125
3126
3127
3128
3129
3130
3131
3132

3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
....
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
....
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
....
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
....
3376
3377
3378
3379
3380
3381
3382
3383

3384
3385
3386
3387
3388
3389
3390
....
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
....
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511

3512
3513
3514
3515
3516
3517
3518
....
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
....
3580
3581
3582
3583
3584
3585
3586
3587
3588

3589
3590
3591
3592

3593
3594
3595
3596
3597
3598
3599
....
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
....
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
....
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
....
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817

3818
3819
3820
3821
3822
3823
3824
3825
3826
....
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
....
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
....
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
....
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124

4125
4126
4127
4128
4129
4130
4131
....
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
....
4206
4207
4208
4209
4210
4211
4212
4213

4214
4215
4216
4217
4218
4219
4220
4221
....
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
....
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
....
4388
4389
4390
4391
4392
4393
4394
4395

4396
4397
4398
4399
4400
4401
4402
....
4410
4411
4412
4413
4414
4415
4416
4417

4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
....
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
....
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523

4524
4525
4526
4527
4528
4529
4530
....
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584

4585
4586
4587

4588

4589
4590
4591

4592
4593
4594
4595
4596
4597
4598
....
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
....
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761

4762
4763
4764
4765
4766
4767
4768
....
4774
4775
4776
4777
4778
4779
4780
4781
4782

4783
4784
4785
4786
4787
4788
4789
4790
4791
....
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892

4893
4894
4895
4896
4897
4898
4899
....
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
....
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
....
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136

5137
5138
5139
5140
5141
5142
5143
5144
....
5184
5185
5186
5187
5188
5189
5190
5191

5192
5193
5194
5195
5196
5197
5198
5199
5200
....
5223
5224
5225
5226
5227
5228
5229
5230

5231
5232
5233
5234
5235
5236
5237
5238
....
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
....
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
....
5347
5348
5349
5350
5351
5352
5353
5354

5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369

5370
5371
5372
5373
5374
5375
5376

5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
....
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
....
5478
5479
5480
5481
5482
5483
5484
5485
5486

5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
....
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
....
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589

5590
5591
5592
5593
5594
5595
5596
....
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
....
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
































































































































































































































































































































































































    tile->blob_odd = NULL;
    tile->blob_even = NULL;
    rl2_destroy_raster (tile->raster);
    tile->raster = NULL;
}

static void
addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row, unsigned int col,
		     double minx, double maxy)
{
/* adding a Tile to some AuxImporter container */
    rl2AuxImporterTilePtr tile;
    if (aux == NULL)
	return;

    tile = malloc (sizeof (rl2AuxImporterTile));
................................................................................
    switch (aux->origin_type)
      {
      case RL2_ORIGIN_ASCII_GRID:
	  ascii_grid_origin = (rl2AsciiGridOriginPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_ascii_grid_origin ((rl2CoveragePtr)
						   (aux->coverage),
						   ascii_grid_origin, tile->row,

						   tile->col, aux->verbose);
	  break;
      case RL2_ORIGIN_JPEG:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_jpeg_origin ((rl2CoveragePtr) (aux->coverage),
					     raster_origin, tile->row,

					     tile->col, aux->forced_conversion,
					     aux->verbose);
	  break;
      case RL2_ORIGIN_JPEG2000:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_jpeg2000_origin ((rl2CoveragePtr)
						 (aux->coverage), raster_origin,

						 tile->row, tile->col,
						 aux->forced_conversion,
						 aux->verbose);
	  break;
      case RL2_ORIGIN_TIFF:
	  tiff_origin = (rl2TiffOriginPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_tiff_origin ((rl2CoveragePtr) (aux->coverage),
					     tiff_origin, tile->row, tile->col,

					     aux->srid, aux->verbose);
	  break;
      case RL2_ORIGIN_RAW:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_raw_pixels ((rl2CoveragePtr) (aux->coverage),
					    raster_origin, tile->row,
					    tile->col);
................................................................................
      }
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */
	  if (res_x != coverage->hResolution)




	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (res_y != coverage->vResolution)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	  fprintf (stderr, "Coverage/ASCII mismatch\n");
	  goto error;
      }
    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, 1);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
	      (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl))
	      goto error;
      }

/* preparing all Tile Requests */
    aux =
	createAuxImporter (coverage, srid, maxx, miny, tile_w, tile_h, res_x,
			   res_y, RL2_ORIGIN_ASCII_GRID, origin, RL2_CONVERT_NO,
			   verbose, compression, 100);
    tile_maxy = maxy;
    for (row = 0; row < height; row += tile_h)
      {
	  tile_minx = minx;
	  for (col = 0; col < width; col += tile_w)
	    {
		/* adding a Tile request */
................................................................................
}

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */

static int
check_jpeg2000_origin_compatibility (rl2RasterPtr raster,
				     rl2CoveragePtr coverage,

				     unsigned int *width, unsigned int *height,
				     unsigned char *forced_conversion)
{
/* checking if the Jpeg2000 and the Coverage are mutually compatible */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
    rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage;
    if (rst == NULL || cvg == NULL)
	return 0;
................................................................................
	    {
		*width = rst->width;
		*height = rst->height;
		*forced_conversion = RL2_CONVERT_NO;
		return 1;
	    }
      }
    if (rst->sampleType == RL2_SAMPLE_UINT16 && rst->pixelType == RL2_PIXEL_RGB
	&& rst->nBands == 3)
      {
	  if (cvg->sampleType == RL2_SAMPLE_UINT16
	      && cvg->pixelType == RL2_PIXEL_RGB && cvg->nBands == 3)
	    {
		*width = rst->width;
		*height = rst->height;
		*forced_conversion = RL2_CONVERT_NO;
................................................................................
	  maxy = height - 1.0;
	  res_x = 1.0;
	  res_y = 1.0;
      }
    raster_in = (rl2PrivRasterPtr) rst_in;
    xml_summary =
	rl2_build_jpeg_xml_summary (width, height, raster_in->pixelType,
				    is_georeferenced, res_x, res_y, minx, miny,
				    maxx, maxy);

    printf ("------------------\n");
    if (total > 1)
	printf ("%d/%d) Importing: %s\n", current, total, src_path);
    else
	printf ("Importing: %s\n", src_path);
    printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
      }
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */
	  if (res_x != coverage->hResolution)




	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (res_y != coverage->vResolution)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	    }
      }

    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
	  maxy = height - 1.0;
	  res_x = 1.0;
	  res_y = 1.0;
      }
    raster_in = (rl2PrivRasterPtr) rst_in;
    xml_summary =
	rl2_build_jpeg2000_xml_summary (width, height, raster_in->sampleType,
					raster_in->pixelType, raster_in->nBands,
					is_georeferenced, res_x, res_y, minx,
					miny, maxx, maxy, tile_width,
					tile_height);

    printf ("------------------\n");
    if (total > 1)
	printf ("%d/%d) Importing: %s\n", current, total, src_path);
    else
	printf ("Importing: %s\n", src_path);
    printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */


	  if (res_x != coverage->hResolution)


	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (res_y != coverage->vResolution)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	    }
      }

    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
    rl2AuxImporterTilePtr *thread_slots = NULL;
    int thread_count;

    if (is_ascii_grid (src_path))
	return do_import_ascii_grid (handle, max_threads, src_path, cvg,
				     section, force_srid, tile_w, tile_h,
				     pyramidize, sample_type, compression,
				     stmt_data, stmt_tils, stmt_sect, stmt_levl,
				     stmt_upd_sect, verbose, current, total);


    if (is_jpeg_image (src_path))
	return do_import_jpeg_image (handle, max_threads, src_path, cvg,
				     section, force_srid, tile_w, tile_h,
				     pyramidize, sample_type, num_bands,
				     compression, quality, stmt_data, stmt_tils,
				     stmt_sect, stmt_levl, stmt_upd_sect,
				     verbose, current, total);

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
    if (is_jpeg2000_image (src_path))
	return do_import_jpeg2000_image (handle, max_threads, src_path, cvg,
					 section, force_srid, tile_w, tile_h,
					 pyramidize, sample_type, num_bands,
					 compression, quality, stmt_data,
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */


	  if (res_x != coverage->hResolution)


	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (res_y != coverage->vResolution)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
		goto error;
	    }
      }

    if (pixel_type == RL2_PIXEL_PALETTE)
      {
	  /* remapping the Palette */










	  if (rl2_check_dbms_palette (handle, cvg, origin) != RL2_OK)
	    {
		fprintf (stderr, "Mismatching Palette !!!\n");
		goto error;
	    }
      }

    if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose) !=
	RL2_TRUE)
      {
	  fprintf (stderr, "Coverage/TIFF mismatch\n");
	  goto error;
      }
    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx, maxy,
	 xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
		      if ((c_file.attrib & _A_RDONLY) == _A_RDONLY
			  || (c_file.attrib & _A_NORMAL) == _A_NORMAL)
			{
			    path =
				sqlite3_mprintf ("%s/%s", dir_path,
						 c_file.name);
			    ret =
				do_import_file (handle, max_threads, path, cvg,
						section, worldfile, force_srid,

						pyramidize, sample_type,
						pixel_type, num_bands, tile_w,
						tile_h, compression, quality,
						stmt_data, stmt_tils, stmt_sect,

						stmt_levl, stmt_upd_sect,
						verbose, cnt + 1, total);
			    sqlite3_free (path);
			    if (!ret)
				goto error;
			    cnt++;
			}
		      if (_findnext (hFile, &c_file) != 0)
			  break;
................................................................................
	       stmt_sect, stmt_levl, stmt_upd_sect, verbose, -1, -1))
	      goto error;
      }
    else
      {
	  /* importing all Image files from a whole directory */
	  if (!do_import_dir
	      (handle, max_threads, dir_path, file_ext, cvg, section, worldfile,
	       force_srid, pyramidize, sample_type, pixel_type, num_bands,
	       tile_w, tile_h, compression, quality, stmt_data, stmt_tils,
	       stmt_sect, stmt_levl, stmt_upd_sect, verbose))
	      goto error;
      }

    sqlite3_finalize (stmt_upd_sect);
    sqlite3_finalize (stmt_sect);
    sqlite3_finalize (stmt_levl);
    sqlite3_finalize (stmt_tils);
................................................................................
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_uint8_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
			   unsigned char num_bands, unsigned int width,
			   unsigned int height,
			   unsigned int tile_width,
			   unsigned int tile_height, unsigned int base_y,
			   unsigned int base_x)
{
/* copying UINT8 pixels from the output buffer into the tile */
    unsigned int x;
    unsigned int y;
    int b;
    const unsigned char *p_in;
    unsigned char *p_out = tile;
................................................................................
	    {
		if ((base_x + x) >= width)
		  {
		      p_out += num_bands;
		      p_in += num_bands;
		      continue;
		  }


















		for (b = 0; b < num_bands; b++)
		    *p_out++ = *p_in++;

	    }
      }
}

static void
copy_int16_outbuf_to_tile (const short *outbuf, short *tile,
			   unsigned int width,
................................................................................
		  }
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_uint16_outbuf_to_tile (const unsigned short *outbuf, unsigned short *tile,
			    unsigned char num_bands, unsigned int width,
			    unsigned int height,
			    unsigned int tile_width,
			    unsigned int tile_height, unsigned int base_y,
			    unsigned int base_x)
{
/* copying UINT16 pixels from the output buffer into the tile */
    unsigned int x;
    unsigned int y;
    int b;
    const unsigned short *p_in;
    unsigned short *p_out = tile;
................................................................................
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_from_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
			  unsigned char sample_type, unsigned char num_bands,

			  unsigned int width, unsigned int height,
			  unsigned int tile_width, unsigned int tile_height,
			  unsigned int base_y, unsigned int base_x)
{
/* copying pixels from the output buffer into the tile */
    switch (sample_type)
      {
      case RL2_SAMPLE_INT8:
	  copy_int8_outbuf_to_tile ((char *) outbuf,
				    (char *) tile, width, height, tile_width,
				    tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_int16_outbuf_to_tile ((short *) outbuf,
				     (short *) tile, width, height, tile_width,
				     tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_UINT16:
	  copy_uint16_outbuf_to_tile ((unsigned short *) outbuf,
				      (unsigned short *) tile, num_bands,
				      width, height, tile_width, tile_height,
				      base_y, base_x);
	  break;
................................................................................
      case RL2_SAMPLE_UINT32:
	  copy_uint32_outbuf_to_tile ((unsigned int *) outbuf,
				      (unsigned int *) tile, width, height,
				      tile_width, tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_float_outbuf_to_tile ((float *) outbuf,
				     (float *) tile, width, height, tile_width,
				     tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_double_outbuf_to_tile ((double *) outbuf,
				      (double *) tile, width, height,
				      tile_width, tile_height, base_y, base_x);
	  break;
      default:
	  copy_uint8_outbuf_to_tile ((unsigned char *) outbuf,
				     (unsigned char *) tile, num_bands, width,
				     height, tile_width, tile_height, base_y,
				     base_x);
	  break;
      };
}

static int
export_geotiff_common (sqlite3 * handle, int max_threads, const char *dst_path,
		       rl2CoveragePtr cvg, int by_section,
		       sqlite3_int64 section_id, double x_res, double y_res,
		       double minx, double miny, double maxx, double maxy,
		       unsigned int width, unsigned int height,
		       unsigned char compression, unsigned int tile_sz,
		       int with_worldfile)
{
/* exporting a GeoTIFF common implementation */
    rl2RasterPtr raster = NULL;
    rl2PalettePtr palette = NULL;
    rl2PalettePtr plt2 = NULL;
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
					 num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  num_bands, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
    return export_geotiff_common (handle, max_threads, dst_path, cvg, 0, 0,
				  x_res, y_res, minx, miny, maxx, maxy, width,
				  height, compression, tile_sz, with_worldfile);
}

RL2_DECLARE int
rl2_export_section_geotiff_from_dbms (sqlite3 * handle, int max_threads,
				      const char *dst_path, rl2CoveragePtr cvg,

				      sqlite3_int64 section_id, double x_res,
				      double y_res, double minx, double miny,
				      double maxx, double maxy,
				      unsigned int width, unsigned int height,
				      unsigned char compression,
				      unsigned int tile_sz, int with_worldfile)
{
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single select Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
	  pix_sz = 8;
	  break;
      };

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, pixel_type,
					       num_bands, palette, compression,
					       1, tile_sz, srid, minx, miny,
					       maxx, maxy, xx_res, yy_res);

    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
					 num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  num_bands, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
				     double miny, double maxx, double maxy,
				     unsigned int width, unsigned int height,
				     unsigned char compression,
				     unsigned int tile_sz)
{
/* exporting a TIFF+TFW from the DBMS into the file-system */
    return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 0,
					0, x_res, y_res, minx, miny, maxx, maxy,
					width, height, compression, tile_sz);

}

RL2_DECLARE int
rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle, int max_threads,

					     const char *dst_path,
					     rl2CoveragePtr cvg,
					     sqlite3_int64 section_id,
					     double x_res, double y_res,
					     double minx, double miny,
					     double maxx, double maxy,
					     unsigned int width,
................................................................................
					     unsigned int height,
					     unsigned char compression,
					     unsigned int tile_sz)
{
/* exporting a TIFF+TFW - single Section */
    return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 1,
					section_id, x_res, y_res, minx, miny,
					maxx, maxy, width, height, compression,
					tile_sz);
}

static int
export_tiff_common (sqlite3 * handle, int max_threads, const char *dst_path,
		    rl2CoveragePtr cvg, int by_section,
		    sqlite3_int64 section_id, double x_res, double y_res,
		    double minx, double miny, double maxx, double maxy,
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
					 num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  num_bands, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
	rl2_destroy_palette (palette);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_tiff_from_dbms (sqlite3 * handle, int max_threads,
			   const char *dst_path, rl2CoveragePtr cvg,
			   double x_res, double y_res, double minx, double miny,
			   double maxx, double maxy, unsigned int width,
			   unsigned int height, unsigned char compression,
			   unsigned int tile_sz)
{
/* exporting a plain TIFF from the DBMS into the file-system */
    return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0, x_res,
			       y_res, minx, miny, maxx, maxy, width, height,
			       compression, tile_sz);
}

RL2_DECLARE int
rl2_export_section_tiff_from_dbms (sqlite3 * handle, int max_threads,
				   const char *dst_path, rl2CoveragePtr cvg,
				   sqlite3_int64 section_id, double x_res,
				   double y_res, double minx, double miny,
				   double maxx, double maxy, unsigned int width,
				   unsigned int height,
				   unsigned char compression,
				   unsigned int tile_sz)
{
/* exporting a plain TIFF - single Section*/
    return export_tiff_common (handle, max_threads, dst_path, cvg, 1,
			       section_id, x_res, y_res, minx, miny, maxx, maxy,
			       width, height, compression, tile_sz);
}

static int
export_triple_band_geotiff_common (int by_section, sqlite3 * handle,
				   const char *dst_path,
				   rl2CoveragePtr cvg, sqlite3_int64 section_id,

				   double x_res, double y_res, double minx,
				   double miny, double maxx, double maxy,
				   unsigned int width, unsigned int height,
				   unsigned char red_band,
				   unsigned char green_band,
				   unsigned char blue_band,
				   unsigned char compression,
				   unsigned int tile_sz, int with_worldfile)
{
................................................................................
	      goto error;
      }

    tiff =
	rl2_create_geotiff_destination (dst_path, handle, width, height,
					sample_type, RL2_PIXEL_RGB, 3,
					NULL, compression, 1, tile_sz, srid,
					minx, miny, maxx, maxy, xx_res, yy_res,
					with_worldfile);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
    else
	out_pixel = RL2_PIXEL_GRAYSCALE;

    tiff =
	rl2_create_geotiff_destination (dst_path, handle, width, height,
					sample_type, out_pixel, 1,
					NULL, compression, 1, tile_sz, srid,
					minx, miny, maxx, maxy, xx_res, yy_res,
					with_worldfile);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       out_pixel, 1, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);

		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					unsigned int height,
					unsigned char mono_band,
					unsigned char compression,
					unsigned int tile_sz,
					int with_worldfile)
{
/* exporting a Mono-Band GeoTIFF from the DBMS into the file-system */
    return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0, x_res,
					    y_res, minx, miny, maxx, maxy,
					    width, height, mono_band,
					    compression, tile_sz,
					    with_worldfile);
}

RL2_DECLARE int
rl2_export_section_mono_band_geotiff_from_dbms (sqlite3 * handle,
						const char *dst_path,
................................................................................

static int
export_triple_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
					  const char *dst_path,
					  rl2CoveragePtr cvg,
					  sqlite3_int64 section_id,
					  double x_res, double y_res,
					  double minx, double miny, double maxx,

					  double maxy, unsigned int width,
					  unsigned int height,
					  unsigned char red_band,
					  unsigned char green_band,
					  unsigned char blue_band,
					  unsigned char compression,
					  unsigned int tile_sz)
{
................................................................................
	       no_data) != RL2_OK)
	      goto error;
      }

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, RL2_PIXEL_RGB,
					       3, NULL, compression, 1, tile_sz,
					       srid, minx, miny, maxx, maxy,
					       xx_res, yy_res);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
							 double y_res,
							 double minx,
							 double miny,
							 double maxx,
							 double maxy,
							 unsigned int width,
							 unsigned int height,
							 unsigned char red_band,

							 unsigned char
							 green_band,
							 unsigned char
							 blue_band,
							 unsigned char
							 compression,
							 unsigned int tile_sz)
................................................................................
						     compression, tile_sz);
}

static int
export_mono_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
					const char *dst_path,
					rl2CoveragePtr cvg,
					sqlite3_int64 section_id, double x_res,

					double y_res, double minx, double miny,
					double maxx, double maxy,
					unsigned int width, unsigned int height,
					unsigned char mono_band,
					unsigned char compression,
					unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW - common implementation */
    rl2RasterPtr raster = NULL;
    rl2PixelPtr no_data_multi = NULL;
................................................................................
	out_pixel = RL2_PIXEL_DATAGRID;
    else
	out_pixel = RL2_PIXEL_GRAYSCALE;

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, out_pixel,
					       1, NULL, compression, 1, tile_sz,
					       srid, minx, miny, maxx, maxy,
					       xx_res, yy_res);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       out_pixel, 1, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);

		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					       unsigned int width,
					       unsigned int height,
					       unsigned char mono_band,
					       unsigned char compression,
					       unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW from the DBMS into the file-system */
    return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg, 0,
						   x_res, y_res, minx, miny,
						   maxx, maxy, width, height,
						   mono_band, compression,
						   tile_sz);
}

RL2_DECLARE int
rl2_export_section_mono_band_tiff_worldfile_from_dbms (sqlite3 * handle,
						       const char *dst_path,
						       rl2CoveragePtr cvg,
						       sqlite3_int64 section_id,

						       double x_res,
						       double y_res,
						       double minx, double miny,

						       double maxx, double maxy,

						       unsigned int width,
						       unsigned int height,
						       unsigned char mono_band,

						       unsigned char
						       compression,
						       unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW - Section */
    return export_mono_band_tiff_worldfile_common (1, handle, dst_path, cvg,
						   section_id, x_res, y_res,
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
				       unsigned char green_band,
				       unsigned char blue_band,
				       unsigned char compression,
				       unsigned int tile_sz)
{
/* exporting a plain Band-Composed TIFF from the DBMS into the file-system */
    return export_triple_band_tiff_common (0, handle, dst_path, cvg, 0, x_res,
					   y_res, minx, miny, maxx, maxy, width,
					   height, red_band, green_band,
					   blue_band, compression, tile_sz);

}

RL2_DECLARE int
rl2_export_section_triple_band_tiff_from_dbms (sqlite3 * handle,
					       const char *dst_path,
					       rl2CoveragePtr cvg,
					       sqlite3_int64 section_id,
................................................................................
					       unsigned char red_band,
					       unsigned char green_band,
					       unsigned char blue_band,
					       unsigned char compression,
					       unsigned int tile_sz)
{
/* exporting a plain Band-Composed TIFF - Section */
    return export_triple_band_tiff_common (1, handle, dst_path, cvg, section_id,
					   x_res, y_res, minx, miny, maxx, maxy,

					   width, height, red_band, green_band,
					   blue_band, compression, tile_sz);
}

static int
export_mono_band_tiff_common (int by_section, sqlite3 * handle,
			      const char *dst_path, rl2CoveragePtr cvg,
			      sqlite3_int64 section_id, double x_res,
			      double y_res, double minx, double miny,
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       out_pixel, 1, bufpix,
				       bufpix_size, NULL, NULL, 0, NULL);

		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					     unsigned char mono_band,
					     unsigned char compression,
					     unsigned int tile_sz)
{
/* exporting a plain Mono-Band TIFF from the DBMS - Section */
    return export_mono_band_tiff_common (1, handle, dst_path, cvg, section_id,
					 x_res, y_res, minx, miny, maxx, maxy,
					 width, height, mono_band, compression,
					 tile_sz);
}

static int
export_ascii_grid_common (int by_section, sqlite3 * handle, int max_threads,
			  const char *dst_path, rl2CoveragePtr cvg,
			  sqlite3_int64 section_id, double res, double minx,
			  double miny, double maxx, double maxy,
................................................................................
	    }
      }

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_DATAGRID) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_DATAGRID) != RL2_OK)
	      goto error;
      }

    ascii =
	rl2_create_ascii_grid_destination (dst_path, width, height,
					   xx_res, minx, miny, is_centered,
................................................................................
				 double res, double minx, double miny,
				 double maxx, double maxy, unsigned int width,
				 unsigned int height, int is_centered,
				 int decimal_digits)
{
/* exporting an ASCII Grid from the DBMS into the file-system */
    return export_ascii_grid_common (0, handle, max_threads, dst_path, cvg, 0,
				     res, minx, miny, maxx, maxy, width, height,
				     is_centered, decimal_digits);
}

RL2_DECLARE int
rl2_export_section_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
					 const char *dst_path,
					 rl2CoveragePtr cvg,
					 sqlite3_int64 section_id, double res,
					 double minx, double miny, double maxx,

					 double maxy, unsigned int width,
					 unsigned int height, int is_centered,
					 int decimal_digits)
{
/* exporting an ASCII Grid - Section */
    return export_ascii_grid_common (1, handle, max_threads, dst_path, cvg,
				     section_id, res, minx, miny, maxx, maxy,
				     width, height, is_centered,
................................................................................
	  if (match == no_data->nBands)
	      return 1;
      }
    return 0;
}

static float
compute_ndvi (void *pixels, unsigned char sample_type, unsigned char num_bands,

	      unsigned short width, unsigned char red_band,
	      unsigned char nir_band, unsigned short row, unsigned short col,
	      rl2PrivPixelPtr in_no_data, float out_no_data)
{
/* computing a Normalized Difference Vegetaion Index -NDVI */
    float red;
    float nir;
    unsigned char *p8;
    unsigned short *p16;
................................................................................

static int
export_ndvi_ascii_grid_common (int by_section, sqlite3 * handle,
			       int max_threads, const char *dst_path,
			       rl2CoveragePtr cvg, sqlite3_int64 section_id,
			       double res, double minx, double miny,
			       double maxx, double maxy, unsigned int width,
			       unsigned int height, int red_band, int nir_band,

			       int is_centered, int decimal_digits)
{
/* exporting an NDVI ASCII Grid common implementation */
    rl2PalettePtr palette = NULL;
    rl2PixelPtr in_no_data;
    rl2AsciiGridDestinationPtr ascii = NULL;
    unsigned char level;
    unsigned char scale;
................................................................................
    if (red_band == nir_band)
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_MULTIBAND) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_MULTIBAND) != RL2_OK)
	      goto error;
      }

/* creating the output NDVI raster */
    out_pixels_size = width * height * sizeof (float);
    out_pixels = malloc (out_pixels_size);
................................................................................
	goto error;
    po = (float *) out_pixels;
    for (row = 0; row < height; row++)
      {
	  /* computing NDVI */
	  for (col = 0; col < width; col++)
	      *po++ =
		  compute_ndvi (pixels, sample_type, num_bands, width, red_band,
				nir_band, row, col,
				(rl2PrivPixelPtr) in_no_data, out_no_data);
      }
    free (pixels);
    pixels = NULL;

    ascii =
	rl2_create_ascii_grid_destination (dst_path, width, height,
................................................................................
    if (palette != NULL)
	rl2_destroy_palette (palette);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
				      const char *dst_path, rl2CoveragePtr cvg,

				      double res, double minx, double miny,
				      double maxx, double maxy,
				      unsigned int width, unsigned int height,
				      int red_band, int nir_band,
				      int is_centered, int decimal_digits)
{
/* exporting an ASCII Grid from the DBMS into the file-system */
    return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path, cvg,
					  0, res, minx, miny, maxx, maxy, width,
					  height, red_band, nir_band,
					  is_centered, decimal_digits);
}

RL2_DECLARE int
rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,

					      const char *dst_path,
					      rl2CoveragePtr cvg,
					      sqlite3_int64 section_id,
					      double res, double minx,
					      double miny, double maxx,
					      double maxy, unsigned int width,
					      unsigned int height, int red_band,

					      int nir_band, int is_centered,
					      int decimal_digits)
{
/* exporting an ASCII Grid - Section */
    return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path, cvg,
					  section_id, res, minx, miny, maxx,
					  maxy, width, height, red_band,
					  nir_band, is_centered,
					  decimal_digits);
}

static int
export_jpeg_common (int by_section, sqlite3 * handle, int max_threads,
		    const char *dst_path, rl2CoveragePtr cvg,
................................................................................
    else
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }

    raster =
	rl2_create_raster (width, height, sample_type, pixel_type, num_bands,
			   outbuf, outbuf_size, NULL, NULL, 0, NULL);
................................................................................
	free (outbuf);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_jpeg_from_dbms (sqlite3 * handle, int max_threads,
			   const char *dst_path, rl2CoveragePtr cvg,
			   double x_res, double y_res, double minx, double miny,
			   double maxx, double maxy, unsigned int width,

			   unsigned int height, int quality, int with_worldfile)
{
/* exporting a JPEG (with possible JGW) from the DBMS into the file-system */
    return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0, x_res,
			       y_res, minx, miny, maxx, maxy, width, height,
			       quality, with_worldfile);
}

RL2_DECLARE int
rl2_export_section_jpeg_from_dbms (sqlite3 * handle, int max_threads,
				   const char *dst_path, rl2CoveragePtr cvg,
				   sqlite3_int64 section_id, double x_res,
				   double y_res, double minx, double miny,
				   double maxx, double maxy, unsigned int width,
				   unsigned int height, int quality,
				   int with_worldfile)
{
/* exporting a JPEG (with possible JGW) - Section */
    return export_jpeg_common (1, handle, max_threads, dst_path, cvg,
			       section_id, x_res, y_res, minx, miny, maxx, maxy,
			       width, height, quality, with_worldfile);
}

static int
export_raw_pixels_common (int by_section, sqlite3 * handle, int max_threads,
			  rl2CoveragePtr cvg, sqlite3_int64 section_id,
			  double x_res, double y_res, double minx, double miny,
			  double maxx, double maxy, unsigned int width,
			  unsigned int height, int big_endian,
			  unsigned char **blob, int *blob_size)
{
/* common implementation for Export RAW pixels */
    unsigned char level;
    unsigned char scale;
    double xx_res = x_res;
    double yy_res = y_res;
    unsigned char sample_type;
................................................................................
	RL2_OK)
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx, miny,
	       maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy,
	       xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    bufpix =
	rl2_copy_endian_raw_pixels (outbuf, outbuf_size, width, height,
				    sample_type, num_bands, big_endian);
    if (bufpix == NULL)
................................................................................
				 double y_res, double minx, double miny,
				 double maxx, double maxy,
				 unsigned int width,
				 unsigned int height, int big_endian,
				 unsigned char **blob, int *blob_size)
{
/* exporting RAW pixel buffer and Transparency Mask from the DBMS */
    return export_raw_pixels_common (0, handle, max_threads, coverage, 0, x_res,
				     y_res, minx, miny, maxx, maxy, width,
				     height, big_endian, blob, blob_size);

}

RL2_DECLARE int
rl2_export_section_raw_pixels_from_dbms (sqlite3 * handle, int max_threads,
					 rl2CoveragePtr coverage,
					 sqlite3_int64 section_id,
					 double x_res, double y_res,
................................................................................
					 unsigned int width,
					 unsigned int height,
					 int big_endian,
					 unsigned char **blob, int *blob_size)
{
/* exporting RAW pixel buffer and Transparency Mask - Section */
    return export_raw_pixels_common (1, handle, max_threads, coverage,
				     section_id, x_res, y_res, minx, miny, maxx,
				     maxy, width, height, big_endian, blob,
				     blob_size);
}

RL2_DECLARE int
rl2_load_raw_raster_into_dbms (sqlite3 * handle, int max_threads,
			       rl2CoveragePtr cvg, const char *section,
			       rl2RasterPtr rst, int pyramidize)
{
................................................................................
    return RL2_OK;

  error:
    if (aux != NULL)
	destroyAuxImporter (aux);
    if (thread_slots != NULL)
	free (thread_slots);
    if (stmt_upd_sect != NULL)
	sqlite3_finalize (stmt_upd_sect);
    if (stmt_sect != NULL)
	sqlite3_finalize (stmt_sect);
    if (stmt_levl != NULL)
	sqlite3_finalize (stmt_levl);
    if (stmt_tils != NULL)
	sqlite3_finalize (stmt_tils);
    if (stmt_data != NULL)
	sqlite3_finalize (stmt_data);
    return RL2_ERROR;
}







































































































































































































































































































































































































|
|







 







|
>
|






>
|






|
>
|







|
>
|







 







|
|
>
>
>
>






|







 







|
|







 







|
|







 







>
|







 







|
|







 







|
|







 







|
|
>
>
>
>






|







 







|
|







 







|
|
|
|







 







>
>
|
>
>






|







 







|
|







 







|
|
>





|
|
|







 







>
>
|
>
>






|







 







>
>
>
>
>
>
>
>
>
>







|
|








|
|







 







|
|
>
|
|
|
|
>
|
|







 







|
|
|
|







 







|
|
|
<
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>







 







|
|
|
|
<
|







 







|
>
|
|
|











|
|







 







|
|








|
|
|





|
|
|
|
|







 







|
|
|






|
|







 







|
|

|
|







 







|
>







 







|
|
|






|
|







 







|
|
|
>







 







|
|

|
|







 







|
|
>



|
>







 







|
|







 







|
|
|






|
|







 







|
|

|
|







 







|
|
|
|


|
|
|







|
|





|
|





|
>
|
|







 







|
|







 







|



|
|







 







|
|







 







|


|
<
|
>







 







|
|
|







 







|
>
|







 







|
|
|







 







|



|
|







 







|
>







 







|
>
|
|
|







 







|
|
|







 







|


|
<
|
>







 







|
|
|
|
|






|
>


|
>
|
>


|
>







 







|



|
|







 







|
|
|
>







 







|
|
>
|
|







 







|


|
<
|
>







 







|
|







 







|
|







|
|







 







|
|







|
>
|







 







|
>
|
|







 







|
>
|







 







|
|







|
|







 







|
|







 







|
>
|
|
|
|
|


|
|
|




|
>






|
>
|



|
|
|







 







|
|







|
|







 







|
|
>
|


|
|
|







|
|
|



|
|





|
|
|
|







 







|
|







|
|







 







|
|
|
>







 







|
|
|







 



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
...
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
...
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
....
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
....
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
....
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
....
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
....
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
....
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
....
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
....
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
....
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
....
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
....
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
....
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
....
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937

2938
2939
2940
2941
2942
2943
2944
2945
....
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
....
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023

3024
3025
3026
3027
3028
3029
3030
3031
....
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
....
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
....
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
....
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
....
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
....
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
....
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
....
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
....
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
....
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
....
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
....
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
....
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
....
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
....
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
....
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
....
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179

4180
4181
4182
4183
4184
4185
4186
4187
4188
....
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
....
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
....
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
....
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
....
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
....
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
....
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
....
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581

4582
4583
4584
4585
4586
4587
4588
4589
4590
....
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
....
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
....
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
....
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
....
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956

4957
4958
4959
4960
4961
4962
4963
4964
4965
....
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
....
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
....
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
....
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
....
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
....
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
....
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
....
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
....
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
....
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
....
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
....
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
....
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
....
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
    tile->blob_odd = NULL;
    tile->blob_even = NULL;
    rl2_destroy_raster (tile->raster);
    tile->raster = NULL;
}

static void
addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row,
		     unsigned int col, double minx, double maxy)
{
/* adding a Tile to some AuxImporter container */
    rl2AuxImporterTilePtr tile;
    if (aux == NULL)
	return;

    tile = malloc (sizeof (rl2AuxImporterTile));
................................................................................
    switch (aux->origin_type)
      {
      case RL2_ORIGIN_ASCII_GRID:
	  ascii_grid_origin = (rl2AsciiGridOriginPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_ascii_grid_origin ((rl2CoveragePtr)
						   (aux->coverage),
						   ascii_grid_origin,
						   tile->row, tile->col,
						   aux->verbose);
	  break;
      case RL2_ORIGIN_JPEG:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_jpeg_origin ((rl2CoveragePtr) (aux->coverage),
					     raster_origin, tile->row,
					     tile->col,
					     aux->forced_conversion,
					     aux->verbose);
	  break;
      case RL2_ORIGIN_JPEG2000:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_jpeg2000_origin ((rl2CoveragePtr)
						 (aux->coverage),
						 raster_origin, tile->row,
						 tile->col,
						 aux->forced_conversion,
						 aux->verbose);
	  break;
      case RL2_ORIGIN_TIFF:
	  tiff_origin = (rl2TiffOriginPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_tiff_origin ((rl2CoveragePtr) (aux->coverage),
					     tiff_origin, tile->row,
					     tile->col, aux->srid,
					     aux->verbose);
	  break;
      case RL2_ORIGIN_RAW:
	  raster_origin = (rl2RasterPtr) (aux->origin);
	  tile->raster =
	      rl2_get_tile_from_raw_pixels ((rl2CoveragePtr) (aux->coverage),
					    raster_origin, tile->row,
					    tile->col);
................................................................................
      }
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */ double x_diff =
	      fabs (coverage->hResolution - res_x);
	  double y_diff = fabs (coverage->vResolution - res_y);
	  double x_lim = coverage->hResolution / 1000000.0;
	  double y_lim = coverage->vResolution / 1000000.0;
	  if (x_diff > x_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (y_diff > y_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	  fprintf (stderr, "Coverage/ASCII mismatch\n");
	  goto error;
      }
    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx,
	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, 1);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
	      (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl))
	      goto error;
      }

/* preparing all Tile Requests */
    aux =
	createAuxImporter (coverage, srid, maxx, miny, tile_w, tile_h, res_x,
			   res_y, RL2_ORIGIN_ASCII_GRID, origin,
			   RL2_CONVERT_NO, verbose, compression, 100);
    tile_maxy = maxy;
    for (row = 0; row < height; row += tile_h)
      {
	  tile_minx = minx;
	  for (col = 0; col < width; col += tile_w)
	    {
		/* adding a Tile request */
................................................................................
}

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */

static int
check_jpeg2000_origin_compatibility (rl2RasterPtr raster,
				     rl2CoveragePtr coverage,
				     unsigned int *width,
				     unsigned int *height,
				     unsigned char *forced_conversion)
{
/* checking if the Jpeg2000 and the Coverage are mutually compatible */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
    rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage;
    if (rst == NULL || cvg == NULL)
	return 0;
................................................................................
	    {
		*width = rst->width;
		*height = rst->height;
		*forced_conversion = RL2_CONVERT_NO;
		return 1;
	    }
      }
    if (rst->sampleType == RL2_SAMPLE_UINT16
	&& rst->pixelType == RL2_PIXEL_RGB && rst->nBands == 3)
      {
	  if (cvg->sampleType == RL2_SAMPLE_UINT16
	      && cvg->pixelType == RL2_PIXEL_RGB && cvg->nBands == 3)
	    {
		*width = rst->width;
		*height = rst->height;
		*forced_conversion = RL2_CONVERT_NO;
................................................................................
	  maxy = height - 1.0;
	  res_x = 1.0;
	  res_y = 1.0;
      }
    raster_in = (rl2PrivRasterPtr) rst_in;
    xml_summary =
	rl2_build_jpeg_xml_summary (width, height, raster_in->pixelType,
				    is_georeferenced, res_x, res_y, minx,
				    miny, maxx, maxy);

    printf ("------------------\n");
    if (total > 1)
	printf ("%d/%d) Importing: %s\n", current, total, src_path);
    else
	printf ("Importing: %s\n", src_path);
    printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
      }
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */ double x_diff =
	      fabs (coverage->hResolution - res_x);
	  double y_diff = fabs (coverage->vResolution - res_y);
	  double x_lim = coverage->hResolution / 1000000.0;
	  double y_lim = coverage->vResolution / 1000000.0;
	  if (x_diff > x_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (y_diff > y_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	    }
      }

    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx,
	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
	  maxy = height - 1.0;
	  res_x = 1.0;
	  res_y = 1.0;
      }
    raster_in = (rl2PrivRasterPtr) rst_in;
    xml_summary =
	rl2_build_jpeg2000_xml_summary (width, height, raster_in->sampleType,
					raster_in->pixelType,
					raster_in->nBands, is_georeferenced,
					res_x, res_y, minx, miny, maxx, maxy,
					tile_width, tile_height);

    printf ("------------------\n");
    if (total > 1)
	printf ("%d/%d) Importing: %s\n", current, total, src_path);
    else
	printf ("Importing: %s\n", src_path);
    printf ("    Image Size (pixels): %d x %d\n", width, height);
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */
	  double x_diff = fabs (coverage->hResolution - res_x);
	  double y_diff = fabs (coverage->vResolution - res_y);
	  double x_lim = coverage->hResolution / 1000000.0;
	  double y_lim = coverage->vResolution / 1000000.0;
	  if (x_diff > x_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (y_diff > y_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
	    }
      }

    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx,
	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
    rl2AuxImporterTilePtr *thread_slots = NULL;
    int thread_count;

    if (is_ascii_grid (src_path))
	return do_import_ascii_grid (handle, max_threads, src_path, cvg,
				     section, force_srid, tile_w, tile_h,
				     pyramidize, sample_type, compression,
				     stmt_data, stmt_tils, stmt_sect,
				     stmt_levl, stmt_upd_sect, verbose,
				     current, total);

    if (is_jpeg_image (src_path))
	return do_import_jpeg_image (handle, max_threads, src_path, cvg,
				     section, force_srid, tile_w, tile_h,
				     pyramidize, sample_type, num_bands,
				     compression, quality, stmt_data,
				     stmt_tils, stmt_sect, stmt_levl,
				     stmt_upd_sect, verbose, current, total);

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */
    if (is_jpeg2000_image (src_path))
	return do_import_jpeg2000_image (handle, max_threads, src_path, cvg,
					 section, force_srid, tile_w, tile_h,
					 pyramidize, sample_type, num_bands,
					 compression, quality, stmt_data,
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */
	  double x_diff = fabs (coverage->hResolution - res_x);
	  double y_diff = fabs (coverage->vResolution - res_y);
	  double x_lim = coverage->hResolution / 1000000.0;
	  double y_lim = coverage->vResolution / 1000000.0;
	  if (x_diff > x_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		goto error;
	    }
	  if (y_diff > y_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		goto error;
	    }
      }
................................................................................
		goto error;
	    }
      }

    if (pixel_type == RL2_PIXEL_PALETTE)
      {
	  /* remapping the Palette */
	  if (do_check_initial_palette (handle, cvg) == RL2_TRUE)
	    {
		if (rl2_install_dbms_palette_from_tiff (handle, cvg, origin) !=
		    RL2_OK)
		  {
		      fprintf (stderr,
			       "Unable to install the initial Palette !!!\n");
		      goto error;
		  }
	    }
	  if (rl2_check_dbms_palette (handle, cvg, origin) != RL2_OK)
	    {
		fprintf (stderr, "Mismatching Palette !!!\n");
		goto error;
	    }
      }

    if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose)
	!= RL2_TRUE)
      {
	  fprintf (stderr, "Coverage/TIFF mismatch\n");
	  goto error;
      }
    no_data = rl2_get_coverage_no_data (cvg);

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, src_path, section, srid, width, height, minx, miny, maxx,
	 maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5,
	 coverage->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (coverage->mixedResolutions)
................................................................................
		      if ((c_file.attrib & _A_RDONLY) == _A_RDONLY
			  || (c_file.attrib & _A_NORMAL) == _A_NORMAL)
			{
			    path =
				sqlite3_mprintf ("%s/%s", dir_path,
						 c_file.name);
			    ret =
				do_import_file (handle, max_threads, path,
						cvg, section, worldfile,
						force_srid, pyramidize,
						sample_type, pixel_type,
						num_bands, tile_w, tile_h,
						compression, quality,
						stmt_data, stmt_tils,
						stmt_sect, stmt_levl,
						stmt_upd_sect, verbose,
						cnt + 1, total);
			    sqlite3_free (path);
			    if (!ret)
				goto error;
			    cnt++;
			}
		      if (_findnext (hFile, &c_file) != 0)
			  break;
................................................................................
	       stmt_sect, stmt_levl, stmt_upd_sect, verbose, -1, -1))
	      goto error;
      }
    else
      {
	  /* importing all Image files from a whole directory */
	  if (!do_import_dir
	      (handle, max_threads, dir_path, file_ext, cvg, section,
	       worldfile, force_srid, pyramidize, sample_type, pixel_type,
	       num_bands, tile_w, tile_h, compression, quality, stmt_data,
	       stmt_tils, stmt_sect, stmt_levl, stmt_upd_sect, verbose))
	      goto error;
      }

    sqlite3_finalize (stmt_upd_sect);
    sqlite3_finalize (stmt_sect);
    sqlite3_finalize (stmt_levl);
    sqlite3_finalize (stmt_tils);
................................................................................
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_uint8_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
			   unsigned char pixel_type, unsigned char num_bands,
			   unsigned int width, unsigned int height,
			   unsigned int tile_width, unsigned int tile_height,

			   unsigned int base_y, unsigned int base_x)
{
/* copying UINT8 pixels from the output buffer into the tile */
    unsigned int x;
    unsigned int y;
    int b;
    const unsigned char *p_in;
    unsigned char *p_out = tile;
................................................................................
	    {
		if ((base_x + x) >= width)
		  {
		      p_out += num_bands;
		      p_in += num_bands;
		      continue;
		  }
		if (pixel_type == RL2_PIXEL_MONOCHROME)
		  {
		      unsigned char pxl = *p_in++;
		      if (pxl == 0)
			  *p_out++ = 1;
		      else
			  *p_out++ = 0;
		  }
		else if (pixel_type == RL2_PIXEL_PALETTE)
		  {
		      unsigned char pxl = *p_in++;
		      if (pxl == 0)
			  *p_out++ = 1;
		      else
			  *p_out++ = 0;
		  }
		else
		  {
		      for (b = 0; b < num_bands; b++)
			  *p_out++ = *p_in++;
		  }
	    }
      }
}

static void
copy_int16_outbuf_to_tile (const short *outbuf, short *tile,
			   unsigned int width,
................................................................................
		  }
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_uint16_outbuf_to_tile (const unsigned short *outbuf,
			    unsigned short *tile, unsigned char num_bands,
			    unsigned int width, unsigned int height,
			    unsigned int tile_width, unsigned int tile_height,

			    unsigned int base_y, unsigned int base_x)
{
/* copying UINT16 pixels from the output buffer into the tile */
    unsigned int x;
    unsigned int y;
    int b;
    const unsigned short *p_in;
    unsigned short *p_out = tile;
................................................................................
		*p_out++ = *p_in++;
	    }
      }
}

static void
copy_from_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile,
			  unsigned char sample_type, unsigned char pixel_type,
			  unsigned char num_bands, unsigned int width,
			  unsigned int height, unsigned int tile_width,
			  unsigned int tile_height, unsigned int base_y,
			  unsigned int base_x)
{
/* copying pixels from the output buffer into the tile */
    switch (sample_type)
      {
      case RL2_SAMPLE_INT8:
	  copy_int8_outbuf_to_tile ((char *) outbuf,
				    (char *) tile, width, height, tile_width,
				    tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_int16_outbuf_to_tile ((short *) outbuf,
				     (short *) tile, width, height,
				     tile_width, tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_UINT16:
	  copy_uint16_outbuf_to_tile ((unsigned short *) outbuf,
				      (unsigned short *) tile, num_bands,
				      width, height, tile_width, tile_height,
				      base_y, base_x);
	  break;
................................................................................
      case RL2_SAMPLE_UINT32:
	  copy_uint32_outbuf_to_tile ((unsigned int *) outbuf,
				      (unsigned int *) tile, width, height,
				      tile_width, tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_float_outbuf_to_tile ((float *) outbuf,
				     (float *) tile, width, height,
				     tile_width, tile_height, base_y, base_x);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_double_outbuf_to_tile ((double *) outbuf,
				      (double *) tile, width, height,
				      tile_width, tile_height, base_y, base_x);
	  break;
      default:
	  copy_uint8_outbuf_to_tile ((unsigned char *) outbuf,
				     (unsigned char *) tile, pixel_type,
				     num_bands, width, height, tile_width,
				     tile_height, base_y, base_x);
	  break;
      };
}

static int
export_geotiff_common (sqlite3 * handle, int max_threads,
		       const char *dst_path, rl2CoveragePtr cvg,
		       int by_section, sqlite3_int64 section_id, double x_res,
		       double y_res, double minx, double miny, double maxx,
		       double maxy, unsigned int width, unsigned int height,
		       unsigned char compression, unsigned int tile_sz,
		       int with_worldfile)
{
/* exporting a GeoTIFF common implementation */
    rl2RasterPtr raster = NULL;
    rl2PalettePtr palette = NULL;
    rl2PalettePtr plt2 = NULL;
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
	       &palette, pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
					 sample_type, num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, num_bands, width, height,
					  tile_sz, tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
    return export_geotiff_common (handle, max_threads, dst_path, cvg, 0, 0,
				  x_res, y_res, minx, miny, maxx, maxy, width,
				  height, compression, tile_sz, with_worldfile);
}

RL2_DECLARE int
rl2_export_section_geotiff_from_dbms (sqlite3 * handle, int max_threads,
				      const char *dst_path,
				      rl2CoveragePtr cvg,
				      sqlite3_int64 section_id, double x_res,
				      double y_res, double minx, double miny,
				      double maxx, double maxy,
				      unsigned int width, unsigned int height,
				      unsigned char compression,
				      unsigned int tile_sz, int with_worldfile)
{
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single select Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
	       &palette, pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
	  pix_sz = 8;
	  break;
      };

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, pixel_type,
					       num_bands, palette,
					       compression, 1, tile_sz, srid,
					       minx, miny, maxx, maxy, xx_res,
					       yy_res);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
					 sample_type, num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, num_bands, width, height,
					  tile_sz, tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
				     double miny, double maxx, double maxy,
				     unsigned int width, unsigned int height,
				     unsigned char compression,
				     unsigned int tile_sz)
{
/* exporting a TIFF+TFW from the DBMS into the file-system */
    return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 0,
					0, x_res, y_res, minx, miny, maxx,
					maxy, width, height, compression,
					tile_sz);
}

RL2_DECLARE int
rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle,
					     int max_threads,
					     const char *dst_path,
					     rl2CoveragePtr cvg,
					     sqlite3_int64 section_id,
					     double x_res, double y_res,
					     double minx, double miny,
					     double maxx, double maxy,
					     unsigned int width,
................................................................................
					     unsigned int height,
					     unsigned char compression,
					     unsigned int tile_sz)
{
/* exporting a TIFF+TFW - single Section */
    return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 1,
					section_id, x_res, y_res, minx, miny,
					maxx, maxy, width, height,
					compression, tile_sz);
}

static int
export_tiff_common (sqlite3 * handle, int max_threads, const char *dst_path,
		    rl2CoveragePtr cvg, int by_section,
		    sqlite3_int64 section_id, double x_res, double y_res,
		    double minx, double miny, double maxx, double maxy,
................................................................................
	    }
      }

    if (by_section)
      {
	  /* just a single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size,
	       &palette, pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette,
	       pixel_type) != RL2_OK)
	      goto error;
      }

/* computing the sample size */
    switch (sample_type)
      {
................................................................................
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL)
		    rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_sz, tile_sz,
					 sample_type, num_bands, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, num_bands, width, height,
					  tile_sz, tile_sz, base_y, base_x);
		plt2 = rl2_clone_palette (palette);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       pixel_type, num_bands, bufpix,
				       bufpix_size, plt2, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
................................................................................
	rl2_destroy_palette (palette);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_tiff_from_dbms (sqlite3 * handle, int max_threads,
			   const char *dst_path, rl2CoveragePtr cvg,
			   double x_res, double y_res, double minx,
			   double miny, double maxx, double maxy,
			   unsigned int width, unsigned int height,
			   unsigned char compression, unsigned int tile_sz)
{
/* exporting a plain TIFF from the DBMS into the file-system */
    return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0,
			       x_res, y_res, minx, miny, maxx, maxy, width,
			       height, compression, tile_sz);
}

RL2_DECLARE int
rl2_export_section_tiff_from_dbms (sqlite3 * handle, int max_threads,
				   const char *dst_path, rl2CoveragePtr cvg,
				   sqlite3_int64 section_id, double x_res,
				   double y_res, double minx, double miny,
				   double maxx, double maxy,
				   unsigned int width, unsigned int height,
				   unsigned char compression,
				   unsigned int tile_sz)
{
/* exporting a plain TIFF - single Section*/
    return export_tiff_common (handle, max_threads, dst_path, cvg, 1,
			       section_id, x_res, y_res, minx, miny, maxx,
			       maxy, width, height, compression, tile_sz);
}

static int
export_triple_band_geotiff_common (int by_section, sqlite3 * handle,
				   const char *dst_path,
				   rl2CoveragePtr cvg,
				   sqlite3_int64 section_id, double x_res,
				   double y_res, double minx, double miny,
				   double maxx, double maxy,
				   unsigned int width, unsigned int height,
				   unsigned char red_band,
				   unsigned char green_band,
				   unsigned char blue_band,
				   unsigned char compression,
				   unsigned int tile_sz, int with_worldfile)
{
................................................................................
	      goto error;
      }

    tiff =
	rl2_create_geotiff_destination (dst_path, handle, width, height,
					sample_type, RL2_PIXEL_RGB, 3,
					NULL, compression, 1, tile_sz, srid,
					minx, miny, maxx, maxy, xx_res,
					yy_res, with_worldfile);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
				       NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
    else
	out_pixel = RL2_PIXEL_GRAYSCALE;

    tiff =
	rl2_create_geotiff_destination (dst_path, handle, width, height,
					sample_type, out_pixel, 1,
					NULL, compression, 1, tile_sz, srid,
					minx, miny, maxx, maxy, xx_res,
					yy_res, with_worldfile);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,

				       1, bufpix, bufpix_size, NULL, NULL, 0,
				       NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					unsigned int height,
					unsigned char mono_band,
					unsigned char compression,
					unsigned int tile_sz,
					int with_worldfile)
{
/* exporting a Mono-Band GeoTIFF from the DBMS into the file-system */
    return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0,
					    x_res, y_res, minx, miny, maxx,
					    maxy, width, height, mono_band,
					    compression, tile_sz,
					    with_worldfile);
}

RL2_DECLARE int
rl2_export_section_mono_band_geotiff_from_dbms (sqlite3 * handle,
						const char *dst_path,
................................................................................

static int
export_triple_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
					  const char *dst_path,
					  rl2CoveragePtr cvg,
					  sqlite3_int64 section_id,
					  double x_res, double y_res,
					  double minx, double miny,
					  double maxx, double maxy,
					  unsigned int width,
					  unsigned int height,
					  unsigned char red_band,
					  unsigned char green_band,
					  unsigned char blue_band,
					  unsigned char compression,
					  unsigned int tile_sz)
{
................................................................................
	       no_data) != RL2_OK)
	      goto error;
      }

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, RL2_PIXEL_RGB,
					       3, NULL, compression, 1,
					       tile_sz, srid, minx, miny,
					       maxx, maxy, xx_res, yy_res);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
				       NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
							 double y_res,
							 double minx,
							 double miny,
							 double maxx,
							 double maxy,
							 unsigned int width,
							 unsigned int height,
							 unsigned char
							 red_band,
							 unsigned char
							 green_band,
							 unsigned char
							 blue_band,
							 unsigned char
							 compression,
							 unsigned int tile_sz)
................................................................................
						     compression, tile_sz);
}

static int
export_mono_band_tiff_worldfile_common (int by_section, sqlite3 * handle,
					const char *dst_path,
					rl2CoveragePtr cvg,
					sqlite3_int64 section_id,
					double x_res, double y_res,
					double minx, double miny, double maxx,
					double maxy, unsigned int width,
					unsigned int height,
					unsigned char mono_band,
					unsigned char compression,
					unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW - common implementation */
    rl2RasterPtr raster = NULL;
    rl2PixelPtr no_data_multi = NULL;
................................................................................
	out_pixel = RL2_PIXEL_DATAGRID;
    else
	out_pixel = RL2_PIXEL_GRAYSCALE;

    tiff =
	rl2_create_tiff_worldfile_destination (dst_path, width, height,
					       sample_type, out_pixel,
					       1, NULL, compression, 1,
					       tile_sz, srid, minx, miny,
					       maxx, maxy, xx_res, yy_res);
    if (tiff == NULL)
	goto error;
    for (base_y = 0; base_y < height; base_y += tile_sz)
      {
	  for (base_x = 0; base_x < width; base_x += tile_sz)
	    {
		/* exporting all tiles from the output buffer */
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,

				       1, bufpix, bufpix_size, NULL, NULL, 0,
				       NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					       unsigned int width,
					       unsigned int height,
					       unsigned char mono_band,
					       unsigned char compression,
					       unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW from the DBMS into the file-system */
    return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg,
						   0, x_res, y_res, minx,
						   miny, maxx, maxy, width,
						   height, mono_band,
						   compression, tile_sz);
}

RL2_DECLARE int
rl2_export_section_mono_band_tiff_worldfile_from_dbms (sqlite3 * handle,
						       const char *dst_path,
						       rl2CoveragePtr cvg,
						       sqlite3_int64
						       section_id,
						       double x_res,
						       double y_res,
						       double minx,
						       double miny,
						       double maxx,
						       double maxy,
						       unsigned int width,
						       unsigned int height,
						       unsigned char
						       mono_band,
						       unsigned char
						       compression,
						       unsigned int tile_sz)
{
/* exporting a Mono-Band TIFF+TFW - Section */
    return export_mono_band_tiff_worldfile_common (1, handle, dst_path, cvg,
						   section_id, x_res, y_res,
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     3, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 3, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type,
				       RL2_PIXEL_RGB, 3, bufpix, bufpix_size,
				       NULL, NULL, 0, NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
				       unsigned char green_band,
				       unsigned char blue_band,
				       unsigned char compression,
				       unsigned int tile_sz)
{
/* exporting a plain Band-Composed TIFF from the DBMS into the file-system */
    return export_triple_band_tiff_common (0, handle, dst_path, cvg, 0, x_res,
					   y_res, minx, miny, maxx, maxy,
					   width, height, red_band,
					   green_band, blue_band, compression,
					   tile_sz);
}

RL2_DECLARE int
rl2_export_section_triple_band_tiff_from_dbms (sqlite3 * handle,
					       const char *dst_path,
					       rl2CoveragePtr cvg,
					       sqlite3_int64 section_id,
................................................................................
					       unsigned char red_band,
					       unsigned char green_band,
					       unsigned char blue_band,
					       unsigned char compression,
					       unsigned int tile_sz)
{
/* exporting a plain Band-Composed TIFF - Section */
    return export_triple_band_tiff_common (1, handle, dst_path, cvg,
					   section_id, x_res, y_res, minx,
					   miny, maxx, maxy, width, height,
					   red_band, green_band, blue_band,
					   compression, tile_sz);
}

static int
export_mono_band_tiff_common (int by_section, sqlite3 * handle,
			      const char *dst_path, rl2CoveragePtr cvg,
			      sqlite3_int64 section_id, double x_res,
			      double y_res, double minx, double miny,
................................................................................
		      fprintf (stderr,
			       "rl2tool Export: Insufficient Memory !!!\n");
		      goto error;
		  }
		rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type,
				     1, no_data);
		copy_from_outbuf_to_tile (outbuf, bufpix, sample_type,
					  pixel_type, 1, width, height, tile_sz,
					  tile_sz, base_y, base_x);
		raster =
		    rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel,

				       1, bufpix, bufpix_size, NULL, NULL, 0,
				       NULL);
		bufpix = NULL;
		if (raster == NULL)
		    goto error;
		if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) !=
		    RL2_OK)
		    goto error;
		rl2_destroy_raster (raster);
................................................................................
					     unsigned char mono_band,
					     unsigned char compression,
					     unsigned int tile_sz)
{
/* exporting a plain Mono-Band TIFF from the DBMS - Section */
    return export_mono_band_tiff_common (1, handle, dst_path, cvg, section_id,
					 x_res, y_res, minx, miny, maxx, maxy,
					 width, height, mono_band,
					 compression, tile_sz);
}

static int
export_ascii_grid_common (int by_section, sqlite3 * handle, int max_threads,
			  const char *dst_path, rl2CoveragePtr cvg,
			  sqlite3_int64 section_id, double res, double minx,
			  double miny, double maxx, double maxy,
................................................................................
	    }
      }

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_DATAGRID) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_DATAGRID) != RL2_OK)
	      goto error;
      }

    ascii =
	rl2_create_ascii_grid_destination (dst_path, width, height,
					   xx_res, minx, miny, is_centered,
................................................................................
				 double res, double minx, double miny,
				 double maxx, double maxy, unsigned int width,
				 unsigned int height, int is_centered,
				 int decimal_digits)
{
/* exporting an ASCII Grid from the DBMS into the file-system */
    return export_ascii_grid_common (0, handle, max_threads, dst_path, cvg, 0,
				     res, minx, miny, maxx, maxy, width,
				     height, is_centered, decimal_digits);
}

RL2_DECLARE int
rl2_export_section_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
					 const char *dst_path,
					 rl2CoveragePtr cvg,
					 sqlite3_int64 section_id, double res,
					 double minx, double miny,
					 double maxx, double maxy,
					 unsigned int width,
					 unsigned int height, int is_centered,
					 int decimal_digits)
{
/* exporting an ASCII Grid - Section */
    return export_ascii_grid_common (1, handle, max_threads, dst_path, cvg,
				     section_id, res, minx, miny, maxx, maxy,
				     width, height, is_centered,
................................................................................
	  if (match == no_data->nBands)
	      return 1;
      }
    return 0;
}

static float
compute_ndvi (void *pixels, unsigned char sample_type,
	      unsigned char num_bands, unsigned short width,
	      unsigned char red_band, unsigned char nir_band,
	      unsigned short row, unsigned short col,
	      rl2PrivPixelPtr in_no_data, float out_no_data)
{
/* computing a Normalized Difference Vegetaion Index -NDVI */
    float red;
    float nir;
    unsigned char *p8;
    unsigned short *p16;
................................................................................

static int
export_ndvi_ascii_grid_common (int by_section, sqlite3 * handle,
			       int max_threads, const char *dst_path,
			       rl2CoveragePtr cvg, sqlite3_int64 section_id,
			       double res, double minx, double miny,
			       double maxx, double maxy, unsigned int width,
			       unsigned int height, int red_band,
			       int nir_band, int is_centered,
			       int decimal_digits)
{
/* exporting an NDVI ASCII Grid common implementation */
    rl2PalettePtr palette = NULL;
    rl2PixelPtr in_no_data;
    rl2AsciiGridDestinationPtr ascii = NULL;
    unsigned char level;
    unsigned char scale;
................................................................................
    if (red_band == nir_band)
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_MULTIBAND) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, res, res, &pixels, &pixels_size, &palette,
	       RL2_PIXEL_MULTIBAND) != RL2_OK)
	      goto error;
      }

/* creating the output NDVI raster */
    out_pixels_size = width * height * sizeof (float);
    out_pixels = malloc (out_pixels_size);
................................................................................
	goto error;
    po = (float *) out_pixels;
    for (row = 0; row < height; row++)
      {
	  /* computing NDVI */
	  for (col = 0; col < width; col++)
	      *po++ =
		  compute_ndvi (pixels, sample_type, num_bands, width,
				red_band, nir_band, row, col,
				(rl2PrivPixelPtr) in_no_data, out_no_data);
      }
    free (pixels);
    pixels = NULL;

    ascii =
	rl2_create_ascii_grid_destination (dst_path, width, height,
................................................................................
    if (palette != NULL)
	rl2_destroy_palette (palette);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads,
				      const char *dst_path,
				      rl2CoveragePtr cvg, double res,
				      double minx, double miny, double maxx,
				      double maxy, unsigned int width,
				      unsigned int height, int red_band,
				      int nir_band, int is_centered,
				      int decimal_digits)
{
/* exporting an ASCII Grid from the DBMS into the file-system */
    return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path,
					  cvg, 0, res, minx, miny, maxx, maxy,
					  width, height, red_band, nir_band,
					  is_centered, decimal_digits);
}

RL2_DECLARE int
rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle,
					      int max_threads,
					      const char *dst_path,
					      rl2CoveragePtr cvg,
					      sqlite3_int64 section_id,
					      double res, double minx,
					      double miny, double maxx,
					      double maxy, unsigned int width,
					      unsigned int height,
					      int red_band, int nir_band,
					      int is_centered,
					      int decimal_digits)
{
/* exporting an ASCII Grid - Section */
    return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path,
					  cvg, section_id, res, minx, miny,
					  maxx, maxy, width, height, red_band,
					  nir_band, is_centered,
					  decimal_digits);
}

static int
export_jpeg_common (int by_section, sqlite3 * handle, int max_threads,
		    const char *dst_path, rl2CoveragePtr cvg,
................................................................................
    else
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }

    raster =
	rl2_create_raster (width, height, sample_type, pixel_type, num_bands,
			   outbuf, outbuf_size, NULL, NULL, 0, NULL);
................................................................................
	free (outbuf);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_export_jpeg_from_dbms (sqlite3 * handle, int max_threads,
			   const char *dst_path, rl2CoveragePtr cvg,
			   double x_res, double y_res, double minx,
			   double miny, double maxx, double maxy,
			   unsigned int width, unsigned int height,
			   int quality, int with_worldfile)
{
/* exporting a JPEG (with possible JGW) from the DBMS into the file-system */
    return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0,
			       x_res, y_res, minx, miny, maxx, maxy, width,
			       height, quality, with_worldfile);
}

RL2_DECLARE int
rl2_export_section_jpeg_from_dbms (sqlite3 * handle, int max_threads,
				   const char *dst_path, rl2CoveragePtr cvg,
				   sqlite3_int64 section_id, double x_res,
				   double y_res, double minx, double miny,
				   double maxx, double maxy,
				   unsigned int width, unsigned int height,
				   int quality, int with_worldfile)
{
/* exporting a JPEG (with possible JGW) - Section */
    return export_jpeg_common (1, handle, max_threads, dst_path, cvg,
			       section_id, x_res, y_res, minx, miny, maxx,
			       maxy, width, height, quality, with_worldfile);
}

static int
export_raw_pixels_common (int by_section, sqlite3 * handle, int max_threads,
			  rl2CoveragePtr cvg, sqlite3_int64 section_id,
			  double x_res, double y_res, double minx,
			  double miny, double maxx, double maxy,
			  unsigned int width, unsigned int height,
			  int big_endian, unsigned char **blob, int *blob_size)
{
/* common implementation for Export RAW pixels */
    unsigned char level;
    unsigned char scale;
    double xx_res = x_res;
    double yy_res = y_res;
    unsigned char sample_type;
................................................................................
	RL2_OK)
	goto error;

    if (by_section)
      {
	  /* single Section */
	  if (rl2_get_section_raw_raster_data
	      (handle, max_threads, cvg, section_id, width, height, minx,
	       miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    else
      {
	  /* whole Coverage */
	  if (rl2_get_raw_raster_data
	      (handle, max_threads, cvg, width, height, minx, miny, maxx,
	       maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL,
	       pixel_type) != RL2_OK)
	      goto error;
      }
    bufpix =
	rl2_copy_endian_raw_pixels (outbuf, outbuf_size, width, height,
				    sample_type, num_bands, big_endian);
    if (bufpix == NULL)
................................................................................
				 double y_res, double minx, double miny,
				 double maxx, double maxy,
				 unsigned int width,
				 unsigned int height, int big_endian,
				 unsigned char **blob, int *blob_size)
{
/* exporting RAW pixel buffer and Transparency Mask from the DBMS */
    return export_raw_pixels_common (0, handle, max_threads, coverage, 0,
				     x_res, y_res, minx, miny, maxx, maxy,
				     width, height, big_endian, blob,
				     blob_size);
}

RL2_DECLARE int
rl2_export_section_raw_pixels_from_dbms (sqlite3 * handle, int max_threads,
					 rl2CoveragePtr coverage,
					 sqlite3_int64 section_id,
					 double x_res, double y_res,
................................................................................
					 unsigned int width,
					 unsigned int height,
					 int big_endian,
					 unsigned char **blob, int *blob_size)
{
/* exporting RAW pixel buffer and Transparency Mask - Section */
    return export_raw_pixels_common (1, handle, max_threads, coverage,
				     section_id, x_res, y_res, minx, miny,
				     maxx, maxy, width, height, big_endian,
				     blob, blob_size);
}

RL2_DECLARE int
rl2_load_raw_raster_into_dbms (sqlite3 * handle, int max_threads,
			       rl2CoveragePtr cvg, const char *section,
			       rl2RasterPtr rst, int pyramidize)
{
................................................................................
    return RL2_OK;

  error:
    if (aux != NULL)
	destroyAuxImporter (aux);
    if (thread_slots != NULL)
	free (thread_slots);
    if (stmt_upd_sect != NULL)
	sqlite3_finalize (stmt_upd_sect);
    if (stmt_sect != NULL)
	sqlite3_finalize (stmt_sect);
    if (stmt_levl != NULL)
	sqlite3_finalize (stmt_levl);
    if (stmt_tils != NULL)
	sqlite3_finalize (stmt_tils);
    if (stmt_data != NULL)
	sqlite3_finalize (stmt_data);
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_load_raw_tiles_into_dbms (sqlite3 * handle,
			      rl2CoveragePtr cvg, const char *section,
			      unsigned int sctn_width,
			      unsigned int sctn_height,
			      int sctn_srid,
			      double sctn_minx,
			      double sctn_miny,
			      double sctn_maxx,
			      double sctn_maxy,
			      int (*getTile) (void *data, double tile_minx,
					      double tile_miny,
					      double tile_maxx,
					      double tile_maxy,
					      unsigned char *bufpix,
					      rl2PalettePtr * palette),
			      void *data, int pyramidize)
{
/* callback-based IMPORT Raster function */
    rl2PrivCoveragePtr privcvg = (rl2PrivCoveragePtr) cvg;
    int ret;
    char *sql;
    const char *coverage;
    unsigned char sample_type;
    unsigned char pixel_type;
    unsigned char num_bands;
    unsigned int tile_w;
    unsigned int tile_h;
    unsigned char compression;
    int quality;
    char *table;
    char *xtable;
    unsigned int tileWidth;
    unsigned int tileHeight;
    unsigned int width = sctn_width;
    unsigned int height = sctn_height;
    int srid;
    double minx = sctn_minx;
    double miny = sctn_miny;
    double maxx = sctn_maxx;
    double maxy = sctn_maxy;
    double tile_minx;
    double tile_miny;
    double tile_maxx;
    double tile_maxy;
    rl2RasterStatisticsPtr section_stats = NULL;
    rl2PixelPtr no_data = NULL;
    rl2PalettePtr palette = NULL;
    rl2PalettePtr aux_palette = NULL;
    unsigned int row;
    unsigned int col;
    double res_x;
    double res_y;
    double hResolution;
    double vResolution;
    double base_res_x;
    double base_res_y;
    char *xml_summary = NULL;
    sqlite3_stmt *stmt_data = NULL;
    sqlite3_stmt *stmt_tils = NULL;
    sqlite3_stmt *stmt_sect = NULL;
    sqlite3_stmt *stmt_levl = NULL;
    sqlite3_stmt *stmt_upd_sect = NULL;
    sqlite3_int64 section_id;
    int pixel_size;
    int bufpix_sz;

    if (cvg == NULL)
	goto error;
    if (section == NULL)
	goto error;
    if (width == 0 || height == 0)
	goto error;
    if (minx >= maxx || miny >= maxy)
	goto error;
    hResolution = (sctn_maxx - sctn_minx) / (double) sctn_width;
    vResolution = (sctn_maxy - sctn_miny) / (double) sctn_height;

    if (rl2_get_coverage_tile_size (cvg, &tileWidth, &tileHeight) != RL2_OK)
	goto error;
    if (rl2_get_coverage_srid (cvg, &srid) != RL2_OK)
	goto error;
    if (srid != sctn_srid)
	goto error;
    srid = sctn_srid;

    tile_w = tileWidth;
    tile_h = tileHeight;
    rl2_get_coverage_compression (cvg, &compression, &quality);
    rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands);
    coverage = rl2_get_coverage_name (cvg);
    switch (sample_type)
      {
      case RL2_SAMPLE_INT16:
      case RL2_SAMPLE_UINT16:
	  pixel_size = 2;
	  break;
      case RL2_SAMPLE_INT32:
      case RL2_SAMPLE_UINT32:
      case RL2_SAMPLE_FLOAT:
	  pixel_size = 4;
	  break;
      case RL2_SAMPLE_DOUBLE:
	  pixel_size = 8;
	  break;
      default:
	  pixel_size = 1;
	  break;
      };
    pixel_size *= num_bands;
    bufpix_sz = tile_w * tile_h * pixel_size;

    table = sqlite3_mprintf ("%s_sections", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf
	("INSERT INTO \"%s\" (section_id, section_name, file_path, "
	 "md5_checksum, summary, width, height, geometry) "
	 "VALUES (NULL, ?, ?, ?, XB_Create(?), ?, ?, ?)", xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_sect, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("INSERT INTO sections SQL error: %s\n",
		  sqlite3_errmsg (handle));
	  goto error;
      }

    table = sqlite3_mprintf ("%s_sections", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf
	("UPDATE \"%s\" SET statistics = ? WHERE section_id = ?", xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_upd_sect, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("UPDATE sections SQL error: %s\n", sqlite3_errmsg (handle));
	  goto error;
      }

    if (privcvg->mixedResolutions)
      {
	  /* mixed resolutions Coverage */
	  table = sqlite3_mprintf ("%s_section_levels", coverage);
	  xtable = rl2_double_quoted_sql (table);
	  sqlite3_free (table);
	  sql =
	      sqlite3_mprintf
	      ("INSERT OR IGNORE INTO \"%s\" (section_id, pyramid_level, "
	       "x_resolution_1_1, y_resolution_1_1, "
	       "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, "
	       "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
	       "VALUES (?, 0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable);
	  free (xtable);
	  ret =
	      sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL);
	  sqlite3_free (sql);
	  if (ret != SQLITE_OK)
	    {
		printf ("INSERT INTO section_levels SQL error: %s\n",
			sqlite3_errmsg (handle));
		goto error;
	    }
      }
    else
      {
	  /* single resolution Coverage */
	  table = sqlite3_mprintf ("%s_levels", coverage);
	  xtable = rl2_double_quoted_sql (table);
	  sqlite3_free (table);
	  sql =
	      sqlite3_mprintf
	      ("INSERT OR IGNORE INTO \"%s\" (pyramid_level, "
	       "x_resolution_1_1, y_resolution_1_1, "
	       "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, "
	       "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) "
	       "VALUES (0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable);
	  free (xtable);
	  ret =
	      sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL);
	  sqlite3_free (sql);
	  if (ret != SQLITE_OK)
	    {
		printf ("INSERT INTO levels SQL error: %s\n",
			sqlite3_errmsg (handle));
		goto error;
	    }
      }

    table = sqlite3_mprintf ("%s_tiles", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf
	("INSERT INTO \"%s\" (tile_id, pyramid_level, section_id, geometry) "
	 "VALUES (NULL, 0, ?, BuildMBR(?, ?, ?, ?, ?))", xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tils, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("INSERT INTO tiles SQL error: %s\n", sqlite3_errmsg (handle));
	  goto error;
      }

    table = sqlite3_mprintf ("%s_tile_data", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf
	("INSERT INTO \"%s\" (tile_id, tile_data_odd, tile_data_even) "
	 "VALUES (?, ?, ?)", xtable);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("INSERT INTO tile_data SQL error: %s\n",
		  sqlite3_errmsg (handle));
	  goto error;
      }
    res_x = hResolution;
    res_y = vResolution;
    base_res_x = privcvg->hResolution;
    base_res_y = privcvg->vResolution;

/* INSERTing the section */
    if (!rl2_do_insert_section
	(handle, "loaded from RAW pixels", section, srid, width, height, minx,
	 miny, maxx, maxy, xml_summary, privcvg->sectionPaths,
	 privcvg->sectionMD5, privcvg->sectionSummary, stmt_sect, &section_id))
	goto error;
    section_stats = rl2_create_raster_statistics (sample_type, num_bands);
    if (section_stats == NULL)
	goto error;
/* INSERTing the base-levels */
    if (privcvg->mixedResolutions)
      {
	  /* multiple resolutions Coverage */
	  if (!rl2_do_insert_section_levels
	      (handle, section_id, res_x, res_y, 1.0, sample_type, stmt_levl))
	      goto error;
      }
    else
      {
	  /* single resolution Coverage */
	  if (!rl2_do_insert_levels
	      (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl))
	      goto error;
      }

/* looping on tiles */
    tile_maxy = maxy;
    for (row = 0; row < height; row += tile_h)
      {
	  tile_miny = tile_maxy - ((double) tile_h * res_y);
	  tile_minx = minx;
	  for (col = 0; col < width; col += tile_w)
	    {
		/* requesting a Tile */
		rl2RasterPtr tile;
		unsigned char *blob_odd;
		unsigned char *blob_even;
		int blob_odd_sz;
		int blob_even_sz;
		unsigned char *bufpix = malloc (bufpix_sz);

		if (pixel_type == RL2_PIXEL_PALETTE)
		    rl2_prime_void_tile_palette (bufpix, tile_w, tile_h,
						 no_data);
		else
		    rl2_prime_void_tile (bufpix, tile_w, tile_h,
					 sample_type, num_bands, no_data);

		tile_maxx = tile_minx + ((double) tile_w * res_x);
		if (!getTile
		    (data, tile_minx, tile_miny, tile_maxx, tile_maxy, bufpix,
		     &palette))
		  {
		      if (bufpix != NULL)
			  free (bufpix);
		      goto error;
		  }

		/* building a raster Tile */
		tile =
		    rl2_create_raster (tile_w, tile_h, sample_type, pixel_type,
				       num_bands, bufpix, bufpix_sz, palette,
				       NULL, 0, no_data);
		if (tile == NULL)
		  {
		      if (bufpix != NULL)
			  free (bufpix);
		      goto error;
		  }

		/* encoding the Tile */
		if (rl2_raster_encode
		    (tile, compression, &blob_odd, &blob_odd_sz, &blob_even,
		     &blob_even_sz, quality, 1) != RL2_OK)
		  {
		      fprintf (stderr,
			       "ERROR: unable to encode a tile [Row=%d Col=%d]\n",
			       row, col);
		      rl2_destroy_raster (tile);
		      goto error;
		  }
		aux_palette = rl2_clone_palette (rl2_get_raster_palette (tile));
		rl2_destroy_raster (tile);

		/* INSERTing the tile */
		if (!do_insert_tile
		    (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
		     section_id, srid, tile_minx, tile_miny, tile_maxx,
		     tile_maxy, aux_palette, no_data, stmt_tils, stmt_data,
		     section_stats))
		    goto error;

		/* next tile */
		tile_minx += (double) tile_w *res_x;
	    }
	  tile_maxy -= (double) tile_h *res_y;
      }

/* updating the Section's Statistics */
    compute_aggregate_sq_diff (section_stats);
    if (!rl2_do_insert_stats (handle, section_stats, section_id, stmt_upd_sect))
	goto error;

    rl2_destroy_raster_statistics (section_stats);
    section_stats = NULL;

    if (pyramidize)
      {
	  /* immediately building the Section's Pyramid */
	  const char *coverage_name = rl2_get_coverage_name (cvg);
	  if (coverage_name == NULL)
	      goto error;
	  if (rl2_build_section_pyramid
	      (handle, 1, coverage_name, section_id, 1, 0) != RL2_OK)
	    {
		fprintf (stderr, "unable to build the Section's Pyramid\n");
		goto error;
	    }
      }

    sqlite3_finalize (stmt_upd_sect);
    sqlite3_finalize (stmt_sect);
    sqlite3_finalize (stmt_levl);
    sqlite3_finalize (stmt_tils);
    sqlite3_finalize (stmt_data);
    stmt_upd_sect = NULL;
    stmt_sect = NULL;
    stmt_levl = NULL;
    stmt_tils = NULL;
    stmt_data = NULL;

    if (rl2_update_dbms_coverage (handle, coverage) != RL2_OK)
      {
	  fprintf (stderr, "unable to update the Coverage\n");
	  goto error;
      }

    return RL2_OK;

  error:
    if (stmt_upd_sect != NULL)
	sqlite3_finalize (stmt_upd_sect);
    if (stmt_sect != NULL)
	sqlite3_finalize (stmt_sect);
    if (stmt_levl != NULL)
	sqlite3_finalize (stmt_levl);
    if (stmt_tils != NULL)
	sqlite3_finalize (stmt_tils);
    if (stmt_data != NULL)
	sqlite3_finalize (stmt_data);
    return RL2_ERROR;
}

Changes to src/rl2jpeg.c.

226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
...
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
...
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
...
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
...
847
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
...
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
....
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
....
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
....
1310
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
....
1528
1529
1530
1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541
1542
1543
    /* The source object is made permanent so that a series of JPEG images
     * can be read from the same buffer by calling jpeg_mem_src only before
     * the first one.
     */
    if (cinfo->src == NULL)
      {				/* first time for this JPEG object? */
	  cinfo->src = (struct jpeg_source_mgr *)
	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,

					  sizeof (struct jpeg_source_mgr));
      }

    src = cinfo->src;
    src->init_source = init_mem_source;
    src->fill_input_buffer = fill_mem_input_buffer;
    src->skip_input_data = skip_input_data;
................................................................................

    /* The destination object is made permanent so that multiple JPEG images
     * can be written to the same buffer without re-executing jpeg_mem_dest.
     */
    if (cinfo->dest == NULL)
      {				/* first time for this JPEG object? */
	  cinfo->dest = (struct jpeg_destination_mgr *)
	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,

					  sizeof (jpeg_mem_destination_mgr));
	  dest = (jpeg_mem_dest_ptr) cinfo->dest;
	  dest->newbuffer = NULL;
      }

    dest = (jpeg_mem_dest_ptr) cinfo->dest;
    dest->pub.init_destination = init_mem_destination;
................................................................................
/* creating a JPEG image from a raster */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
    unsigned char *blob;
    int blob_size;

    if (rst == NULL)
	return RL2_ERROR;
    if (check_jpeg_compatibility (rst->sampleType, rst->pixelType, rst->nBands)
	!= RL2_OK)
	return RL2_ERROR;
    if (rl2_data_to_jpeg
	(rst->rasterBuffer, rst->maskBuffer, (rl2PalettePtr) (rst->Palette),
	 rst->width, rst->height, rst->sampleType, rst->pixelType, &blob,
	 &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
................................................................................
/* creating a PNG image from an RGB buffer */
    unsigned char *blob;
    int blob_size;
    if (rgb == NULL)
	return RL2_ERROR;

    if (rl2_data_to_jpeg
	(rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, &blob,
	 &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
    *jpeg_size = blob_size;
    return RL2_OK;
}

RL2_DECLARE int
rl2_gray_to_jpeg (unsigned int width, unsigned int height,
		  const unsigned char *gray, int quality, unsigned char **jpeg,
		  int *jpeg_size)
{
/* creating a PNG image from a Grayscale buffer */
    unsigned char *blob;
    int blob_size;
    if (gray == NULL)
	return RL2_ERROR;

    if (rl2_data_to_jpeg
	(gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
	 &blob, &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
    *jpeg_size = blob_size;
    return RL2_OK;
}

RL2_PRIVATE int
................................................................................
    rst = rl2_raster_from_jpeg (blob, blob_size);
    free (blob);
    if (rst == NULL)
	return NULL;

/* creating the raster section */
    scn =
	rl2_create_section (path, RL2_COMPRESSION_JPEG, RL2_TILESIZE_UNDEFINED,
			    RL2_TILESIZE_UNDEFINED, rst);

    return scn;
}

RL2_DECLARE rl2RasterPtr
rl2_raster_from_jpeg (const unsigned char *jpeg, int jpeg_size)
{
/* attempting to create a raster from a JPEG image */
................................................................................
	goto error;
    nBands = 1;
    if (pixel_type == RL2_PIXEL_RGB)
	nBands = 3;

/* creating the raster */
    rst =
	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type, nBands,
			   data, data_size, NULL, NULL, 0, NULL);
    if (rst == NULL)
	goto error;
    return rst;

  error:
    if (rst != NULL)
	rl2_destroy_raster (rst);
    if (data != NULL)
	free (data);
    return NULL;
}

RL2_DECLARE int
rl2_get_jpeg_infos (const char *path, unsigned int *width, unsigned int *height,
		    unsigned char *pixel_type)
{
/* attempting to retrieve basic infos from a JPEG image */
    int jpeg_size;
    unsigned char *jpeg = NULL;
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    int row_stride;
................................................................................
	  /* reading all decompressed scanlines */
	  jpeg_read_scanlines (&cinfo, buffer, 1);
	  if (cinfo.out_color_space == JCS_CMYK)
	    {
		JSAMPROW row = buffer[0];
		for (i = 0; i < (int) (cinfo.output_width); i++)
		  {
		      CMYK2RGB (*(row + 0), *(row + 1), *(row + 2), *(row + 3),
				inverted, p_data);
		      row += 4;
		      p_data += 3;
		  }
	    }
	  else if (cinfo.out_color_space == JCS_GRAYSCALE)
	    {
		JSAMPROW row = buffer[0];
................................................................................
				unsigned char forced_conversion, int verbose)
{
/* checking for strict compatibility */
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1

	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
	      return 1;
      }
    if (verbose)
	fprintf (stderr, "Mismatching JPEG colorspace !!!\n");
    return 0;
}
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =

	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
			       prev, maxx - minx);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, maxy - miny);
	  sqlite3_free (prev);
	  prev = xml;







|
>







 







|
>







 







|
|







 







|
|








|
|








|
|







 







|
|
>







 







|
|













|
|







 







|
|







 







|
|







 







|
>







 







>
|
|







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
...
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
...
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
...
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
....
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
....
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
....
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
    /* The source object is made permanent so that a series of JPEG images
     * can be read from the same buffer by calling jpeg_mem_src only before
     * the first one.
     */
    if (cinfo->src == NULL)
      {				/* first time for this JPEG object? */
	  cinfo->src = (struct jpeg_source_mgr *)
	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
					  JPOOL_PERMANENT,
					  sizeof (struct jpeg_source_mgr));
      }

    src = cinfo->src;
    src->init_source = init_mem_source;
    src->fill_input_buffer = fill_mem_input_buffer;
    src->skip_input_data = skip_input_data;
................................................................................

    /* The destination object is made permanent so that multiple JPEG images
     * can be written to the same buffer without re-executing jpeg_mem_dest.
     */
    if (cinfo->dest == NULL)
      {				/* first time for this JPEG object? */
	  cinfo->dest = (struct jpeg_destination_mgr *)
	      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
					  JPOOL_PERMANENT,
					  sizeof (jpeg_mem_destination_mgr));
	  dest = (jpeg_mem_dest_ptr) cinfo->dest;
	  dest->newbuffer = NULL;
      }

    dest = (jpeg_mem_dest_ptr) cinfo->dest;
    dest->pub.init_destination = init_mem_destination;
................................................................................
/* creating a JPEG image from a raster */
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;
    unsigned char *blob;
    int blob_size;

    if (rst == NULL)
	return RL2_ERROR;
    if (check_jpeg_compatibility
	(rst->sampleType, rst->pixelType, rst->nBands) != RL2_OK)
	return RL2_ERROR;
    if (rl2_data_to_jpeg
	(rst->rasterBuffer, rst->maskBuffer, (rl2PalettePtr) (rst->Palette),
	 rst->width, rst->height, rst->sampleType, rst->pixelType, &blob,
	 &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
................................................................................
/* creating a PNG image from an RGB buffer */
    unsigned char *blob;
    int blob_size;
    if (rgb == NULL)
	return RL2_ERROR;

    if (rl2_data_to_jpeg
	(rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB,
	 &blob, &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
    *jpeg_size = blob_size;
    return RL2_OK;
}

RL2_DECLARE int
rl2_gray_to_jpeg (unsigned int width, unsigned int height,
		  const unsigned char *gray, int quality,
		  unsigned char **jpeg, int *jpeg_size)
{
/* creating a PNG image from a Grayscale buffer */
    unsigned char *blob;
    int blob_size;
    if (gray == NULL)
	return RL2_ERROR;

    if (rl2_data_to_jpeg
	(gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8,
	 RL2_PIXEL_GRAYSCALE, &blob, &blob_size, quality) != RL2_OK)
	return RL2_ERROR;
    *jpeg = blob;
    *jpeg_size = blob_size;
    return RL2_OK;
}

RL2_PRIVATE int
................................................................................
    rst = rl2_raster_from_jpeg (blob, blob_size);
    free (blob);
    if (rst == NULL)
	return NULL;

/* creating the raster section */
    scn =
	rl2_create_section (path, RL2_COMPRESSION_JPEG,
			    RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED,
			    rst);
    return scn;
}

RL2_DECLARE rl2RasterPtr
rl2_raster_from_jpeg (const unsigned char *jpeg, int jpeg_size)
{
/* attempting to create a raster from a JPEG image */
................................................................................
	goto error;
    nBands = 1;
    if (pixel_type == RL2_PIXEL_RGB)
	nBands = 3;

/* creating the raster */
    rst =
	rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type,
			   nBands, data, data_size, NULL, NULL, 0, NULL);
    if (rst == NULL)
	goto error;
    return rst;

  error:
    if (rst != NULL)
	rl2_destroy_raster (rst);
    if (data != NULL)
	free (data);
    return NULL;
}

RL2_DECLARE int
rl2_get_jpeg_infos (const char *path, unsigned int *width,
		    unsigned int *height, unsigned char *pixel_type)
{
/* attempting to retrieve basic infos from a JPEG image */
    int jpeg_size;
    unsigned char *jpeg = NULL;
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    int row_stride;
................................................................................
	  /* reading all decompressed scanlines */
	  jpeg_read_scanlines (&cinfo, buffer, 1);
	  if (cinfo.out_color_space == JCS_CMYK)
	    {
		JSAMPROW row = buffer[0];
		for (i = 0; i < (int) (cinfo.output_width); i++)
		  {
		      CMYK2RGB (*(row + 0), *(row + 1), *(row + 2),
				*(row + 3), inverted, p_data);
		      row += 4;
		      p_data += 3;
		  }
	    }
	  else if (cinfo.out_color_space == JCS_GRAYSCALE)
	    {
		JSAMPROW row = buffer[0];
................................................................................
				unsigned char forced_conversion, int verbose)
{
/* checking for strict compatibility */
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
	      && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
	      return 1;
      }
    if (verbose)
	fprintf (stderr, "Mismatching JPEG colorspace !!!\n");
    return 0;
}
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf
	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
	       maxx - minx);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, maxy - miny);
	  sqlite3_free (prev);
	  prev = xml;

Changes to src/rl2openjpeg.c.

55
56
57
58
59
60
61
62



63

64
65
66
67
68
69
70
...
688
689
690
691
692
693
694
695

696
697
698
699
700
701
702
703
...
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
...
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
...
913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976

977
978
979
980
981
982
983
984
...
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
....
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
....
1600
1601
1602
1603
1604
1605
1606

1607
1608
1609
1610
1611
1612
1613
1614
1615
#include "rasterlite2/rl2tiff.h"
#include "rasterlite2_private.h"

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */

#ifdef HAVE_OPENJPEG_2_1_OPENJPEG_H
#include <openjpeg-2.1/openjpeg.h>
#else



#include <openjpeg-2.0/openjpeg.h>

#endif

struct jp2_memfile
{
/* a struct emulating a file [memory mapped] */
    unsigned char *buffer;
    int malloc_block;
................................................................................
      }
}

RL2_PRIVATE int
rl2_decode_jpeg2000_scaled (int scale, const unsigned char *jpeg2000,
			    int jpeg2000_sz, unsigned int *xwidth,
			    unsigned int *xheight, unsigned char xsample_type,
			    unsigned char xpixel_type, unsigned char xnum_bands,

			    unsigned char **pixels, int *pixels_size)
{
/* attempting to create a raster from a Jpeg2000 image - supporting rescaled size */
    unsigned char *buf = NULL;
    int buf_size = 0;
    unsigned int width;
    unsigned int height;
    unsigned char sample_type = RL2_SAMPLE_UNKNOWN;
................................................................................
		fprintf (stderr,
			 "OpenJpeg Error: opj_decode_tile_data() failed\n");
		goto error;
	    }
	  if (sample_type == RL2_SAMPLE_UINT16)
	      save_tile_u16 ((unsigned short *) buf,
			     (unsigned short *) jp2_data, tile_x0 / scale,
			     tile_y0 / scale, tile_x1 / scale, tile_y1 / scale,
			     num_bands, width / scale, height / scale);

	  else
	      save_tile_u8 ((unsigned char *) buf, (unsigned char *) jp2_data,
			    tile_x0 / scale, tile_y0 / scale, tile_x1 / scale,
			    tile_y1 / scale, num_bands, width / scale,
			    height / scale);
	  free (jp2_data);
	  jp2_data = NULL;
................................................................................
				    int verbose)
{
/* checking for strict compatibility */
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1

	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3
							  || coverage->nBands ==
							  4))
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_MULTIBAND
	      && raster->nBands == coverage->nBands
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3
							  || coverage->nBands ==
							  4))
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_MULTIBAND
	      && raster->nBands == coverage->nBands
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (verbose)
	fprintf (stderr, "Mismatching Jpeg2000 colorspace !!!\n");
    return 0;
}

static int
read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin, unsigned short width,

				  unsigned short height, unsigned int startRow,
				  unsigned int startCol, unsigned char *pixels)
{
/* Grayscale -> RGB */
    unsigned short x;
    unsigned short y;
    unsigned short row;
    unsigned short col;
................................................................................
		*p_out++ = value;	/* blue */
	    }
      }
    return 1;
}

static int
read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin, unsigned short width,

				  unsigned short height, unsigned int startRow,
				  unsigned int startCol, unsigned char *pixels)
{
/* RGB -> Grayscale */
    unsigned short x;
    unsigned short y;
    unsigned short row;
    unsigned short col;
................................................................................
    if (no_data != NULL)
	rl2_destroy_pixel (no_data);
    return RL2_ERROR;
}

RL2_DECLARE rl2RasterPtr
rl2_get_tile_from_jpeg2000_origin (rl2CoveragePtr cvg, rl2RasterPtr jpeg2000,
				   unsigned int startRow, unsigned int startCol,

				   unsigned char forced_conversion, int verbose)
{
/* attempting to create a Coverage-tile from a Jpeg2000 origin */
    unsigned int x;
    rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg;
    rl2PrivRasterPtr origin = (rl2PrivRasterPtr) jpeg2000;
    rl2RasterPtr raster = NULL;
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =

	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
			       prev, maxx - minx);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, maxy - miny);
	  sqlite3_free (prev);
	  prev = xml;








>
>
>

>







 







|
>
|







 







|
|
>







 







|
|







 







|
>







|
|



|
|
<











|
|











|
|
<













|
>
|







 







|
>
|







 







|
>







 







>
|
|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
...
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
...
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
...
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
...
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967

968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
....
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
....
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
....
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
#include "rasterlite2/rl2tiff.h"
#include "rasterlite2_private.h"

#ifndef OMIT_OPENJPEG		/* only if OpenJpeg is enabled */

#ifdef HAVE_OPENJPEG_2_1_OPENJPEG_H
#include <openjpeg-2.1/openjpeg.h>
#else
#ifdef __ANDROID__		/* Android specific */
#include <openjpeg.h>
#else
#include <openjpeg-2.0/openjpeg.h>
#endif
#endif

struct jp2_memfile
{
/* a struct emulating a file [memory mapped] */
    unsigned char *buffer;
    int malloc_block;
................................................................................
      }
}

RL2_PRIVATE int
rl2_decode_jpeg2000_scaled (int scale, const unsigned char *jpeg2000,
			    int jpeg2000_sz, unsigned int *xwidth,
			    unsigned int *xheight, unsigned char xsample_type,
			    unsigned char xpixel_type,
			    unsigned char xnum_bands, unsigned char **pixels,
			    int *pixels_size)
{
/* attempting to create a raster from a Jpeg2000 image - supporting rescaled size */
    unsigned char *buf = NULL;
    int buf_size = 0;
    unsigned int width;
    unsigned int height;
    unsigned char sample_type = RL2_SAMPLE_UNKNOWN;
................................................................................
		fprintf (stderr,
			 "OpenJpeg Error: opj_decode_tile_data() failed\n");
		goto error;
	    }
	  if (sample_type == RL2_SAMPLE_UINT16)
	      save_tile_u16 ((unsigned short *) buf,
			     (unsigned short *) jp2_data, tile_x0 / scale,
			     tile_y0 / scale, tile_x1 / scale,
			     tile_y1 / scale, num_bands, width / scale,
			     height / scale);
	  else
	      save_tile_u8 ((unsigned char *) buf, (unsigned char *) jp2_data,
			    tile_x0 / scale, tile_y0 / scale, tile_x1 / scale,
			    tile_y1 / scale, num_bands, width / scale,
			    height / scale);
	  free (jp2_data);
	  jp2_data = NULL;
................................................................................
				    int verbose)
{
/* checking for strict compatibility */
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
................................................................................
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_GRAYSCALE
	      && raster->nBands == 1
	      && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_DATAGRID
	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT8
	&& coverage->pixelType == RL2_PIXEL_MULTIBAND
	&& (coverage->nBands == 3 || coverage->nBands == 4))

      {
	  if (raster->sampleType == RL2_SAMPLE_UINT8
	      && raster->pixelType == RL2_PIXEL_MULTIBAND
	      && raster->nBands == coverage->nBands
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_DATAGRID
	      && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3)
      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (coverage->sampleType == RL2_SAMPLE_UINT16
	&& coverage->pixelType == RL2_PIXEL_MULTIBAND
	&& (coverage->nBands == 3 || coverage->nBands == 4))

      {
	  if (raster->sampleType == RL2_SAMPLE_UINT16
	      && raster->pixelType == RL2_PIXEL_MULTIBAND
	      && raster->nBands == coverage->nBands
	      && forced_conversion == RL2_CONVERT_NO)
	      return 1;
      }
    if (verbose)
	fprintf (stderr, "Mismatching Jpeg2000 colorspace !!!\n");
    return 0;
}

static int
read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin,
				  unsigned short width, unsigned short height,
				  unsigned int startRow,
				  unsigned int startCol, unsigned char *pixels)
{
/* Grayscale -> RGB */
    unsigned short x;
    unsigned short y;
    unsigned short row;
    unsigned short col;
................................................................................
		*p_out++ = value;	/* blue */
	    }
      }
    return 1;
}

static int
read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin,
				  unsigned short width, unsigned short height,
				  unsigned int startRow,
				  unsigned int startCol, unsigned char *pixels)
{
/* RGB -> Grayscale */
    unsigned short x;
    unsigned short y;
    unsigned short row;
    unsigned short col;
................................................................................
    if (no_data != NULL)
	rl2_destroy_pixel (no_data);
    return RL2_ERROR;
}

RL2_DECLARE rl2RasterPtr
rl2_get_tile_from_jpeg2000_origin (rl2CoveragePtr cvg, rl2RasterPtr jpeg2000,
				   unsigned int startRow,
				   unsigned int startCol,
				   unsigned char forced_conversion, int verbose)
{
/* attempting to create a Coverage-tile from a Jpeg2000 origin */
    unsigned int x;
    rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg;
    rl2PrivRasterPtr origin = (rl2PrivRasterPtr) jpeg2000;
    rl2RasterPtr raster = NULL;
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf
	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
	       maxx - minx);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, maxy - miny);
	  sqlite3_free (prev);
	  prev = xml;

Changes to src/rl2paint.c.

182
183
184
185
186
187
188










189
190
191
192
193
194
195
...
768
769
770
771
772
773
774
775

776
777
778
779
780
781
782
783
....
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1058
....
1164
1165
1166
1167
1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
....
1554
1555
1556
1557
1558
1559
1560

1561

1562
1563
1564
1565
1566
1567
1568
....
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581


1582
1583
1584

1585
1586
1587

1588
1589
1590
1591
1592
1593

1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611




















1612
1613
1614
1615
1616
1617
1618
....
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
....
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774
1775
1776
1777
1778
1779
1780
....
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930






1931
1932
1933
1934
1935
1936
1937
....
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
....
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
....
2576
2577
2578
2579
2580
2581
2582

2583
2584
2585
2586
2587
2588
2589
....
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
....
2660
2661
2662
2663
2664
2665
2666
2667


2668
2669
2670
2671

2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685


2686
2687






















































2688
2689
2690
2691
2692
2693
2694
....
2699
2700
2701
2702
2703
2704
2705

2706
2707
2708
2709
2710
2711
2712








2713
2714
2715
2716
2717
2718
2719
....
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737


2738
2739
2740
2741
2742
2743
2744

2745
2746
2747
2748
2749
2750
2751
2752
2753

2754
2755
2756
2757
2758
2759
2760
....
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789


2790
2791
2792
2793
2794
2795
2796
....
2804
2805
2806
2807
2808
2809
2810
2811
2812

2813
2814
2815
2816
2817
2818
2819
....
2887
2888
2889
2890
2891
2892
2893


























































































































































2894
2895
2896
2897
2898
2899
2900
....
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
    int width;
    int height;
    unsigned char *rgba;
    cairo_surface_t *bitmap;
    cairo_pattern_t *pattern;
} RL2GraphBitmap;
typedef RL2GraphBitmap *RL2GraphBitmapPtr;











RL2_DECLARE rl2GraphicsContextPtr
rl2_graph_create_context (int width, int height)
{
/* creating a generic Graphics Context */
    RL2GraphContextPtr ctx;

................................................................................
					 double height, unsigned char red1,
					 unsigned char green1,
					 unsigned char blue1,
					 unsigned char alpha1,
					 unsigned char red2,
					 unsigned char green2,
					 unsigned char blue2,
					 unsigned char alpha2, double pen_width,

					 int line_cap, int line_join)
{
/* setting up a Linear Gradient Pen - solid style */
    double d_red = (double) red1 / 255.0;
    double d_green = (double) green1 / 255.0;
    double d_blue = (double) blue1 / 255.0;
    double d_alpha = (double) alpha1 / 255.0;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
................................................................................
    return 1;
}

RL2_DECLARE int
rl2_graph_set_linear_gradient_brush (rl2GraphicsContextPtr context, double x,
				     double y, double width, double height,
				     unsigned char red1, unsigned char green1,
				     unsigned char blue1, unsigned char alpha1,

				     unsigned char red2, unsigned char green2,
				     unsigned char blue2, unsigned char alpha2)
{
/* setting up a Linear Gradient Brush */
    double d_red = (double) red1 / 255.0;
    double d_green = (double) green1 / 255.0;
    double d_blue = (double) blue1 / 255.0;
    double d_alpha = (double) alpha1 / 255.0;
................................................................................
	      style = CAIRO_FONT_SLANT_ITALIC;
	  if (fnt->style == RL2_FONTSTYLE_OBLIQUE)
	      style = CAIRO_FONT_SLANT_OBLIQUE;
	  if (fnt->weight == RL2_FONTWEIGHT_BOLD)
	      weight = CAIRO_FONT_WEIGHT_BOLD;
	  cairo_select_font_face (cairo, fnt->facename, style, weight);
	  cairo_set_font_size (cairo, size);

      }
    else
      {
	  /* using a TrueType font */
	  cairo_font_options_t *font_options = cairo_font_options_create ();
	  cairo_matrix_t ctm;
	  cairo_matrix_t font_matrix;
................................................................................
    unsigned char red;
    unsigned char green;
    unsigned char blue;
    unsigned char alpha;
    unsigned char xred;
    unsigned char xgreen;
    unsigned char xblue;

    int valid = 0;

    unsigned char *bitmap;
    RL2PrivGraphPatternPtr pattern = (RL2PrivGraphPatternPtr) ptrn;
    if (pattern == NULL)
	return RL2_ERROR;

    width = pattern->width;
    height = pattern->height;
................................................................................
    if (bitmap == NULL)
	return RL2_ERROR;
/* checking for a Monochrome Pattern */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
				       &alpha);
		if (alpha != 0)
		  {


		      if (valid)
			{
			    if (xred == red && xgreen == green && xblue == blue)

				;
			    else
				return RL2_ERROR;

			}
		      else
			{
			    xred = red;
			    xgreen = green;
			    xblue = blue;

			    valid = 1;
			}
		  }
	    }
      }
/* all right, applying the new color */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
				       &alpha);
		if (alpha != 0)
		    aux_pattern_set_pixel (x, y, width, bitmap, r, g, b, alpha);
	    }
      }
    cairo_surface_mark_dirty (pattern->bitmap);
    return RL2_OK;




















}

RL2_DECLARE int
rl2_graph_pattern_transparency (rl2GraphicsPatternPtr ptrn, unsigned char aleph)
{
/* changing the Pattern's transparency */
    int x;
................................................................................
    if (bitmap == NULL)
	return RL2_ERROR;
/* applying the new transparency */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue,
				       &alpha);
		if (alpha != 0)
		    aux_pattern_set_pixel (x, y, width, bitmap, red, green,
					   blue, aleph);
	    }
      }
    cairo_surface_mark_dirty (pattern->bitmap);
    return RL2_OK;
................................................................................
      }

/* destroying the cached font */
    rl2_destroy_private_tt_font (font);
}

RL2_DECLARE rl2GraphicsFontPtr
rl2_graph_create_TrueType_font (const void *priv_data, const unsigned char *ttf,

				int ttf_bytes, double size)
{
/* creating a TrueType font */
    RL2GraphFontPtr fnt;
    char *facename;
    int is_bold;
    int is_italic;
    unsigned char *font = NULL;
................................................................................
}

RL2_DECLARE void
rl2_graph_destroy_font (rl2GraphicsFontPtr font)
{
/* destroying a font */
    RL2GraphFontPtr fnt = (RL2GraphFontPtr) font;

    if (fnt == NULL)
	return;
    if (fnt->toy_font == 0)
      {
	  if (fnt->cairo_scaled_font != NULL)
	      cairo_scaled_font_destroy (fnt->cairo_scaled_font);
	  if (fnt->cairo_font != NULL)
	      cairo_font_face_destroy (fnt->cairo_font);
      }
    else
      {
	  if (fnt->facename != NULL)
	      free (fnt->facename);
	  free (fnt);
      }






}

RL2_DECLARE int
rl2_graph_font_set_color (rl2GraphicsFontPtr font, unsigned char red,
			  unsigned char green, unsigned char blue,
			  unsigned char alpha)
{
................................................................................
    set_current_pen (ctx);
    cairo_stroke (cairo);
    return 1;
}

RL2_DECLARE int
rl2_graph_draw_circle_sector (rl2GraphicsContextPtr context, double center_x,
			      double center_y, double radius, double from_angle,
			      double to_angle)
{
/* drawing a filled circular sector */
    cairo_t *cairo;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
    if (ctx == NULL)
	return 0;
    if (ctx->type == RL2_SURFACE_PDF)
................................................................................
    *height = extents.height;
    *post_x = extents.x_advance;
    *post_y = extents.y_advance;
    return 1;
}

RL2_DECLARE int
rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text, double x,
		     double y, double angle, double anchor_point_x,
		     double anchor_point_y)
{
/* drawing a text string (using the current font) */
    double rads;
    double pre_x;
    double pre_y;
    double width;
................................................................................
			  rl2_geometry_from_blob (blob3, size3);
		      if (result == NULL)
			  break;
		      if (result->first_point == NULL)
			  break;
		      *x = result->first_point->x;
		      *y = result->first_point->y;

		      ok = 1;
		  }
	    }
	  else
	      goto error;
      }
    if (ok == 0)
................................................................................
    rl2GetPoint (ln->coords, ln->points - 1, &xx, &yy);
    if (xx == x && yy == y)
	return 1;
    return 0;
}

static rl2GeometryPtr
aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom, rl2GeometryPtr circle,
		  double x, double y)
{
/* reducing a Curve by discarding the alreasdy processed portion */
    sqlite3_stmt *stmt = NULL;
    const char *sql;
    int ret;
    unsigned char *blob1;
    int size1;
    unsigned char *blob2;
    int size2;
    rl2GeometryPtr out = NULL;
    rl2LinestringPtr ln;
    rl2LinestringPtr save_ln = NULL;
    int count = 0;

    rl2_serialize_linestring (geom->first_linestring, &blob1, &size1);
    rl2_serialize_linestring (circle->first_linestring, &blob2, &size2);

/* preparing the SQL query statement */
    sql = "SELECT ST_Split(?, ?)";
................................................................................
		      ln = result->first_linestring;
		      while (ln != NULL)
			{
			    if (aux_is_discarded_portion (ln, x, y))
				;
			    else
			      {
				  save_ln = ln;


				  count++;
			      }
			    ln = ln->next;
			}

		  }
	    }
	  else
	      goto error;
      }
    if (save_ln == NULL || count != 1)
	goto error;
    out = rl2_clone_linestring (save_ln);
    sqlite3_finalize (stmt);
    return out;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);


    return NULL;
}























































static rl2GeometryPtr
rl2_draw_wrapped_label (sqlite3 * handle, rl2GraphicsContextPtr context,
			cairo_t * cairo, const char *text, rl2GeometryPtr geom)
{
/* placing each character along the modelling line */
    double x0;
................................................................................
    double m;
    double rads;
    double angle;
    char buf[2];
    rl2GeometryPtr g2;
    rl2GeometryPtr g = rl2_clone_curve (geom);
    rl2GeometryPtr circle;

    const char *c = text;
    cairo_font_extents_t extents;

    cairo_font_extents (cairo, &extents);
    radius =
	sqrt ((extents.max_x_advance * extents.max_x_advance) +
	      (extents.height * extents.height)) / 2.0;








    while (*c != '\0' && g != NULL)
      {
	  buf[0] = *c;
	  buf[1] = '\0';
	  get_aux_start_point (g, &x0, &y0);
	  circle = rl2_build_circle (x0, y0, radius);
	  if (!get_aux_interception_point (handle, g, circle, &x1, &y1))
................................................................................
		rl2_destroy_geometry (g);
		g = NULL;
		break;
	    }
	  m = (y1 - y0) / (x1 - x0);
	  rads = atan (m);
	  angle = rads / .0174532925199432958;
	  if (x1 < x0)
	      angle += 180.0;
	  rl2_graph_draw_text (context, buf, x0, y0, angle, 0.5, 0.5);
	  c++;
	  g2 = aux_reduce_curve (handle, g, circle, x0, y0);
	  rl2_destroy_geometry (circle);
	  rl2_destroy_geometry (g);
	  g = g2;
      }


    return g;
}

RL2_DECLARE int
rl2_graph_draw_warped_text (sqlite3 * handle, rl2GraphicsContextPtr context,
			    const char *text, int points, double *x, double *y,
			    double initial_gap, double gap, int repeated)

{
/* drawing a text string warped along a modelling curve (using the current font) */
    double curve_len;
    double text_len;
    double extra_len;
    double start;
    double from;
    rl2GeometryPtr geom = NULL;
    rl2GeometryPtr geom2 = NULL;

    cairo_t *cairo;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;

    if (ctx == NULL)
	return 0;
    if (text == NULL)
	return 0;
................................................................................

    geom = rl2_curve_from_XY (points, x, y);
    if (geom == NULL)
	return 0;

    curve_len = rl2_compute_curve_length (geom);
    do_estimate_text_length (cairo, text, &text_len, &extra_len);
    if ((text_len + (2.0 * extra_len)) > curve_len)
	return 0;		/* not enough room to place the label */

    if (repeated)
      {
	  /* repeated labels */
	  int first = 1;
	  rl2GeometryPtr geom3 = rl2_clone_linestring (geom->first_linestring);
	  while (geom3 != NULL)
	    {
		if (first)
		  {
		      start = initial_gap + extra_len;
		      first = 0;
		  }
		else
		    start = gap + extra_len;
		curve_len = rl2_compute_curve_length (geom3);


		from = start / curve_len;
		/* extracting the sub-path modelling the label */
		geom2 = rl2_curve_substring (handle, geom3, from, 1.0);
		rl2_destroy_geometry (geom3);
		if (geom2 == NULL)
		    goto error;
		geom3 =
................................................................................
	  /* single label */
	  start = (curve_len - text_len) / 2.0;
	  from = start / curve_len;
	  /* extracting the sub-path modelling the label */
	  geom2 = rl2_curve_substring (handle, geom, from, 1.0);
	  if (geom2 == NULL)
	      goto error;
	  rl2_draw_wrapped_label (handle, context, cairo, text, geom2);
	  rl2_destroy_geometry (geom2);

      }

    rl2_destroy_geometry (geom);
    return 1;

  error:
    rl2_destroy_geometry (geom);
................................................................................
    cairo_scale (cairo, scale_x, scale_y);
    cairo_set_source (cairo, bmp->pattern);
    cairo_paint (cairo);
    cairo_restore (cairo);
    cairo_surface_flush (surface);
    return 1;
}



























































































































































RL2_DECLARE int
rl2_graph_draw_graphic_symbol (rl2GraphicsContextPtr context,
			       rl2GraphicsPatternPtr symbol, double width,
			       double height, double x,
			       double y, double angle,
			       double anchor_point_x, double anchor_point_y)
................................................................................
      }
    cairo_restore (cairo);
    cairo_surface_flush (surface);

    return 1;
}

static unsigned char
unpremultiply (unsigned char c, unsigned char a)
{
/* Cairo has premultiplied alphas */
    double x = ((double) c * 255.0) / (double) a;
    if (a == 0)
	return 0;
    return (unsigned char) x;
}

RL2_DECLARE unsigned char *
rl2_graph_get_context_rgb_array (rl2GraphicsContextPtr context)
{
/* creating an RGB buffer from the given Context */
    int width;
    int height;
    int x;







>
>
>
>
>
>
>
>
>
>







 







|
>
|







 







|
>
|







 







>







 







>

>







 







|
|


>
>


|
>


<
>






>










|
|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|







 







|
>
|







 







<






<
<





<

>
>
>
>
>
>







 







|
|







 







|
|







 







>







 







|
|











<







 







|
>
>




>





|

<






>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







>
>
>
>
>
>
>
>







 







|








>
>





|
|
>









>







 







|






|










>
>







 







|

>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
....
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
....
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
....
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
....
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
....
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
....
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
....
1948
1949
1950
1951
1952
1953
1954

1955
1956
1957
1958
1959
1960


1961
1962
1963
1964
1965

1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
....
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
....
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
....
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
....
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671

2672
2673
2674
2675
2676
2677
2678
....
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723

2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
....
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
....
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
....
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
....
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
....
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
....
3389
3390
3391
3392
3393
3394
3395










3396
3397
3398
3399
3400
3401
3402
    int width;
    int height;
    unsigned char *rgba;
    cairo_surface_t *bitmap;
    cairo_pattern_t *pattern;
} RL2GraphBitmap;
typedef RL2GraphBitmap *RL2GraphBitmapPtr;

static unsigned char
unpremultiply (unsigned char c, unsigned char a)
{
/* Cairo has premultiplied alphas */
    double x = ((double) c * 255.0) / (double) a;
    if (a == 0)
	return 0;
    return (unsigned char) x;
}

RL2_DECLARE rl2GraphicsContextPtr
rl2_graph_create_context (int width, int height)
{
/* creating a generic Graphics Context */
    RL2GraphContextPtr ctx;

................................................................................
					 double height, unsigned char red1,
					 unsigned char green1,
					 unsigned char blue1,
					 unsigned char alpha1,
					 unsigned char red2,
					 unsigned char green2,
					 unsigned char blue2,
					 unsigned char alpha2,
					 double pen_width, int line_cap,
					 int line_join)
{
/* setting up a Linear Gradient Pen - solid style */
    double d_red = (double) red1 / 255.0;
    double d_green = (double) green1 / 255.0;
    double d_blue = (double) blue1 / 255.0;
    double d_alpha = (double) alpha1 / 255.0;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
................................................................................
    return 1;
}

RL2_DECLARE int
rl2_graph_set_linear_gradient_brush (rl2GraphicsContextPtr context, double x,
				     double y, double width, double height,
				     unsigned char red1, unsigned char green1,
				     unsigned char blue1,
				     unsigned char alpha1, unsigned char red2,
				     unsigned char green2,
				     unsigned char blue2, unsigned char alpha2)
{
/* setting up a Linear Gradient Brush */
    double d_red = (double) red1 / 255.0;
    double d_green = (double) green1 / 255.0;
    double d_blue = (double) blue1 / 255.0;
    double d_alpha = (double) alpha1 / 255.0;
................................................................................
	      style = CAIRO_FONT_SLANT_ITALIC;
	  if (fnt->style == RL2_FONTSTYLE_OBLIQUE)
	      style = CAIRO_FONT_SLANT_OBLIQUE;
	  if (fnt->weight == RL2_FONTWEIGHT_BOLD)
	      weight = CAIRO_FONT_WEIGHT_BOLD;
	  cairo_select_font_face (cairo, fnt->facename, style, weight);
	  cairo_set_font_size (cairo, size);
	  fnt->cairo_font = cairo_get_font_face (cairo);
      }
    else
      {
	  /* using a TrueType font */
	  cairo_font_options_t *font_options = cairo_font_options_create ();
	  cairo_matrix_t ctm;
	  cairo_matrix_t font_matrix;
................................................................................
    unsigned char red;
    unsigned char green;
    unsigned char blue;
    unsigned char alpha;
    unsigned char xred;
    unsigned char xgreen;
    unsigned char xblue;
    unsigned char xalpha;
    int valid = 0;
    int has_black = 0;
    unsigned char *bitmap;
    RL2PrivGraphPatternPtr pattern = (RL2PrivGraphPatternPtr) ptrn;
    if (pattern == NULL)
	return RL2_ERROR;

    width = pattern->width;
    height = pattern->height;
................................................................................
    if (bitmap == NULL)
	return RL2_ERROR;
/* checking for a Monochrome Pattern */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
				       &blue, &alpha);
		if (alpha != 0)
		  {
		      if (red < 64 && green < 64 && blue < 64)
			  has_black++;
		      if (valid)
			{
			    if (xred == red && xgreen == green
				&& xblue == blue && alpha == xalpha)
				;
			    else

				goto not_mono;
			}
		      else
			{
			    xred = red;
			    xgreen = green;
			    xblue = blue;
			    xalpha = alpha;
			    valid = 1;
			}
		  }
	    }
      }
/* all right, applying the new color */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
				       &blue, &alpha);
		if (alpha != 0)
		    aux_pattern_set_pixel (x, y, width, bitmap, r, g, b, alpha);
	    }
      }
    cairo_surface_mark_dirty (pattern->bitmap);
    return RL2_OK;

  not_mono:
    if (has_black)
      {
	  /* recoloring only the black pixels */
	  for (y = 0; y < height; y++)
	    {
		for (x = 0; x < width; x++)
		  {
		      aux_pattern_get_pixel (x, y, width, bitmap, &red,
					     &green, &blue, &alpha);
		      if (red < 64 && green < 64 && blue < 64)
			  aux_pattern_set_pixel (x, y, width, bitmap, r, g, b,
						 alpha);
		  }
	    }
	  cairo_surface_mark_dirty (pattern->bitmap);
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_graph_pattern_transparency (rl2GraphicsPatternPtr ptrn, unsigned char aleph)
{
/* changing the Pattern's transparency */
    int x;
................................................................................
    if (bitmap == NULL)
	return RL2_ERROR;
/* applying the new transparency */
    for (y = 0; y < height; y++)
      {
	  for (x = 0; x < width; x++)
	    {
		aux_pattern_get_pixel (x, y, width, bitmap, &red, &green,
				       &blue, &alpha);
		if (alpha != 0)
		    aux_pattern_set_pixel (x, y, width, bitmap, red, green,
					   blue, aleph);
	    }
      }
    cairo_surface_mark_dirty (pattern->bitmap);
    return RL2_OK;
................................................................................
      }

/* destroying the cached font */
    rl2_destroy_private_tt_font (font);
}

RL2_DECLARE rl2GraphicsFontPtr
rl2_graph_create_TrueType_font (const void *priv_data,
				const unsigned char *ttf, int ttf_bytes,
				double size)
{
/* creating a TrueType font */
    RL2GraphFontPtr fnt;
    char *facename;
    int is_bold;
    int is_italic;
    unsigned char *font = NULL;
................................................................................
}

RL2_DECLARE void
rl2_graph_destroy_font (rl2GraphicsFontPtr font)
{
/* destroying a font */
    RL2GraphFontPtr fnt = (RL2GraphFontPtr) font;

    if (fnt == NULL)
	return;
    if (fnt->toy_font == 0)
      {
	  if (fnt->cairo_scaled_font != NULL)
	      cairo_scaled_font_destroy (fnt->cairo_scaled_font);


      }
    else
      {
	  if (fnt->facename != NULL)
	      free (fnt->facename);

      }
    if (fnt->cairo_font != NULL)
      {
	  if (cairo_font_face_get_reference_count (fnt->cairo_font) > 0)
	      cairo_font_face_destroy (fnt->cairo_font);
      }
    free (fnt);
}

RL2_DECLARE int
rl2_graph_font_set_color (rl2GraphicsFontPtr font, unsigned char red,
			  unsigned char green, unsigned char blue,
			  unsigned char alpha)
{
................................................................................
    set_current_pen (ctx);
    cairo_stroke (cairo);
    return 1;
}

RL2_DECLARE int
rl2_graph_draw_circle_sector (rl2GraphicsContextPtr context, double center_x,
			      double center_y, double radius,
			      double from_angle, double to_angle)
{
/* drawing a filled circular sector */
    cairo_t *cairo;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;
    if (ctx == NULL)
	return 0;
    if (ctx->type == RL2_SURFACE_PDF)
................................................................................
    *height = extents.height;
    *post_x = extents.x_advance;
    *post_y = extents.y_advance;
    return 1;
}

RL2_DECLARE int
rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text,
		     double x, double y, double angle, double anchor_point_x,
		     double anchor_point_y)
{
/* drawing a text string (using the current font) */
    double rads;
    double pre_x;
    double pre_y;
    double width;
................................................................................
			  rl2_geometry_from_blob (blob3, size3);
		      if (result == NULL)
			  break;
		      if (result->first_point == NULL)
			  break;
		      *x = result->first_point->x;
		      *y = result->first_point->y;
		      rl2_destroy_geometry (result);
		      ok = 1;
		  }
	    }
	  else
	      goto error;
      }
    if (ok == 0)
................................................................................
    rl2GetPoint (ln->coords, ln->points - 1, &xx, &yy);
    if (xx == x && yy == y)
	return 1;
    return 0;
}

static rl2GeometryPtr
aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom,
		  rl2GeometryPtr circle, double x, double y)
{
/* reducing a Curve by discarding the alreasdy processed portion */
    sqlite3_stmt *stmt = NULL;
    const char *sql;
    int ret;
    unsigned char *blob1;
    int size1;
    unsigned char *blob2;
    int size2;
    rl2GeometryPtr out = NULL;
    rl2LinestringPtr ln;

    int count = 0;

    rl2_serialize_linestring (geom->first_linestring, &blob1, &size1);
    rl2_serialize_linestring (circle->first_linestring, &blob2, &size2);

/* preparing the SQL query statement */
    sql = "SELECT ST_Split(?, ?)";
................................................................................
		      ln = result->first_linestring;
		      while (ln != NULL)
			{
			    if (aux_is_discarded_portion (ln, x, y))
				;
			    else
			      {
				  if (out != NULL)
				      rl2_destroy_geometry (out);
				  out = rl2_clone_linestring (ln);
				  count++;
			      }
			    ln = ln->next;
			}
		      rl2_destroy_geometry (result);
		  }
	    }
	  else
	      goto error;
      }
    if (out == NULL || count != 1)
	goto error;

    sqlite3_finalize (stmt);
    return out;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    if (out != NULL)
	rl2_destroy_geometry (out);
    return NULL;
}

static int
check_reverse (rl2GeometryPtr geom)
{
/* testing for an inverse label */
    rl2LinestringPtr ln;
    double x0;
    double y0;
    double x1;
    double y1;
    double width;
    double height;
    int last;

    if (geom == NULL)
	return 0;
    ln = geom->first_linestring;
    if (ln == NULL)
	return 0;
    if (ln->points < 2)
	return 0;
    last = ln->points - 1;

    rl2GetPoint (ln->coords, 0, &x0, &y0);
    rl2GetPoint (ln->coords, last, &x1, &y1);
    width = fabs (x0 - x1);
    height = fabs (y0 - y1);
    if (width > 3.0)
      {
	  if (x0 > x1)
	      return 1;
      }
    else
      {
	  if (y0 > y1)
	      return 1;
      }
    return 0;
}

static void
reverse_text (const char *in, char *dest, int len)
{
/* reversing a text string */
    char *out;
    int n = 1;
    while (*in != '\0')
      {
	  out = dest + len - n;
	  *out = *in++;
	  n++;
      }
    *(dest + len) = '\0';
}

static rl2GeometryPtr
rl2_draw_wrapped_label (sqlite3 * handle, rl2GraphicsContextPtr context,
			cairo_t * cairo, const char *text, rl2GeometryPtr geom)
{
/* placing each character along the modelling line */
    double x0;
................................................................................
    double m;
    double rads;
    double angle;
    char buf[2];
    rl2GeometryPtr g2;
    rl2GeometryPtr g = rl2_clone_curve (geom);
    rl2GeometryPtr circle;
    char *rev_text = NULL;
    const char *c = text;
    cairo_font_extents_t extents;

    cairo_font_extents (cairo, &extents);
    radius =
	sqrt ((extents.max_x_advance * extents.max_x_advance) +
	      (extents.height * extents.height)) / 2.0;
    if (check_reverse (g))
      {
	  /* reverse text */
	  int len = strlen (text);
	  rev_text = malloc (len + 1);
	  reverse_text (text, rev_text, len);
	  c = rev_text;
      }
    while (*c != '\0' && g != NULL)
      {
	  buf[0] = *c;
	  buf[1] = '\0';
	  get_aux_start_point (g, &x0, &y0);
	  circle = rl2_build_circle (x0, y0, radius);
	  if (!get_aux_interception_point (handle, g, circle, &x1, &y1))
................................................................................
		rl2_destroy_geometry (g);
		g = NULL;
		break;
	    }
	  m = (y1 - y0) / (x1 - x0);
	  rads = atan (m);
	  angle = rads / .0174532925199432958;
	  if (x1 < x0 && rev_text == NULL)
	      angle += 180.0;
	  rl2_graph_draw_text (context, buf, x0, y0, angle, 0.5, 0.5);
	  c++;
	  g2 = aux_reduce_curve (handle, g, circle, x0, y0);
	  rl2_destroy_geometry (circle);
	  rl2_destroy_geometry (g);
	  g = g2;
      }
    if (rev_text)
	free (rev_text);
    return g;
}

RL2_DECLARE int
rl2_graph_draw_warped_text (sqlite3 * handle, rl2GraphicsContextPtr context,
			    const char *text, int points, double *x,
			    double *y, double initial_gap, double gap,
			    int repeated)
{
/* drawing a text string warped along a modelling curve (using the current font) */
    double curve_len;
    double text_len;
    double extra_len;
    double start;
    double from;
    rl2GeometryPtr geom = NULL;
    rl2GeometryPtr geom2 = NULL;
    rl2GeometryPtr geom3 = NULL;
    cairo_t *cairo;
    RL2GraphContextPtr ctx = (RL2GraphContextPtr) context;

    if (ctx == NULL)
	return 0;
    if (text == NULL)
	return 0;
................................................................................

    geom = rl2_curve_from_XY (points, x, y);
    if (geom == NULL)
	return 0;

    curve_len = rl2_compute_curve_length (geom);
    do_estimate_text_length (cairo, text, &text_len, &extra_len);
    if ((initial_gap + text_len + (2.0 * extra_len)) > curve_len)
	return 0;		/* not enough room to place the label */

    if (repeated)
      {
	  /* repeated labels */
	  int first = 1;
	  geom3 = rl2_clone_linestring (geom->first_linestring);
	  while (geom3 != NULL)
	    {
		if (first)
		  {
		      start = initial_gap + extra_len;
		      first = 0;
		  }
		else
		    start = gap + extra_len;
		curve_len = rl2_compute_curve_length (geom3);
		if ((start + text_len + extra_len) > curve_len)
		    break;	/* not enough room to place the label */
		from = start / curve_len;
		/* extracting the sub-path modelling the label */
		geom2 = rl2_curve_substring (handle, geom3, from, 1.0);
		rl2_destroy_geometry (geom3);
		if (geom2 == NULL)
		    goto error;
		geom3 =
................................................................................
	  /* single label */
	  start = (curve_len - text_len) / 2.0;
	  from = start / curve_len;
	  /* extracting the sub-path modelling the label */
	  geom2 = rl2_curve_substring (handle, geom, from, 1.0);
	  if (geom2 == NULL)
	      goto error;
	  geom3 = rl2_draw_wrapped_label (handle, context, cairo, text, geom2);
	  rl2_destroy_geometry (geom2);
	  rl2_destroy_geometry (geom3);
      }

    rl2_destroy_geometry (geom);
    return 1;

  error:
    rl2_destroy_geometry (geom);
................................................................................
    cairo_scale (cairo, scale_x, scale_y);
    cairo_set_source (cairo, bmp->pattern);
    cairo_paint (cairo);
    cairo_restore (cairo);
    cairo_surface_flush (surface);
    return 1;
}

RL2_DECLARE int
rl2_rescale_pixbuf (const unsigned char *inbuf, unsigned int inwidth,
		    unsigned int inheight, unsigned char pixtype,
		    const unsigned char *outbuf, unsigned int outwidth,
		    unsigned int outheight)
{
/* drawing a rescaled pixbufx (RGB or GRAYSCALE) */
    unsigned char *pixbuf = NULL;
    int bufsz;
    const unsigned char *p_in;
    unsigned char *p_out;
    unsigned int x;
    unsigned int y;
    int stride;
    double scale_x = (double) outwidth / (double) inwidth;
    double scale_y = (double) outheight / (double) inheight;
    int little_endian = rl2cr_endian_arch ();
    cairo_t *cairo;
    cairo_surface_t *surface;
    cairo_surface_t *bitmap;
    cairo_pattern_t *pattern;
    if (pixtype != RL2_PIXEL_RGB && pixtype != RL2_PIXEL_GRAYSCALE)
	return 0;

/* creating a Cairo context */
    surface =
	cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outwidth, outheight);
    if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS)
	;
    else
	goto error1;
    cairo = cairo_create (surface);
    if (cairo_status (cairo) == CAIRO_STATUS_NO_MEMORY)
	goto error2;

/* allocating and populating data for Cairo */
    stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, inwidth);
    bufsz = stride * inheight;
    pixbuf = malloc (bufsz);
    if (pixbuf == NULL)
      {
	  goto error2;
      }
    p_in = inbuf;
    p_out = pixbuf;
    for (y = 0; y < inheight; y++)
      {
	  for (x = 0; x < inwidth; x++)
	    {
		unsigned char r;
		unsigned char g;
		unsigned char b;
		if (pixtype == RL2_PIXEL_RGB)
		  {
		      r = *p_in++;
		      g = *p_in++;
		      b = *p_in++;
		  }
		else
		  {
		      r = *p_in++;
		      g = r;
		      b = r;
		  }
		if (little_endian)
		  {
		      *p_out++ = b;
		      *p_out++ = g;
		      *p_out++ = r;
		      *p_out++ = 0xff;
		  }
		else
		  {
		      *p_out++ = 0xff;
		      *p_out++ = r;
		      *p_out++ = g;
		      *p_out++ = b;
		  }
	    }
      }

/* creating the input pattern */
    bitmap =
	cairo_image_surface_create_for_data (pixbuf, CAIRO_FORMAT_ARGB32,
					     inwidth, inheight, stride);
    pattern = cairo_pattern_create_for_surface (bitmap);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);

/* rescaling the image */
    cairo_save (cairo);
    cairo_scale (cairo, scale_x, scale_y);
    cairo_set_source (cairo, pattern);
    cairo_paint (cairo);
    cairo_restore (cairo);
    cairo_surface_flush (surface);

/* cleaning up the input pattern */
    cairo_pattern_destroy (pattern);
    cairo_surface_destroy (bitmap);
    free (pixbuf);

/* exporting the rescaled image */
    p_in = cairo_image_surface_get_data (surface);
    p_out = (unsigned char *) outbuf;
    for (y = 0; y < outheight; y++)
      {
	  for (x = 0; x < outwidth; x++)
	    {
		unsigned char r;
		unsigned char g;
		unsigned char b;
		unsigned char a;
		if (little_endian)
		  {
		      b = *p_in++;
		      g = *p_in++;
		      r = *p_in++;
		      a = *p_in++;
		  }
		else
		  {
		      a = *p_in++;
		      r = *p_in++;
		      g = *p_in++;
		      b = *p_in++;
		  }
		if (pixtype == RL2_PIXEL_RGB)
		  {
		      *p_out++ = unpremultiply (r, a);
		      *p_out++ = unpremultiply (g, a);
		      *p_out++ = unpremultiply (b, a);

		  }
		else
		    *p_out++ = unpremultiply (r, a);
	    }
      }

/* destroying the Cairo context */
    cairo_destroy (cairo);
    cairo_surface_destroy (surface);
    return 1;

  error2:
    if (pixbuf != NULL)
	free (pixbuf);
    cairo_destroy (cairo);
    cairo_surface_destroy (surface);
    return 0;
  error1:
    cairo_surface_destroy (surface);
    return 0;
}

RL2_DECLARE int
rl2_graph_draw_graphic_symbol (rl2GraphicsContextPtr context,
			       rl2GraphicsPatternPtr symbol, double width,
			       double height, double x,
			       double y, double angle,
			       double anchor_point_x, double anchor_point_y)
................................................................................
      }
    cairo_restore (cairo);
    cairo_surface_flush (surface);

    return 1;
}











RL2_DECLARE unsigned char *
rl2_graph_get_context_rgb_array (rl2GraphicsContextPtr context)
{
/* creating an RGB buffer from the given Context */
    int width;
    int height;
    int x;

Changes to src/rl2png.c.

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
....
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1095
....
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
....
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
....
1411
1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1425
1426
	rl2_free (green);
    if (blue != NULL)
	rl2_free (blue);
    return RL2_ERROR;
}

static int
compress_grayscale_png8 (const unsigned char *pixels, const unsigned char *mask,
			 double opacity, unsigned int width,
			 unsigned int height, unsigned char sample_type,
			 unsigned char pixel_type, unsigned char **png,
			 int *png_size)
{
/* compressing a PNG image of the GRAYSCALE type - 8 bits */
    png_structp png_ptr;
    png_infop info_ptr;
    int bit_depth;
    png_bytep *row_pointers = NULL;
    png_bytep p_out;
................................................................................
    *png = blob;
    *png_size = blob_size;
    return RL2_OK;
}

RL2_DECLARE int
rl2_rgb_real_alpha_to_png (unsigned int width, unsigned int height,
			   const unsigned char *rgb, const unsigned char *alpha,

			   unsigned char **png, int *png_size)
{
/* creating a PNG image from two distinct RGB + Alpha buffer */
    unsigned char *blob;
    int blob_size;
    if (rgb == NULL || alpha == NULL)
	return RL2_ERROR;

................................................................................
      case RL2_PIXEL_DATAGRID:
	  if (sample_type == RL2_SAMPLE_UINT16)
	      ret =
		  compress_grayscale_png16 (pixels, width, height,
					    sample_type, &blob, &blob_size);
	  else
	      ret =
		  compress_grayscale_png8 (pixels, mask, opacity, width, height,
					   sample_type, pixel_type, &blob,
					   &blob_size);
	  break;
      case RL2_PIXEL_RGB:
	  if (sample_type == RL2_SAMPLE_UINT8)
	      ret =
		  compress_rgb_png8 (pixels, mask, opacity, width, height,
				     &blob, &blob_size);
	  else if (sample_type == RL2_SAMPLE_UINT16)
................................................................................
		  compress_rgb_png16 (pixels, width, height, &blob, &blob_size);
	  break;
      case RL2_PIXEL_MULTIBAND:
	  if (sample_type == RL2_SAMPLE_UINT8)
	    {
		if (num_bands == 3)
		    ret =
			compress_rgb_png8 (pixels, mask, opacity, width, height,
					   &blob, &blob_size);
		else if (num_bands == 4)
		    ret =
			compress_4bands_png8 (pixels, width, height, &blob,
					      &blob_size);
	    }
	  else if (sample_type == RL2_SAMPLE_UINT16)
	    {
................................................................................
	  if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
	      nBands = 4;
      }
    if (*xpixel_type == RL2_PIXEL_DATAGRID)
	pixel_type = RL2_PIXEL_DATAGRID;
    if (pixel_type == RL2_PIXEL_PALETTE)
      {

	  if (png_get_tRNS (png_ptr, info_ptr, &transp, &nTransp, &transpValues)
	      == PNG_INFO_tRNS)
	    {
		/* a Transparency palette is defined */
		int i;
		for (i = 0; i < nTransp; i++)
		    *(alpha + i) = *(transp + i);
		has_alpha = 1;
	    }







|
|
|
|
|







 







|
>
|







 







|
|
|







 







|
|







 







>
|
|







224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
....
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
....
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
....
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
	rl2_free (green);
    if (blue != NULL)
	rl2_free (blue);
    return RL2_ERROR;
}

static int
compress_grayscale_png8 (const unsigned char *pixels,
			 const unsigned char *mask, double opacity,
			 unsigned int width, unsigned int height,
			 unsigned char sample_type, unsigned char pixel_type,
			 unsigned char **png, int *png_size)
{
/* compressing a PNG image of the GRAYSCALE type - 8 bits */
    png_structp png_ptr;
    png_infop info_ptr;
    int bit_depth;
    png_bytep *row_pointers = NULL;
    png_bytep p_out;
................................................................................
    *png = blob;
    *png_size = blob_size;
    return RL2_OK;
}

RL2_DECLARE int
rl2_rgb_real_alpha_to_png (unsigned int width, unsigned int height,
			   const unsigned char *rgb,
			   const unsigned char *alpha, unsigned char **png,
			   int *png_size)
{
/* creating a PNG image from two distinct RGB + Alpha buffer */
    unsigned char *blob;
    int blob_size;
    if (rgb == NULL || alpha == NULL)
	return RL2_ERROR;

................................................................................
      case RL2_PIXEL_DATAGRID:
	  if (sample_type == RL2_SAMPLE_UINT16)
	      ret =
		  compress_grayscale_png16 (pixels, width, height,
					    sample_type, &blob, &blob_size);
	  else
	      ret =
		  compress_grayscale_png8 (pixels, mask, opacity, width,
					   height, sample_type, pixel_type,
					   &blob, &blob_size);
	  break;
      case RL2_PIXEL_RGB:
	  if (sample_type == RL2_SAMPLE_UINT8)
	      ret =
		  compress_rgb_png8 (pixels, mask, opacity, width, height,
				     &blob, &blob_size);
	  else if (sample_type == RL2_SAMPLE_UINT16)
................................................................................
		  compress_rgb_png16 (pixels, width, height, &blob, &blob_size);
	  break;
      case RL2_PIXEL_MULTIBAND:
	  if (sample_type == RL2_SAMPLE_UINT8)
	    {
		if (num_bands == 3)
		    ret =
			compress_rgb_png8 (pixels, mask, opacity, width,
					   height, &blob, &blob_size);
		else if (num_bands == 4)
		    ret =
			compress_4bands_png8 (pixels, width, height, &blob,
					      &blob_size);
	    }
	  else if (sample_type == RL2_SAMPLE_UINT16)
	    {
................................................................................
	  if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
	      nBands = 4;
      }
    if (*xpixel_type == RL2_PIXEL_DATAGRID)
	pixel_type = RL2_PIXEL_DATAGRID;
    if (pixel_type == RL2_PIXEL_PALETTE)
      {
	  if (png_get_tRNS
	      (png_ptr, info_ptr, &transp, &nTransp,
	       &transpValues) == PNG_INFO_tRNS)
	    {
		/* a Transparency palette is defined */
		int i;
		for (i = 0; i < nTransp; i++)
		    *(alpha + i) = *(transp + i);
		has_alpha = 1;
	    }

Changes to src/rl2pyramid.c.

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361
362
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
...
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
...
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
...
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
...
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
....
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
....
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
....
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
....
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
....
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
....
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
....
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
....
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
....
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
....
1762
1763
1764
1765
1766
1767
1768

1769
1770
1771
1772
1773
1774
1775
1776
1777
....
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
....
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936

1937
1938
1939
1940
1941
1942
1943
....
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
....
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161

2162
2163
2164
2165
2166
2167
2168
....
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
....
2529
2530
2531
2532
2533
2534
2535
2536
2537

2538
2539
2540
2541
2542
2543
2544
....
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
....
3115
3116
3117
3118
3119
3120
3121
3122

3123
3124
3125
3126
3127
3128
3129
3130
....
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
....
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
....
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098

4099
4100
4101
4102
4103
4104
4105
4106
....
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
....
4329
4330
4331
4332
4333
4334
4335

4336
4337
4338
4339
4340
4341
4342
4343
....
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
....
4580
4581
4582
4583
4584
4585
4586
4587

4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
....
4612
4613
4614
4615
4616
4617
4618


4619
4620
4621
4622


4623
4624
4625
4626
4627
4628
4629
....
4954
4955
4956
4957
4958
4959
4960
4961

4962
4963
4964
4965
4966
4967
4968
4969
....
5002
5003
5004
5005
5006
5007
5008
5009



5010
5011
5012
5013
5014
5015
5016
....
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
....
5059
5060
5061
5062
5063
5064
5065

5066
5067
5068
5069
5070
5071
5072
5073
....
5357
5358
5359
5360
5361
5362
5363
5364

5365
5366
5367
5368
5369
5370
5371
5372
....
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
....
5502
5503
5504
5505
5506
5507
5508


5509
5510
5511
5512
5513
5514
5515
....
5528
5529
5530
5531
5532
5533
5534
5535

5536
5537
5538
5539
5540

5541
5542
5543
5544


5545
5546
5547
5548
5549
5550
5551
....
5563
5564
5565
5566
5567
5568
5569
5570
5571

5572
5573
5574
5575
5576
5577
5578
....
5634
5635
5636
5637
5638
5639
5640
5641

5642
5643
5644
5645
5646
5647
5648
5649
....
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
....
5761
5762
5763
5764
5765
5766
5767


5768
5769
5770
5771
5772
5773
5774
....
5779
5780
5781
5782
5783
5784
5785


5786
5787
5788
5789

5790
5791
5792
5793
5794
5795
5796
....
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
....
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
....
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
....
6403
6404
6405
6406
6407
6408
6409
6410

6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
....
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
....
6513
6514
6515
6516
6517
6518
6519
6520

6521
6522
6523
6524
6525

6526
6527
6528
6529
6530
6531
6532
....
6606
6607
6608
6609
6610
6611
6612

6613
6614
6615
6616
6617
6618
6619
6620
6621
#endif

    table = sqlite3_mprintf ("%s_tiles", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf ("SELECT Count(*) FROM \"%s\" "
			 "WHERE section_id = %s AND pyramid_level > 0", xtable,
			 sect_id);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 1;
    while (1)
      {
................................................................................
      }
    sqlite3_finalize (stmt);
    stmt = NULL;
    if (!ok)
	goto error;

/* Coverage's palette and no-data */

    sql = sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages "
			   "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
	  goto error;
      }
................................................................................
	  free (tile_in);
	  tile_in = tile_in_n;
      }
    free (pyr);
}

static int
insert_tile_into_section_pyramid (SectionPyramidPtr pyr, sqlite3_int64 tile_id,
				  double minx, double miny, double maxx,
				  double maxy)
{
/* inserting a base tile into the Pyramid level */
    SectionPyramidTileInPtr tile;
    if (pyr == NULL)
	return 0;
    tile = alloc_section_pyramid_tile (tile_id, minx, miny, maxx, maxy);
    if (tile == NULL)
................................................................................
      {
	  if (tile->cx > minx && tile->cx < maxx && tile->cy > miny
	      && tile->cy < maxy)
	    {
		if (first)
		  {
		      out =
			  add_pyramid_out_tile (pyr, row, col, minx, miny, maxx,
						maxy);
		      first = 0;
		  }
		if (out != NULL)
		    add_pyramid_sub_tile (out, tile);
	    }
	  tile = tile->next;
      }
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		char *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int8 (buf_in, tileWidth, tileHeight, col * 8,
					row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
		     unsigned int tileHeight, int x, int y, unsigned char nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		unsigned char *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_uint8 (buf_in, tileWidth, tileHeight, col * 8,
					 row * 8, nd);
	    }
      }
}

static double
rescale_pixel_int16 (const short *buf_in, unsigned int tileWidth,
		     unsigned int tileHeight, int x, int y, short nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		short *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int16 (buf_in, tileWidth, tileHeight, col * 8,
					 row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, unsigned short nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		int *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int32 (buf_in, tileWidth, tileHeight, col * 8,
					 row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint32 (const unsigned int *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, unsigned int nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		float *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_float (buf_in, tileWidth, tileHeight, col * 8,
					 row * 8, nd);
	    }
      }
}

static double
rescale_pixel_double (const double *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, double nd)
................................................................................
      {
      case RL2_SAMPLE_INT8:
	  rescale_grid_int8 ((char *) buf_out, tileWidth, tileHeight,
			     (const char *) buf_in, x, y, tic_x, tic_y,
			     no_data);
	  break;
      case RL2_SAMPLE_UINT8:
	  rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth, tileHeight,
			      (const unsigned char *) buf_in, x, y, tic_x,
			      tic_y, no_data);
	  break;
      case RL2_SAMPLE_INT16:
	  rescale_grid_int16 ((short *) buf_out, tileWidth, tileHeight,
			      (const short *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_UINT16:
................................................................................
	  break;
      case RL2_SAMPLE_INT32:
	  rescale_grid_int32 ((int *) buf_out, tileWidth, tileHeight,
			      (const int *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_UINT32:
	  rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth, tileHeight,
			       (const unsigned int *) buf_in, x, y, tic_x,
			       tic_y, no_data);
	  break;
      case RL2_SAMPLE_FLOAT:
	  rescale_grid_float ((float *) buf_out, tileWidth, tileHeight,
			      (const float *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_DOUBLE:
................................................................................
				  break;
			      }
			    pos_x += geo_x;
			}
		      pos_y -= geo_y;
		  }
		rst = (rl2PrivRasterPtr) raster_in;
		rescale_grid (buf_out, tileWidth, tileHeight, rst->rasterBuffer,
			      sample_type, x, y, tic_x, tic_y, no_data);

		rl2_destroy_raster (raster_in);
		raster_in = NULL;
		tile_in = tile_in->next;
	    }

	  raster_out = NULL;
	  raster_out =
................................................................................
		goto error;
	    }
	  rl2_destroy_raster (raster_out);
	  raster_out = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))

	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
    if (mask != NULL)
	free (mask);
    return 0;
}

static double
rescale_mb_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
			unsigned int tileHeight, unsigned int x, unsigned int y,
			unsigned char nd, unsigned char nb,
			unsigned char num_bands)
{
/* rescaling a MultiBand pixel sample (8x8) - UINT8 */
    unsigned int row;
    unsigned int col;
    int nodata = 0;
    int valid = 0;
................................................................................
				&& pxl->nBands == num_bands)
			      {
				  rl2PrivSamplePtr sample = pxl->Samples + nb;
				  nd = sample->uint8;
			      }
			}
		      *(p_out + nb) =
			  rescale_mb_pixel_uint8 (buf_in, tileWidth, tileHeight,
						  col * 8, row * 8, nd, nb,
						  num_bands);
		  }
	    }
      }
}

static double
rescale_mb_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
................................................................................
			      {
				  rl2PrivSamplePtr sample = pxl->Samples + nb;
				  nd = sample->uint16;
			      }
			}
		      *(p_out + nb) =
			  rescale_mb_pixel_uint16 (buf_in, tileWidth,
						   tileHeight, col * 8, row * 8,
						   nd, nb, num_bands);
		  }
	    }
      }
}

static void
rescale_multiband (void *buf_out, unsigned int tileWidth,
................................................................................
      case RL2_SAMPLE_UINT8:
	  rescale_multiband_uint8 ((unsigned char *) buf_out, tileWidth,
				   tileHeight, (const unsigned char *) buf_in,
				   x, y, tic_x, tic_y, num_bands, no_data);
	  break;
      case RL2_SAMPLE_UINT16:
	  rescale_multiband_uint16 ((unsigned short *) buf_out, tileWidth,

				    tileHeight, (const unsigned short *) buf_in,
				    x, y, tic_x, tic_y, num_bands, no_data);
	  break;
      };
}

static int
update_sect_pyramid_multiband (sqlite3 * handle, sqlite3_stmt * stmt_rd,
			       sqlite3_stmt * stmt_tils,
................................................................................
			      }
			    pos_x += geo_x;
			}
		      pos_y -= geo_y;
		  }
		rst = (rl2PrivRasterPtr) raster_in;
		rescale_multiband (buf_out, tileWidth, tileHeight,
				   rst->rasterBuffer, sample_type, num_bands, x,
				   y, tic_x, tic_y, no_data);
		rl2_destroy_raster (raster_in);
		raster_in = NULL;
		tile_in = tile_in->next;
	    }

	  raster_out = NULL;
	  raster_out =
................................................................................
		goto error;
	    }
	  rl2_destroy_raster (raster_out);
	  raster_out = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))

	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
							    0);
			}
		      compression = RL2_COMPRESSION_PNG;
		  }
		else
		    nd = rl2_clone_pixel (no_data);
		raster =
		    rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8,
				       RL2_PIXEL_GRAYSCALE, 1, gray,
				       tileWidth * tileHeight, NULL, alpha,
				       tileWidth * tileHeight, nd);
	    }
	  else if (pyr->pixel_type == RL2_PIXEL_RGB)
	    {
		/* RGB Pyramid */
		nd = rl2_clone_pixel (no_data);
		raster =
		    rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8,
				       RL2_PIXEL_RGB, 3, rgb,
				       tileWidth * tileHeight * 3, NULL, alpha,
				       tileWidth * tileHeight, nd);
	    }
	  if (raster == NULL)
	    {
		fprintf (stderr, "ERROR: unable to create a Pyramid Tile\n");
		goto error;
	    }
	  if (rl2_raster_encode
................................................................................
	  rl2_destroy_raster (raster);
	  raster = NULL;
	  rl2_graph_destroy_context (ctx);
	  ctx = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level,
	       pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny,
	       tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data))

	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
	rl2_graph_destroy_context (ctx);
    return 0;
}

#define floor2(exp) ((long) exp)

static rl2RasterPtr
create_124_rescaled_raster (const unsigned char *rgba, unsigned char pixel_type,
			    unsigned int tileWidth, unsigned int tileHeight,
			    int scale)
{
/* creating a rescaled raster (1,2 or 4 bit pyramids) 
/
/ this function builds an high quality rescaled sub-image by applying pixel interpolation
/
/ this code is widely inspired by the original GD gdImageCopyResampled() function
*/
................................................................................
			    *p_msk = 1;
			}
		  }
	    }
      }

    raster =
	rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8, pixel_type,
			   num_bands, rgb, rgb_sz, NULL, mask, mask_sz, NULL);

    return raster;
}

static void
copy_124_rescaled (rl2RasterPtr raster_out, rl2RasterPtr raster_in,
		   unsigned int base_x, unsigned int base_y)
{
................................................................................
		double tile_x = sqlite3_column_double (stmt_geo, 1);
		double tile_y = sqlite3_column_double (stmt_geo, 2);

		rgba = load_tile_base (stmt_data, tile_id, palette, no_data);
		if (rgba == NULL)
		    goto error;
		base_tile =
		    create_124_rescaled_raster (rgba, out_pixel_type, tileWidth,
						tileHeight, factor);
		free (rgba);
		if (base_tile == NULL)
		    goto error;
		shift_x = tile_x - minx;
		shift_y = maxy - tile_y;
		x = (int) (shift_x / res_x);
		y = (int) (shift_y / res_y);
................................................................................
    for (ib = 0; ib < num_bands; ib++)
	*p_out++ = (unsigned char) (*(sum + ib) / (double) valid);
    free (sum);
    *p_msk = 1;
}

static void
mb_prime_nodata_u8 (unsigned char *buf, unsigned int width, unsigned int height,

		    unsigned char num_bands, rl2PixelPtr no_data)
{
/* priming a void buffer */
    rl2PrivPixelPtr nd = (rl2PrivPixelPtr) no_data;
    unsigned int x;
    unsigned int y;
    unsigned char ib;
    unsigned char *p = buf;
................................................................................
					    (unsigned char *) buf_in, mask_in,
					    (unsigned char *) buf, mask, x, y,
					    ox, oy, no_data);
		      break;
		  case RL2_SAMPLE_UINT16:
		      rescale_multiband_u16 (tileWidth, tileHeight, num_bands,
					     out_width, out_height, factor,
					     (unsigned short *) buf_in, mask_in,
					     (unsigned short *) buf, mask, x, y,
					     ox, oy, no_data);
		      break;
		  };
		ox++;
	    }
	  oy++;
      }

................................................................................
					   out_height, factor,
					   (unsigned char *) buf_in,
					   (unsigned char *) buf, mask, x, y,
					   ox, oy, no_data_u8);
		      break;
		  case RL2_SAMPLE_INT16:
		      rescale_datagrid_16 (tileWidth, tileHeight, out_width,
					   out_height, factor, (short *) buf_in,
					   (short *) buf, mask, x, y, ox, oy,
					   no_data_16);
		      break;
		  case RL2_SAMPLE_UINT16:
		      rescale_datagrid_u16 (tileWidth, tileHeight, out_width,
					    out_height, factor,
					    (unsigned short *) buf_in,
					    (unsigned short *) buf, mask, x, y,
					    ox, oy, no_data_u16);
		      break;
		  case RL2_SAMPLE_INT32:
		      rescale_datagrid_32 (tileWidth, tileHeight, out_width,
					   out_height, factor, (int *) buf_in,
					   (int *) buf, mask, x, y, ox, oy,
					   no_data_32);
		      break;
................................................................................
    return raster;
}

static int
rescale_monolithic_multiband (int id_level,
			      unsigned int tileWidth, unsigned int tileHeight,
			      unsigned char sample_type,
			      unsigned char num_bands, int factor, double res_x,
			      double res_y, double minx, double miny,
			      double maxx, double maxy, unsigned char *buffer,

			      int buf_size, unsigned char *mask, int *mask_size,
			      rl2PixelPtr no_data, sqlite3_stmt * stmt_geo,
			      sqlite3_stmt * stmt_data)
{
/* rescaling monolithic MultiBand */
    rl2RasterPtr raster = NULL;
    rl2RasterPtr base_tile = NULL;
    rl2PrivRasterPtr rst;
................................................................................
    p_out = mask;
    for (y = 0; y < tileHeight; y++)
      {
	  /* priming full transparency */
	  for (x = 0; x < tileWidth; x++)
	      *p_out++ = 0;
      }
    rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type, num_bands,
			 no_data);
/* creating the output raster */
    raster =
	rl2_create_raster (tileWidth, tileHeight, sample_type,
			   RL2_PIXEL_MULTIBAND, num_bands, buffer, buf_size,
			   NULL, mask, *mask_size, nd);
    if (raster == NULL)
	goto error;
................................................................................
	  rl2_destroy_raster (raster);
      }
    return 0;
}

static int
prepare_section_pyramid_stmts (sqlite3 * handle, const char *coverage,

			       int mixed_resolutions, sqlite3_stmt ** xstmt_rd,
			       sqlite3_stmt ** xstmt_levl,
			       sqlite3_stmt ** xstmt_tils,
			       sqlite3_stmt ** xstmt_data)
{
/* preparing the section pyramid related SQL statements */
    char *table_tile_data;
    char *xtable_tile_data;
................................................................................

    if (!get_section_infos
	(handle, coverage, section_id, &sect_width, &sect_height, &minx,
	 &miny, &maxx, &maxy, &palette, &no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
	 &stmt_data))
	goto error;

    while (1)
      {
	  /* looping on pyramid levels */
	  if (mixed_resolutions)
	      table_levels = sqlite3_mprintf ("%s_section_levels", coverage);
................................................................................
		      scale = 8;
		      if (first)
			{
			    pyr =
				alloc_sect_pyramid (section_id, sect_width,
						    sect_height, sample_type,
						    pixel_type, num_samples,
						    compression, quality, srid,

						    new_res_x, new_res_y,
						    (double) tileWidth *
						    new_res_x,
						    (double) tileHeight *
						    new_res_y, minx, miny, maxx,
						    maxy, scale);
			    first = 0;
			    if (pyr == NULL)
				goto error;
			}
		      if (!insert_tile_into_section_pyramid
			  (pyr, tile_id, tminx, tminy, tmaxx, tmaxy))
			  goto error;
................................................................................
	  if (pyr == NULL)
	      goto error;

	  out_maxy = maxy;
	  for (row = 0; row < pyr->scaled_height; row += tileHeight)
	    {
		out_miny = out_maxy - pyr->tile_height;


		out_minx = minx;
		for (col = 0; col < pyr->scaled_width; col += tileWidth)
		  {
		      out_maxx = out_minx + pyr->tile_width;


		      set_pyramid_tile_destination (pyr, out_minx, out_miny,
						    out_maxx, out_maxy, row,
						    col);
		      out_minx += pyr->tile_width;
		  }
		out_maxy -= pyr->tile_height;
	    }
................................................................................
}

static int
get_section_raw_raster_data (sqlite3 * handle, int max_threads,
			     const char *coverage, sqlite3_int64 sect_id,
			     unsigned int width, unsigned int height,
			     unsigned char sample_type,
			     unsigned char pixel_type, unsigned char num_bands,

			     double minx, double maxy, double x_res,
			     double y_res, unsigned char **buffer,
			     int *buf_size, rl2PalettePtr palette,
			     rl2PixelPtr no_data)
{
/* attempting to return a buffer containing raw pixels from the whole DBMS Section */
    unsigned char *bufpix = NULL;
    int bufpix_size;
................................................................................

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    sql =
	sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
			 "FROM \"%s\" "
			 "WHERE pyramid_level = 0 AND section_id = ?", xxtiles);



    sqlite3_free (xtiles);
    free (xxtiles);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT section raw tiles SQL error: %s\n",
................................................................................
    if (pixel_type == RL2_PIXEL_PALETTE)
	void_raw_buffer_palette (bufpix, width, height, no_data);
    else
	void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			 no_data);
    if (!rl2_load_dbms_tiles_section
	(handle, max_threads, sect_id, stmt_tiles, stmt_data, bufpix, width,
	 height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, maxy,
	 RL2_SCALE_1, palette, no_data))
	goto error;
    sqlite3_finalize (stmt_tiles);
    sqlite3_finalize (stmt_data);
    *buffer = bufpix;
    *buf_size = bufpix_size;
    return 1;

................................................................................
    if (bufpix != NULL)
	free (bufpix);
    return 0;
}

static void
raster_tile_124_rescaled (unsigned char *outbuf,

			  unsigned char pixel_type, const unsigned char *inbuf,
			  unsigned int section_width,
			  unsigned int section_height, unsigned int out_width,
			  unsigned int out_height, rl2PalettePtr palette)
{
/* 
/ this function builds an high quality rescaled sub-image by applying pixel interpolation
/
................................................................................
do_build_124_bit_section_pyramid (sqlite3 * handle, int max_threads,
				  const char *coverage, int mixed_resolutions,
				  sqlite3_int64 section_id,
				  unsigned char sample_type,
				  unsigned char pixel_type,
				  unsigned char num_samples, int srid,
				  unsigned int tileWidth,
				  unsigned int tileHeight, unsigned char bgRed,

				  unsigned char bgGreen, unsigned char bgBlue)
{
/* attempting to (re)build a 1,2,4-bit section pyramid from scratch */
    double base_res_x;
    double base_res_y;
    unsigned int sect_width;
    unsigned int sect_height;
    int id_level = 0;
................................................................................
      {
	  if (!find_base_resolution
	      (handle, coverage, &base_res_x, &base_res_y))
	      goto error;
      }
    if (!get_section_raw_raster_data
	(handle, max_threads, coverage, section_id, sect_width, sect_height,
	 sample_type, pixel_type, num_samples, minx, maxy, base_res_x,
	 base_res_y, &inbuf, &inbuf_size, palette, no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
	 &stmt_data))
	goto error;

    id_level = 1;
    scale = 2;
    x_res = base_res_x * 2.0;
    y_res = base_res_y * 2.0;
    while (1)
................................................................................
		    goto error;
	    }

	  for (row = 0; row < out_height; row += tileHeight)
	    {
		t_minx = minx;
		t_miny = t_maxy - (tileHeight * y_res);


		for (col = 0; col < out_width; col += tileWidth)
		  {
		      if (pixel_type == RL2_PIXEL_MONOCHROME)
			{
			    if (no_data == NULL)
				nd = NULL;
			    else
................................................................................
			    if (no_data == NULL)
				nd = NULL;
			    else
			      {
				  /* converting the NO-DATA pixel */
				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
							 RL2_PIXEL_RGB, 3);
				  rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND,

							      bgRed);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_GREEN_BAND,
							      bgGreen);
				  rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,

							      bgBlue);
			      }
			}
		      t_maxx = t_minx + (tileWidth * x_res);


		      if (!copy_124_tile
			  (out_pixel_type, outbuf, &tilebuf,
			   &tilebuf_sz, &tilemask, &tilemask_sz, row, col,
			   out_width, out_height, tileWidth, tileHeight,
			   no_data))
			{
			    fprintf (stderr,
................................................................................
		      if (raster == NULL)
			{
			    fprintf (stderr,
				     "ERROR: unable to create a Pyramid Tile\n");
			    goto error;
			}
		      if (rl2_raster_encode
			  (raster, RL2_COMPRESSION_PNG, &blob_odd, &blob_odd_sz,
			   &blob_even, &blob_even_sz, 100, 1) != RL2_OK)

			{
			    fprintf (stderr,
				     "ERROR: unable to encode a Pyramid tile\n");
			    goto error;
			}

		      /* INSERTing the tile */
................................................................................
}

static int
do_build_palette_section_pyramid (sqlite3 * handle, int max_threads,
				  const char *coverage, int mixed_resolutions,
				  sqlite3_int64 section_id, int srid,
				  unsigned int tileWidth,
				  unsigned int tileHeight, unsigned char bgRed,

				  unsigned char bgGreen, unsigned char bgBlue)
{
/* attempting to (re)build a Palette section pyramid from scratch */
    double base_res_x;
    double base_res_y;
    unsigned int sect_width;
    unsigned int sect_height;
    int id_level = 0;
................................................................................
      {
	  if (!find_base_resolution
	      (handle, coverage, &base_res_x, &base_res_y))
	      goto error;
      }
    if (!get_section_raw_raster_data
	(handle, max_threads, coverage, section_id, sect_width, sect_height,
	 RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, maxy, base_res_x,
	 base_res_y, &inbuf, &inbuf_size, palette, no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils,
	 &stmt_data))
	goto error;

    id_level = 1;
    scale = 2;
    x_res = base_res_x * 2.0;
    y_res = base_res_y * 2.0;
    while (1)
................................................................................
		    goto error;
	    }

	  for (row = 0; row < out_height; row += tileHeight)
	    {
		t_minx = minx;
		t_miny = t_maxy - (tileHeight * y_res);


		for (col = 0; col < out_width; col += tileWidth)
		  {
		      if (no_data == NULL)
			  nd = NULL;
		      else
			{
			    /* converting the NO-DATA pixel */
................................................................................
			    rl2_set_pixel_sample_uint8 (nd,
							RL2_GREEN_BAND,
							bgGreen);
			    rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,
							bgBlue);
			}
		      t_maxx = t_minx + (tileWidth * x_res);


		      if (!copy_124_tile (out_pixel_type, outbuf, &tilebuf,
					  &tilebuf_sz, &tilemask, &tilemask_sz,
					  row, col, out_width, out_height,
					  tileWidth, tileHeight, no_data))

			{
			    fprintf (stderr,
				     "ERROR: unable to extract a Pyramid Tile\n");
			    goto error;
			}

		      raster =
................................................................................
		    goto error;
	    }
	  else
	    {
		/* ordinary RGB, Grayscale, MultiBand or DataGrid Pyramid */
		if (!do_build_section_pyramid
		    (handle, coverage, section_id, sample_type, pixel_type,
		     num_bands, compression, ptrcvg->mixedResolutions, quality,
		     srid, tileWidth, tileHeight))
		    goto error;
	    }
	  if (verbose)
	    {
		printf ("  ----------\n");
#if defined(_WIN32) && !defined(__MINGW32__)
		printf
................................................................................
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;
	  if (ret == SQLITE_ROW)
	    {
		sqlite3_int64 section_id = sqlite3_column_int64 (stmt, 0);
		if (rl2_build_section_pyramid
		    (handle, max_threads, coverage, section_id, forced_rebuild,
		     verbose) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		fprintf (stderr,
			 "SELECT section_id; sqlite3_step() error: %s\n",
			 sqlite3_errmsg (handle));
................................................................................
	  out_sample_type = RL2_SAMPLE_UINT8;
	  out_pixel_type = RL2_PIXEL_RGB;
	  out_num_bands = 3;
	  out_compression = RL2_COMPRESSION_PNG;
	  out_quality = 100;
	  virt_levels = 1;
      }
    else if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE
	     && num_bands == 1)
      {
	  /* palette 8: output colorspace is RGB compression PNG */
	  out_sample_type = RL2_SAMPLE_UINT8;
	  out_pixel_type = RL2_PIXEL_RGB;
	  out_num_bands = 3;
	  out_compression = RL2_COMPRESSION_PNG;
	  out_quality = 100;
................................................................................
		      if (tile_miny < miny)
			  end_y = miny;

		      if ((sample_type == RL2_SAMPLE_UINT8
			   && pixel_type == RL2_PIXEL_GRAYSCALE
			   && num_bands == 1)
			  || (sample_type == RL2_SAMPLE_UINT8
			      && pixel_type == RL2_PIXEL_RGB && num_bands == 3)

			  || (sample_type == RL2_SAMPLE_UINT8
			      && pixel_type == RL2_PIXEL_PALETTE
			      && num_bands == 1))
			{
			    /* RGB, PALETTE or GRAYSCALE datasource (UINT8) */
			    if (!rescale_monolithic_rgba
				(id_level, tileWidth, tileHeight, resize_factor,
				 res_x, res_y, tile_minx, tile_miny,
				 tile_maxx, tile_maxy, buffer, buf_size, mask,
				 &mask_size, palette, no_data, stmt_geo,
				 stmt_rd))
				goto error;
			    if (mask_size == 0)
				mask = NULL;
			}
		      else if (((sample_type == RL2_SAMPLE_1_BIT
				 || sample_type == RL2_SAMPLE_2_BIT
				 || sample_type == RL2_SAMPLE_4_BIT)
................................................................................
		      else if (pixel_type == RL2_PIXEL_DATAGRID)
			{
			    /* DataGrid */
			    if (!rescale_monolithic_datagrid
				(id_level, tileWidth, tileHeight, sample_type,
				 resize_factor, res_x, res_y, tile_minx,
				 tile_miny, tile_maxx, tile_maxy, buffer,
				 buf_size, mask, &mask_size, no_data, stmt_geo,
				 stmt_rd))
				goto error;
			    if (mask_size == 0)
				mask = NULL;
			}
		      else
			{
			    /* unknown */
................................................................................
			{
			    if (no_data == NULL)
				nd = NULL;
			    else
			      {
				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
							 RL2_PIXEL_RGB, 3);
				  rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND,

							      255);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_GREEN_BAND,
							      255);
				  rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,

							      255);
			      }
			}
		      else
			  nd = rl2_clone_pixel (no_data);

		      raster =
................................................................................
    sqlite3_finalize (stmt_rd);
    sqlite3_finalize (stmt_levl);
    sqlite3_finalize (stmt_tils);
    sqlite3_finalize (stmt_data);
    if (verbose)
      {
	  printf ("  ----------\n");

	  printf ("    Monolithic Pyramid levels successfully built for: %s\n",
		  coverage);
      }
    free (buffer);
    free (mask);
    rl2_destroy_coverage (cvg);

    return RL2_OK;








|
|







 







>
|
|







 







|
|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|
|







 







|
|
|







 







|
|
>







 







|
|
|
>







 







|
|







 







|
|
|







 







|
|







 







>
|
|







 







|
|







 







|
|
|
>







 







|
|
|
|






|
|
|
|







 







|
|
|
>







 







|
|
|







 







|
|
>







 







|
|







 







|
>
|







 







|
|
|







 







|
|
|





|
|







 







|
|
|
>
|







 







|
|







 







>
|







 







|
|







 







|
>
|



|
|







 







>
>




>
>







 







|
>
|







 







|
>
>
>







 







|
|







 







>
|







 







|
>
|







 







|
|



|
|







 







>
>







 







|
>




|
>




>
>







 







|
|
>







 







|
>
|







 







|
|



|
|







 







>
>







 







>
>

|
|
|
>







 







|
|







 







|
|







 







|
|







 







|
>






|
|
|
|
|







 







|
|







 







|
>




|
>







 







>
|
|







255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
...
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
...
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
...
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
....
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
....
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
....
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
....
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
....
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
....
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
....
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
....
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
....
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
....
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
....
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
....
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
....
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
....
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
....
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
....
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
....
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
....
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
....
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
....
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
....
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
....
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
....
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
....
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
....
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
....
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
....
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
....
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
....
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
....
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
....
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
....
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
....
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
....
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
....
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
....
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
....
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
....
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
....
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
....
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
....
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
....
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
....
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
....
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
....
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
#endif

    table = sqlite3_mprintf ("%s_tiles", coverage);
    xtable = rl2_double_quoted_sql (table);
    sqlite3_free (table);
    sql =
	sqlite3_mprintf ("SELECT Count(*) FROM \"%s\" "
			 "WHERE section_id = %s AND pyramid_level > 0",
			 xtable, sect_id);
    free (xtable);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 1;
    while (1)
      {
................................................................................
      }
    sqlite3_finalize (stmt);
    stmt = NULL;
    if (!ok)
	goto error;

/* Coverage's palette and no-data */
    sql =
	sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages "
			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle));
	  goto error;
      }
................................................................................
	  free (tile_in);
	  tile_in = tile_in_n;
      }
    free (pyr);
}

static int
insert_tile_into_section_pyramid (SectionPyramidPtr pyr,
				  sqlite3_int64 tile_id, double minx,
				  double miny, double maxx, double maxy)
{
/* inserting a base tile into the Pyramid level */
    SectionPyramidTileInPtr tile;
    if (pyr == NULL)
	return 0;
    tile = alloc_section_pyramid_tile (tile_id, minx, miny, maxx, maxy);
    if (tile == NULL)
................................................................................
      {
	  if (tile->cx > minx && tile->cx < maxx && tile->cy > miny
	      && tile->cy < maxy)
	    {
		if (first)
		  {
		      out =
			  add_pyramid_out_tile (pyr, row, col, minx, miny,
						maxx, maxy);
		      first = 0;
		  }
		if (out != NULL)
		    add_pyramid_sub_tile (out, tile);
	    }
	  tile = tile->next;
      }
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		char *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int8 (buf_in, tileWidth, tileHeight,
					col * 8, row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
		     unsigned int tileHeight, int x, int y, unsigned char nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		unsigned char *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_uint8 (buf_in, tileWidth, tileHeight,
					 col * 8, row * 8, nd);
	    }
      }
}

static double
rescale_pixel_int16 (const short *buf_in, unsigned int tileWidth,
		     unsigned int tileHeight, int x, int y, short nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		short *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int16 (buf_in, tileWidth, tileHeight,
					 col * 8, row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, unsigned short nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		int *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_int32 (buf_in, tileWidth, tileHeight,
					 col * 8, row * 8, nd);
	    }
      }
}

static double
rescale_pixel_uint32 (const unsigned int *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, unsigned int nd)
................................................................................
	  for (col = 0; col < (unsigned int) tic_x; col++)
	    {
		unsigned int xx = col + x;
		float *p_out = p_out_base + xx;
		if (xx >= tileWidth)
		    break;
		*p_out =
		    rescale_pixel_float (buf_in, tileWidth, tileHeight,
					 col * 8, row * 8, nd);
	    }
      }
}

static double
rescale_pixel_double (const double *buf_in, unsigned int tileWidth,
		      unsigned int tileHeight, int x, int y, double nd)
................................................................................
      {
      case RL2_SAMPLE_INT8:
	  rescale_grid_int8 ((char *) buf_out, tileWidth, tileHeight,
			     (const char *) buf_in, x, y, tic_x, tic_y,
			     no_data);
	  break;
      case RL2_SAMPLE_UINT8:
	  rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth,
			      tileHeight, (const unsigned char *) buf_in, x,
			      y, tic_x, tic_y, no_data);
	  break;
      case RL2_SAMPLE_INT16:
	  rescale_grid_int16 ((short *) buf_out, tileWidth, tileHeight,
			      (const short *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_UINT16:
................................................................................
	  break;
      case RL2_SAMPLE_INT32:
	  rescale_grid_int32 ((int *) buf_out, tileWidth, tileHeight,
			      (const int *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_UINT32:
	  rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth,
			       tileHeight, (const unsigned int *) buf_in, x,
			       y, tic_x, tic_y, no_data);
	  break;
      case RL2_SAMPLE_FLOAT:
	  rescale_grid_float ((float *) buf_out, tileWidth, tileHeight,
			      (const float *) buf_in, x, y, tic_x, tic_y,
			      no_data);
	  break;
      case RL2_SAMPLE_DOUBLE:
................................................................................
				  break;
			      }
			    pos_x += geo_x;
			}
		      pos_y -= geo_y;
		  }
		rst = (rl2PrivRasterPtr) raster_in;
		rescale_grid (buf_out, tileWidth, tileHeight,
			      rst->rasterBuffer, sample_type, x, y, tic_x,
			      tic_y, no_data);
		rl2_destroy_raster (raster_in);
		raster_in = NULL;
		tile_in = tile_in->next;
	    }

	  raster_out = NULL;
	  raster_out =
................................................................................
		goto error;
	    }
	  rl2_destroy_raster (raster_out);
	  raster_out = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
	       stmt_data))
	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
    if (mask != NULL)
	free (mask);
    return 0;
}

static double
rescale_mb_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth,
			unsigned int tileHeight, unsigned int x,
			unsigned int y, unsigned char nd, unsigned char nb,
			unsigned char num_bands)
{
/* rescaling a MultiBand pixel sample (8x8) - UINT8 */
    unsigned int row;
    unsigned int col;
    int nodata = 0;
    int valid = 0;
................................................................................
				&& pxl->nBands == num_bands)
			      {
				  rl2PrivSamplePtr sample = pxl->Samples + nb;
				  nd = sample->uint8;
			      }
			}
		      *(p_out + nb) =
			  rescale_mb_pixel_uint8 (buf_in, tileWidth,
						  tileHeight, col * 8,
						  row * 8, nd, nb, num_bands);
		  }
	    }
      }
}

static double
rescale_mb_pixel_uint16 (const unsigned short *buf_in, unsigned int tileWidth,
................................................................................
			      {
				  rl2PrivSamplePtr sample = pxl->Samples + nb;
				  nd = sample->uint16;
			      }
			}
		      *(p_out + nb) =
			  rescale_mb_pixel_uint16 (buf_in, tileWidth,
						   tileHeight, col * 8,
						   row * 8, nd, nb, num_bands);
		  }
	    }
      }
}

static void
rescale_multiband (void *buf_out, unsigned int tileWidth,
................................................................................
      case RL2_SAMPLE_UINT8:
	  rescale_multiband_uint8 ((unsigned char *) buf_out, tileWidth,
				   tileHeight, (const unsigned char *) buf_in,
				   x, y, tic_x, tic_y, num_bands, no_data);
	  break;
      case RL2_SAMPLE_UINT16:
	  rescale_multiband_uint16 ((unsigned short *) buf_out, tileWidth,
				    tileHeight,
				    (const unsigned short *) buf_in, x, y,
				    tic_x, tic_y, num_bands, no_data);
	  break;
      };
}

static int
update_sect_pyramid_multiband (sqlite3 * handle, sqlite3_stmt * stmt_rd,
			       sqlite3_stmt * stmt_tils,
................................................................................
			      }
			    pos_x += geo_x;
			}
		      pos_y -= geo_y;
		  }
		rst = (rl2PrivRasterPtr) raster_in;
		rescale_multiband (buf_out, tileWidth, tileHeight,
				   rst->rasterBuffer, sample_type, num_bands,
				   x, y, tic_x, tic_y, no_data);
		rl2_destroy_raster (raster_in);
		raster_in = NULL;
		tile_in = tile_in->next;
	    }

	  raster_out = NULL;
	  raster_out =
................................................................................
		goto error;
	    }
	  rl2_destroy_raster (raster_out);
	  raster_out = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
	       stmt_data))
	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
							    0);
			}
		      compression = RL2_COMPRESSION_PNG;
		  }
		else
		    nd = rl2_clone_pixel (no_data);
		raster =
		    rl2_create_raster (tileWidth, tileHeight,
				       RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE,
				       1, gray, tileWidth * tileHeight, NULL,
				       alpha, tileWidth * tileHeight, nd);
	    }
	  else if (pyr->pixel_type == RL2_PIXEL_RGB)
	    {
		/* RGB Pyramid */
		nd = rl2_clone_pixel (no_data);
		raster =
		    rl2_create_raster (tileWidth, tileHeight,
				       RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3,
				       rgb, tileWidth * tileHeight * 3, NULL,
				       alpha, tileWidth * tileHeight, nd);
	    }
	  if (raster == NULL)
	    {
		fprintf (stderr, "ERROR: unable to create a Pyramid Tile\n");
		goto error;
	    }
	  if (rl2_raster_encode
................................................................................
	  rl2_destroy_raster (raster);
	  raster = NULL;
	  rl2_graph_destroy_context (ctx);
	  ctx = NULL;

	  /* INSERTing the tile */
	  if (!do_insert_pyramid_tile
	      (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
	       id_level, pyr->section_id, pyr->srid, tile_out->minx,
	       tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils,
	       stmt_data))
	      goto error;

	  tile_out = tile_out->next;
      }

    return 1;

................................................................................
	rl2_graph_destroy_context (ctx);
    return 0;
}

#define floor2(exp) ((long) exp)

static rl2RasterPtr
create_124_rescaled_raster (const unsigned char *rgba,
			    unsigned char pixel_type, unsigned int tileWidth,
			    unsigned int tileHeight, int scale)
{
/* creating a rescaled raster (1,2 or 4 bit pyramids) 
/
/ this function builds an high quality rescaled sub-image by applying pixel interpolation
/
/ this code is widely inspired by the original GD gdImageCopyResampled() function
*/
................................................................................
			    *p_msk = 1;
			}
		  }
	    }
      }

    raster =
	rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8,
			   pixel_type, num_bands, rgb, rgb_sz, NULL, mask,
			   mask_sz, NULL);
    return raster;
}

static void
copy_124_rescaled (rl2RasterPtr raster_out, rl2RasterPtr raster_in,
		   unsigned int base_x, unsigned int base_y)
{
................................................................................
		double tile_x = sqlite3_column_double (stmt_geo, 1);
		double tile_y = sqlite3_column_double (stmt_geo, 2);

		rgba = load_tile_base (stmt_data, tile_id, palette, no_data);
		if (rgba == NULL)
		    goto error;
		base_tile =
		    create_124_rescaled_raster (rgba, out_pixel_type,
						tileWidth, tileHeight, factor);
		free (rgba);
		if (base_tile == NULL)
		    goto error;
		shift_x = tile_x - minx;
		shift_y = maxy - tile_y;
		x = (int) (shift_x / res_x);
		y = (int) (shift_y / res_y);
................................................................................
    for (ib = 0; ib < num_bands; ib++)
	*p_out++ = (unsigned char) (*(sum + ib) / (double) valid);
    free (sum);
    *p_msk = 1;
}

static void
mb_prime_nodata_u8 (unsigned char *buf, unsigned int width,
		    unsigned int height, unsigned char num_bands,
		    rl2PixelPtr no_data)
{
/* priming a void buffer */
    rl2PrivPixelPtr nd = (rl2PrivPixelPtr) no_data;
    unsigned int x;
    unsigned int y;
    unsigned char ib;
    unsigned char *p = buf;
................................................................................
					    (unsigned char *) buf_in, mask_in,
					    (unsigned char *) buf, mask, x, y,
					    ox, oy, no_data);
		      break;
		  case RL2_SAMPLE_UINT16:
		      rescale_multiband_u16 (tileWidth, tileHeight, num_bands,
					     out_width, out_height, factor,
					     (unsigned short *) buf_in,
					     mask_in, (unsigned short *) buf,
					     mask, x, y, ox, oy, no_data);
		      break;
		  };
		ox++;
	    }
	  oy++;
      }

................................................................................
					   out_height, factor,
					   (unsigned char *) buf_in,
					   (unsigned char *) buf, mask, x, y,
					   ox, oy, no_data_u8);
		      break;
		  case RL2_SAMPLE_INT16:
		      rescale_datagrid_16 (tileWidth, tileHeight, out_width,
					   out_height, factor,
					   (short *) buf_in, (short *) buf,
					   mask, x, y, ox, oy, no_data_16);
		      break;
		  case RL2_SAMPLE_UINT16:
		      rescale_datagrid_u16 (tileWidth, tileHeight, out_width,
					    out_height, factor,
					    (unsigned short *) buf_in,
					    (unsigned short *) buf, mask, x,
					    y, ox, oy, no_data_u16);
		      break;
		  case RL2_SAMPLE_INT32:
		      rescale_datagrid_32 (tileWidth, tileHeight, out_width,
					   out_height, factor, (int *) buf_in,
					   (int *) buf, mask, x, y, ox, oy,
					   no_data_32);
		      break;
................................................................................
    return raster;
}

static int
rescale_monolithic_multiband (int id_level,
			      unsigned int tileWidth, unsigned int tileHeight,
			      unsigned char sample_type,
			      unsigned char num_bands, int factor,
			      double res_x, double res_y, double minx,
			      double miny, double maxx, double maxy,
			      unsigned char *buffer, int buf_size,
			      unsigned char *mask, int *mask_size,
			      rl2PixelPtr no_data, sqlite3_stmt * stmt_geo,
			      sqlite3_stmt * stmt_data)
{
/* rescaling monolithic MultiBand */
    rl2RasterPtr raster = NULL;
    rl2RasterPtr base_tile = NULL;
    rl2PrivRasterPtr rst;
................................................................................
    p_out = mask;
    for (y = 0; y < tileHeight; y++)
      {
	  /* priming full transparency */
	  for (x = 0; x < tileWidth; x++)
	      *p_out++ = 0;
      }
    rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type,
			 num_bands, no_data);
/* creating the output raster */
    raster =
	rl2_create_raster (tileWidth, tileHeight, sample_type,
			   RL2_PIXEL_MULTIBAND, num_bands, buffer, buf_size,
			   NULL, mask, *mask_size, nd);
    if (raster == NULL)
	goto error;
................................................................................
	  rl2_destroy_raster (raster);
      }
    return 0;
}

static int
prepare_section_pyramid_stmts (sqlite3 * handle, const char *coverage,
			       int mixed_resolutions,
			       sqlite3_stmt ** xstmt_rd,
			       sqlite3_stmt ** xstmt_levl,
			       sqlite3_stmt ** xstmt_tils,
			       sqlite3_stmt ** xstmt_data)
{
/* preparing the section pyramid related SQL statements */
    char *table_tile_data;
    char *xtable_tile_data;
................................................................................

    if (!get_section_infos
	(handle, coverage, section_id, &sect_width, &sect_height, &minx,
	 &miny, &maxx, &maxy, &palette, &no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
	 &stmt_tils, &stmt_data))
	goto error;

    while (1)
      {
	  /* looping on pyramid levels */
	  if (mixed_resolutions)
	      table_levels = sqlite3_mprintf ("%s_section_levels", coverage);
................................................................................
		      scale = 8;
		      if (first)
			{
			    pyr =
				alloc_sect_pyramid (section_id, sect_width,
						    sect_height, sample_type,
						    pixel_type, num_samples,
						    compression, quality,
						    srid, new_res_x,
						    new_res_y,
						    (double) tileWidth *
						    new_res_x,
						    (double) tileHeight *
						    new_res_y, minx, miny,
						    maxx, maxy, scale);
			    first = 0;
			    if (pyr == NULL)
				goto error;
			}
		      if (!insert_tile_into_section_pyramid
			  (pyr, tile_id, tminx, tminy, tmaxx, tmaxy))
			  goto error;
................................................................................
	  if (pyr == NULL)
	      goto error;

	  out_maxy = maxy;
	  for (row = 0; row < pyr->scaled_height; row += tileHeight)
	    {
		out_miny = out_maxy - pyr->tile_height;
		if (out_miny < miny)
		    out_miny = miny;
		out_minx = minx;
		for (col = 0; col < pyr->scaled_width; col += tileWidth)
		  {
		      out_maxx = out_minx + pyr->tile_width;
		      if (out_maxx > maxx)
			  out_maxx = maxx;
		      set_pyramid_tile_destination (pyr, out_minx, out_miny,
						    out_maxx, out_maxy, row,
						    col);
		      out_minx += pyr->tile_width;
		  }
		out_maxy -= pyr->tile_height;
	    }
................................................................................
}

static int
get_section_raw_raster_data (sqlite3 * handle, int max_threads,
			     const char *coverage, sqlite3_int64 sect_id,
			     unsigned int width, unsigned int height,
			     unsigned char sample_type,
			     unsigned char pixel_type,
			     unsigned char num_bands, double minx, double miny,
			     double maxx, double maxy, double x_res,
			     double y_res, unsigned char **buffer,
			     int *buf_size, rl2PalettePtr palette,
			     rl2PixelPtr no_data)
{
/* attempting to return a buffer containing raw pixels from the whole DBMS Section */
    unsigned char *bufpix = NULL;
    int bufpix_size;
................................................................................

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    sql =
	sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
			 "FROM \"%s\" "
			 "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( "
			 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
			 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles,
			 xtiles);
    sqlite3_free (xtiles);
    free (xxtiles);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT section raw tiles SQL error: %s\n",
................................................................................
    if (pixel_type == RL2_PIXEL_PALETTE)
	void_raw_buffer_palette (bufpix, width, height, no_data);
    else
	void_raw_buffer (bufpix, width, height, sample_type, num_bands,
			 no_data);
    if (!rl2_load_dbms_tiles_section
	(handle, max_threads, sect_id, stmt_tiles, stmt_data, bufpix, width,
	 height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, miny,
	 maxx, maxy, 0, RL2_SCALE_1, palette, no_data))
	goto error;
    sqlite3_finalize (stmt_tiles);
    sqlite3_finalize (stmt_data);
    *buffer = bufpix;
    *buf_size = bufpix_size;
    return 1;

................................................................................
    if (bufpix != NULL)
	free (bufpix);
    return 0;
}

static void
raster_tile_124_rescaled (unsigned char *outbuf,
			  unsigned char pixel_type,
			  const unsigned char *inbuf,
			  unsigned int section_width,
			  unsigned int section_height, unsigned int out_width,
			  unsigned int out_height, rl2PalettePtr palette)
{
/* 
/ this function builds an high quality rescaled sub-image by applying pixel interpolation
/
................................................................................
do_build_124_bit_section_pyramid (sqlite3 * handle, int max_threads,
				  const char *coverage, int mixed_resolutions,
				  sqlite3_int64 section_id,
				  unsigned char sample_type,
				  unsigned char pixel_type,
				  unsigned char num_samples, int srid,
				  unsigned int tileWidth,
				  unsigned int tileHeight,
				  unsigned char bgRed, unsigned char bgGreen,
				  unsigned char bgBlue)
{
/* attempting to (re)build a 1,2,4-bit section pyramid from scratch */
    double base_res_x;
    double base_res_y;
    unsigned int sect_width;
    unsigned int sect_height;
    int id_level = 0;
................................................................................
      {
	  if (!find_base_resolution
	      (handle, coverage, &base_res_x, &base_res_y))
	      goto error;
      }
    if (!get_section_raw_raster_data
	(handle, max_threads, coverage, section_id, sect_width, sect_height,
	 sample_type, pixel_type, num_samples, minx, miny, maxx, maxy,
	 base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
	 &stmt_tils, &stmt_data))
	goto error;

    id_level = 1;
    scale = 2;
    x_res = base_res_x * 2.0;
    y_res = base_res_y * 2.0;
    while (1)
................................................................................
		    goto error;
	    }

	  for (row = 0; row < out_height; row += tileHeight)
	    {
		t_minx = minx;
		t_miny = t_maxy - (tileHeight * y_res);
		if (t_miny < miny)
		    t_miny = miny;
		for (col = 0; col < out_width; col += tileWidth)
		  {
		      if (pixel_type == RL2_PIXEL_MONOCHROME)
			{
			    if (no_data == NULL)
				nd = NULL;
			    else
................................................................................
			    if (no_data == NULL)
				nd = NULL;
			    else
			      {
				  /* converting the NO-DATA pixel */
				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
							 RL2_PIXEL_RGB, 3);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_RED_BAND,
							      bgRed);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_GREEN_BAND,
							      bgGreen);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_BLUE_BAND,
							      bgBlue);
			      }
			}
		      t_maxx = t_minx + (tileWidth * x_res);
		      if (t_maxx > maxx)
			  t_maxx = maxx;
		      if (!copy_124_tile
			  (out_pixel_type, outbuf, &tilebuf,
			   &tilebuf_sz, &tilemask, &tilemask_sz, row, col,
			   out_width, out_height, tileWidth, tileHeight,
			   no_data))
			{
			    fprintf (stderr,
................................................................................
		      if (raster == NULL)
			{
			    fprintf (stderr,
				     "ERROR: unable to create a Pyramid Tile\n");
			    goto error;
			}
		      if (rl2_raster_encode
			  (raster, RL2_COMPRESSION_PNG, &blob_odd,
			   &blob_odd_sz, &blob_even, &blob_even_sz, 100,
			   1) != RL2_OK)
			{
			    fprintf (stderr,
				     "ERROR: unable to encode a Pyramid tile\n");
			    goto error;
			}

		      /* INSERTing the tile */
................................................................................
}

static int
do_build_palette_section_pyramid (sqlite3 * handle, int max_threads,
				  const char *coverage, int mixed_resolutions,
				  sqlite3_int64 section_id, int srid,
				  unsigned int tileWidth,
				  unsigned int tileHeight,
				  unsigned char bgRed, unsigned char bgGreen,
				  unsigned char bgBlue)
{
/* attempting to (re)build a Palette section pyramid from scratch */
    double base_res_x;
    double base_res_y;
    unsigned int sect_width;
    unsigned int sect_height;
    int id_level = 0;
................................................................................
      {
	  if (!find_base_resolution
	      (handle, coverage, &base_res_x, &base_res_y))
	      goto error;
      }
    if (!get_section_raw_raster_data
	(handle, max_threads, coverage, section_id, sect_width, sect_height,
	 RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, miny, maxx, maxy,
	 base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data))
	goto error;

    if (!prepare_section_pyramid_stmts
	(handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl,
	 &stmt_tils, &stmt_data))
	goto error;

    id_level = 1;
    scale = 2;
    x_res = base_res_x * 2.0;
    y_res = base_res_y * 2.0;
    while (1)
................................................................................
		    goto error;
	    }

	  for (row = 0; row < out_height; row += tileHeight)
	    {
		t_minx = minx;
		t_miny = t_maxy - (tileHeight * y_res);
		if (t_miny < miny)
		    t_miny = miny;
		for (col = 0; col < out_width; col += tileWidth)
		  {
		      if (no_data == NULL)
			  nd = NULL;
		      else
			{
			    /* converting the NO-DATA pixel */
................................................................................
			    rl2_set_pixel_sample_uint8 (nd,
							RL2_GREEN_BAND,
							bgGreen);
			    rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND,
							bgBlue);
			}
		      t_maxx = t_minx + (tileWidth * x_res);
		      if (t_maxx > maxx)
			  t_maxx = maxx;
		      if (!copy_124_tile (out_pixel_type, outbuf, &tilebuf,
					  &tilebuf_sz, &tilemask,
					  &tilemask_sz, row, col, out_width,
					  out_height, tileWidth, tileHeight,
					  no_data))
			{
			    fprintf (stderr,
				     "ERROR: unable to extract a Pyramid Tile\n");
			    goto error;
			}

		      raster =
................................................................................
		    goto error;
	    }
	  else
	    {
		/* ordinary RGB, Grayscale, MultiBand or DataGrid Pyramid */
		if (!do_build_section_pyramid
		    (handle, coverage, section_id, sample_type, pixel_type,
		     num_bands, compression, ptrcvg->mixedResolutions,
		     quality, srid, tileWidth, tileHeight))
		    goto error;
	    }
	  if (verbose)
	    {
		printf ("  ----------\n");
#if defined(_WIN32) && !defined(__MINGW32__)
		printf
................................................................................
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;
	  if (ret == SQLITE_ROW)
	    {
		sqlite3_int64 section_id = sqlite3_column_int64 (stmt, 0);
		if (rl2_build_section_pyramid
		    (handle, max_threads, coverage, section_id,
		     forced_rebuild, verbose) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		fprintf (stderr,
			 "SELECT section_id; sqlite3_step() error: %s\n",
			 sqlite3_errmsg (handle));
................................................................................
	  out_sample_type = RL2_SAMPLE_UINT8;
	  out_pixel_type = RL2_PIXEL_RGB;
	  out_num_bands = 3;
	  out_compression = RL2_COMPRESSION_PNG;
	  out_quality = 100;
	  virt_levels = 1;
      }
    else if (sample_type == RL2_SAMPLE_UINT8
	     && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1)
      {
	  /* palette 8: output colorspace is RGB compression PNG */
	  out_sample_type = RL2_SAMPLE_UINT8;
	  out_pixel_type = RL2_PIXEL_RGB;
	  out_num_bands = 3;
	  out_compression = RL2_COMPRESSION_PNG;
	  out_quality = 100;
................................................................................
		      if (tile_miny < miny)
			  end_y = miny;

		      if ((sample_type == RL2_SAMPLE_UINT8
			   && pixel_type == RL2_PIXEL_GRAYSCALE
			   && num_bands == 1)
			  || (sample_type == RL2_SAMPLE_UINT8
			      && pixel_type == RL2_PIXEL_RGB
			      && num_bands == 3)
			  || (sample_type == RL2_SAMPLE_UINT8
			      && pixel_type == RL2_PIXEL_PALETTE
			      && num_bands == 1))
			{
			    /* RGB, PALETTE or GRAYSCALE datasource (UINT8) */
			    if (!rescale_monolithic_rgba
				(id_level, tileWidth, tileHeight,
				 resize_factor, res_x, res_y, tile_minx,
				 tile_miny, tile_maxx, tile_maxy, buffer,
				 buf_size, mask, &mask_size, palette, no_data,
				 stmt_geo, stmt_rd))
				goto error;
			    if (mask_size == 0)
				mask = NULL;
			}
		      else if (((sample_type == RL2_SAMPLE_1_BIT
				 || sample_type == RL2_SAMPLE_2_BIT
				 || sample_type == RL2_SAMPLE_4_BIT)
................................................................................
		      else if (pixel_type == RL2_PIXEL_DATAGRID)
			{
			    /* DataGrid */
			    if (!rescale_monolithic_datagrid
				(id_level, tileWidth, tileHeight, sample_type,
				 resize_factor, res_x, res_y, tile_minx,
				 tile_miny, tile_maxx, tile_maxy, buffer,
				 buf_size, mask, &mask_size, no_data,
				 stmt_geo, stmt_rd))
				goto error;
			    if (mask_size == 0)
				mask = NULL;
			}
		      else
			{
			    /* unknown */
................................................................................
			{
			    if (no_data == NULL)
				nd = NULL;
			    else
			      {
				  nd = rl2_create_pixel (RL2_SAMPLE_UINT8,
							 RL2_PIXEL_RGB, 3);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_RED_BAND,
							      255);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_GREEN_BAND,
							      255);
				  rl2_set_pixel_sample_uint8 (nd,
							      RL2_BLUE_BAND,
							      255);
			      }
			}
		      else
			  nd = rl2_clone_pixel (no_data);

		      raster =
................................................................................
    sqlite3_finalize (stmt_rd);
    sqlite3_finalize (stmt_levl);
    sqlite3_finalize (stmt_tils);
    sqlite3_finalize (stmt_data);
    if (verbose)
      {
	  printf ("  ----------\n");
	  printf
	      ("    Monolithic Pyramid levels successfully built for: %s\n",
	       coverage);
      }
    free (buffer);
    free (mask);
    rl2_destroy_coverage (cvg);

    return RL2_OK;

Changes to src/rl2rastersym.c.

690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
...
707
708
709
710
711
712
713
714

715
716
717
718
719
720
721
...
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
...
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772
773
774
775
776
777
778
779
...
818
819
820
821
822
823
824











825
826
827
828
829
830
831

832
833
834

835
836
837

838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858

859
860
861
862
863
864
865
...
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896
...
965
966
967
968
969
970
971
972

973
974
975
976
977
978
979
...
993
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
....
1020
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
....
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
....
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
....
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
....
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
....
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
....
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
....
3893
3894
3895
3896
3897
3898
3899
3900

3901
3902
3903
3904
3905
3906
3907
3908
3909
....
4157
4158
4159
4160
4161
4162
4163
4164

4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
....
4181
4182
4183
4184
4185
4186
4187
4188

4189
4190
4191
4192
4193
4194
4195
....
4222
4223
4224
4225
4226
4227
4228
4229
4230

4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241

4242
4243
4244
4245
4246
4247
4248
4249
4250
....
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
....
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297

4298
4299
4300
4301
4302
4303
4304
....
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
....
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353

4354
4355
4356
4357
4358
4359
4360
4361
4362
4363

4364
4365
4366
4367






































































4368
4369
4370
4371
4372
4373
4374
....
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
....
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
....
4937
4938
4939
4940
4941
4942
4943
4944

4945

4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
....
4981
4982
4983
4984
4985
4986
4987

4988
4989
4990
4991
4992
4993
4994
4995
....
4996
4997
4998
4999
5000
5001
5002

5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
....
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
			    for (ib = 0; ib < out_num_bands; ib++)
				p_out++;
			}
		      else
			{
			    /* opaque pixel */
			    p_out =
				mono_int8_pixel_handler (p_in, p_out, mono_band,

							 mono_handling);
			}
		  }
		else
		  {
		      /* testing for NO-DATA values */
		      int match = 0;
................................................................................
		      rl2_get_pixel_sample_int8 (no_data, &sample);
		      if (sample == *p_save++)
			  match++;
		      if (match != 1)
			{
			    /* opaque pixel */
			    p_out =
				mono_int8_pixel_handler (p_in, p_out, mono_band,

							 mono_handling);
			}
		      else
			{
			    /* NO-DATA pixel */
			    for (ib = 0; ib < out_num_bands; ib++)
				p_out++;
................................................................................
static void
copy_uint8_raw_pixels (const unsigned char *buffer, const unsigned char *mask,
		       unsigned char *outbuf, unsigned short width,
		       unsigned short height, unsigned char num_bands,
		       double x_res, double y_res, double minx, double maxy,
		       double tile_minx, double tile_maxy,
		       unsigned short tile_width, unsigned short tile_height,
		       rl2PixelPtr no_data)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
    int b;
    int out_x;
    int out_y;
................................................................................
      {
	  ignore_no_data = 0;
	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
	      != RL2_OK)
	      ignore_no_data = 1;
	  if (nbands != num_bands)
	      ignore_no_data = 1;
	  if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT

	      || sample_type == RL2_SAMPLE_4_BIT
	      || sample_type == RL2_SAMPLE_UINT8)
	      ;
	  else
	      ignore_no_data = 1;
      }

    geo_y = tile_maxy + y_res2;
    for (y = 0; y < tile_height; y++)
      {
	  geo_y -= y_res;
	  out_y = (maxy - geo_y) / y_res;
	  if (out_y < 0 || out_y >= height)
	    {
................................................................................
			}
		  }
		else
		  {
		      /* testing for NO-DATA values */
		      int match = 0;
		      const unsigned char *p_save = p_in;











		      for (b = 0; b < num_bands; b++)
			{
			    unsigned char sample = 0;
			    switch (sample_type)
			      {
			      case RL2_SAMPLE_1_BIT:
				  rl2_get_pixel_sample_1bit (no_data, &sample);

				  break;
			      case RL2_SAMPLE_2_BIT:
				  rl2_get_pixel_sample_2bit (no_data, &sample);

				  break;
			      case RL2_SAMPLE_4_BIT:
				  rl2_get_pixel_sample_4bit (no_data, &sample);

				  break;
			      case RL2_SAMPLE_UINT8:
				  rl2_get_pixel_sample_uint8 (no_data, b,
							      &sample);
				  break;
			      };
			    if (sample == *p_in++)
				match++;
			}
		      if (match != num_bands)
			{
			    /* opaque pixel */
			    p_in = p_save;
			    for (b = 0; b < num_bands; b++)
				*p_out++ = *p_in++;
			}
		      else
			{
			    /* NO-DATA pixel */
			    for (b = 0; b < num_bands; b++)
				p_out++;

			}
		  }
	    }
      }
}

static unsigned char *
................................................................................
    return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
}

static void
copy_uint8_raw_selected_pixels (const unsigned char *buffer,
				const unsigned char *mask,
				unsigned char *outbuf, unsigned short width,
				unsigned short height, unsigned char num_bands,

				double x_res, double y_res, double minx,
				double maxy, double tile_minx, double tile_maxy,
				unsigned short tile_width,
				unsigned short tile_height, rl2PixelPtr no_data,
				unsigned char red_band,
				unsigned char green_band,
				unsigned char blue_band,
				rl2BandHandlingPtr red_handling,
				rl2BandHandlingPtr green_handling,
				rl2BandHandlingPtr blue_handling)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
................................................................................
			    /* skipping a transparent pixel */
			    p_out += 3;
			}
		      else
			{
			    /* opaque pixel */
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out, red_band,

							  red_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  green_band,
							  green_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
			    if (sample == *p_save++)
				match++;
			}
		      if (match != num_bands)
			{
			    /* opaque pixel */
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out, red_band,

							  red_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  green_band,
							  green_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
}

static void
copy_uint8_raw_mono_pixels (const unsigned char *buffer,
			    const unsigned char *mask, unsigned char *outbuf,
			    unsigned short width, unsigned short height,
			    unsigned char out_num_bands,
			    unsigned char num_bands, double x_res, double y_res,
			    double minx, double maxy, double tile_minx,

			    double tile_maxy, unsigned short tile_width,
			    unsigned short tile_height, rl2PixelPtr no_data,
			    unsigned char mono_band,
			    rl2BandHandlingPtr mono_handling)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
................................................................................
		  }
		p_in++;
	    }
      }
}

static void
copy_uint16_raw_pixels (const unsigned short *buffer, const unsigned char *mask,
			unsigned short *outbuf, unsigned short width,
			unsigned short height, unsigned char num_bands,
			double x_res, double y_res, double minx, double maxy,
			double tile_minx, double tile_maxy,
			unsigned short tile_width, unsigned short tile_height,
			rl2PixelPtr no_data)
{
/* copying UINT16 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
    int b;
    int out_x;
    int out_y;
................................................................................
    return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
}

static void
copy_uint16_raw_selected_pixels (const unsigned short *buffer,
				 const unsigned char *mask,
				 unsigned char *outbuf, unsigned short width,
				 unsigned short height, unsigned char num_bands,

				 double x_res, double y_res, double minx,
				 double maxy, double tile_minx,
				 double tile_maxy, unsigned short tile_width,
				 unsigned short tile_height,
				 rl2PixelPtr no_data, unsigned char red_band,
				 unsigned char green_band,
				 unsigned char blue_band,
				 rl2BandHandlingPtr red_handling,
				 rl2BandHandlingPtr green_handling,
				 rl2BandHandlingPtr blue_handling)
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      r = malloc (sizeof (rl2BandHandling));
		      r->colorMap = NULL;
		      r->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(r->minValue), &(r->maxValue),
					  &(r->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      r = malloc (sizeof (rl2BandHandling));
		      r->colorMap = NULL;
		      r->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(g->minValue), &(g->maxValue),
					  &(g->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      b = malloc (sizeof (rl2BandHandling));
		      b->colorMap = NULL;
		      b->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(b->minValue), &(b->maxValue),
					  &(b->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      b = malloc (sizeof (rl2BandHandling));
		      b->colorMap = NULL;
		      b->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(g->minValue), &(g->maxValue),
					  &(g->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
}

static int
do_copy_raw_selected_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
			     unsigned int width, unsigned int height,
			     double x_res, double y_res, double minx,
			     double maxy, double tile_minx, double tile_maxy,
			     unsigned int tile_width, unsigned int tile_height,

			     rl2PixelPtr no_data, unsigned char red_band,
			     unsigned char green_band, unsigned char blue_band,
			     rl2BandHandlingPtr red_handling,
			     rl2BandHandlingPtr green_handling,
			     rl2BandHandlingPtr blue_handling)
{
    switch (rst->sampleType)
      {
      case RL2_SAMPLE_UINT8:
................................................................................
      };
    return 0;
}

static int
do_copy_raw_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
		    unsigned int width, unsigned int height,
		    unsigned char sample_type, unsigned char num_bands,

		    double x_res, double y_res, double minx, double maxy,
		    double tile_minx, double tile_maxy, unsigned int tile_width,
		    unsigned int tile_height, rl2PixelPtr no_data)
{


    switch (sample_type)
      {
      case RL2_SAMPLE_INT8:
	  copy_int8_raw_pixels ((const char *) (rst->rasterBuffer),
				(const unsigned char *) (rst->maskBuffer),
				(char *) outbuf, width, height,
				x_res, y_res, minx, maxy, tile_minx,
................................................................................
	  copy_int16_raw_pixels ((const short *) (rst->rasterBuffer),
				 (const unsigned char *) (rst->maskBuffer),
				 (short *) outbuf, width, height,
				 x_res, y_res, minx, maxy, tile_minx,
				 tile_maxy, tile_width, tile_height, no_data);
	  return 1;
      case RL2_SAMPLE_UINT16:
	  copy_uint16_raw_pixels ((const unsigned short *) (rst->rasterBuffer),

				  (const unsigned char *) (rst->maskBuffer),
				  (unsigned short *) outbuf, width, height,
				  num_bands, x_res, y_res, minx, maxy,
				  tile_minx, tile_maxy, tile_width,
				  tile_height, no_data);
	  return 1;
      case RL2_SAMPLE_INT32:
................................................................................
				  tile_minx, tile_maxy, tile_width,
				  tile_height, no_data);
	  return 1;
      default:
	  copy_uint8_raw_pixels ((const unsigned char *) (rst->rasterBuffer),
				 (const unsigned char *) (rst->maskBuffer),
				 (unsigned char *) outbuf, width, height,
				 num_bands, x_res, y_res, minx, maxy, tile_minx,
				 tile_maxy, tile_width, tile_height, no_data);

	  return 1;
      };
    return 0;
}

RL2_PRIVATE int
rl2_copy_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
		     unsigned int width,
		     unsigned int height, unsigned char sample_type,
		     unsigned char num_bands, unsigned char auto_ndvi,
		     unsigned char red_band_index, unsigned char nir_band_index,

		     double x_res, double y_res, double minx, double maxy,
		     double tile_minx, double tile_maxy, rl2PixelPtr no_data,
		     rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats)
{
/* copying raw pixels into the output buffer */
    unsigned int tile_width;
    unsigned int tile_height;
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;

................................................................................
	return 0;
    if (style != NULL && stats != NULL)
      {
	  /* attempting to apply a RasterSymbolizer */
	  int yes_no;
	  int categorize;
	  int interpolate;
	  if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no) ==
	      RL2_OK)
	    {
		if ((rst->sampleType == RL2_SAMPLE_UINT8
		     || rst->sampleType == RL2_SAMPLE_UINT16)
		    && (rst->pixelType == RL2_PIXEL_RGB
			|| rst->pixelType == RL2_PIXEL_MULTIBAND) && yes_no)
		  {
		      /* triple band selection - false color RGB */
................................................................................
						  blue_band, &red_handling,
						  &green_handling,
						  &blue_handling);
		      if (red_handling == NULL || green_handling == NULL
			  || blue_handling == NULL)
			  return 0;
		      if (do_copy_raw_selected_pixels
			  (rst, outbuf, width, height, x_res, y_res, minx, maxy,
			   tile_minx, tile_maxy, tile_width, tile_height,
			   no_data, red_band, green_band, blue_band,
			   red_handling, green_handling, blue_handling))

			  return 1;
		      if (red_handling != NULL)
			  free (red_handling);
		      if (green_handling != NULL)
			  free (green_handling);
		      if (blue_handling != NULL)
			  free (blue_handling);
................................................................................
		      /* applying Auto NDVI */
		      rl2BandHandlingPtr ndvi_handling = NULL;
		      build_ndvi_handling ((rl2PrivRasterSymbolizerPtr)
					   style, &ndvi_handling);
		      if (ndvi_handling == NULL)
			  return 0;
		      if (do_auto_ndvi_pixels
			  (rst, outbuf, width, height, num_bands, x_res, y_res,
			   minx, maxy, tile_minx, tile_maxy, tile_width,
			   tile_height, no_data, red_band_index, nir_band_index,
			   ndvi_handling))
			  return 1;
		      if (ndvi_handling != NULL)
			  destroy_ndvi_handling (ndvi_handling);
		  }
		if (((rst->sampleType == RL2_SAMPLE_UINT8
		      || rst->sampleType == RL2_SAMPLE_UINT16)
		     || rst->pixelType == RL2_PIXEL_DATAGRID) && yes_no)
................................................................................
						style,
						(rl2PrivRasterStatisticsPtr)
						stats, mono_band,
						&mono_handling);
		      if (mono_handling == NULL)
			  return 0;
		      if (do_copy_raw_mono_pixels
			  (rst, outbuf, width, height, num_bands, x_res, y_res,
			   minx, maxy, tile_minx, tile_maxy, tile_width,
			   tile_height, no_data, mono_band, mono_handling))

			  return 1;
		      if (mono_handling != NULL)
			  destroy_mono_handling (mono_handling);
		  }
	    }
      }

    if (do_copy_raw_pixels
	(rst, outbuf, width, height, sample_type, num_bands, x_res, y_res, minx,
	 maxy, tile_minx, tile_maxy, tile_width, tile_height, no_data))

	return 1;

    return 0;
}







































































static void
get_int8_ennuple (const char *rawbuf, unsigned short row, unsigned short col,
		  unsigned short row_stride, rl2PixelPtr no_data,
		  double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - INT8 */
................................................................................
	  /* checking for NoData values */
	  if (ennuple[i] == nd_val)
	      *has_no_data = 1;
      }
}

static void
get_int16_ennuple (const short *rawbuf, unsigned short row, unsigned short col,
		   unsigned short row_stride, rl2PixelPtr no_data,
		   double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - INT16 */
    const short *p_in;
    short nd_val = 0;
    int i;

    if (no_data != NULL)
................................................................................
	  /* checking for NoData values */
	  if (ennuple[i] == nd_val)
	      *has_no_data = 1;
      }
}

static void
get_float_ennuple (const float *rawbuf, unsigned short row, unsigned short col,
		   unsigned short row_stride, rl2PixelPtr no_data,
		   double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - FLOAT */
    const float *p_in;
    float nd_val = 0.0;
    int i;

    if (no_data != NULL)
................................................................................
	      free (shadower->opaque_thread_id);
	  shadower->opaque_thread_id = NULL;
      }
}

RL2_PRIVATE int
rl2_build_shaded_relief_mask (sqlite3 * handle, int max_threads,
			      rl2CoveragePtr cvg, double relief_factor,

			      double scale_factor, unsigned int width,

			      unsigned int height, double minx, double miny,
			      double maxx, double maxy, double x_res,
			      double y_res, float **shaded_relief,
			      int *shaded_relief_sz)
{
/* attempting to return a Shaded Relief mask from the DBMS Coverage */
    rl2PixelPtr no_data = NULL;
    const char *coverage;
    unsigned char level;
    unsigned char scale;
    double xx_res = x_res;
................................................................................

    if (cvg == NULL || handle == NULL)
	goto error;
    coverage = rl2_get_coverage_name (cvg);
    if (coverage == NULL)
	goto error;
    if (rl2_find_matching_resolution

	(handle, cvg, 0, 0, &xx_res, &yy_res, &level, &scale) != RL2_OK)
	goto error;
    if (rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands) !=
	RL2_OK)
	goto error;
    if (pixel_type != RL2_PIXEL_DATAGRID && num_bands != 1)
	goto error;
    no_data = rl2_get_coverage_no_data (cvg);
................................................................................
    if (no_data == NULL)
	goto error;

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    sql =

	sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "
			 "FROM \"%s\" "
			 "WHERE pyramid_level = ? AND ROWID IN ( "
			 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
			 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles,
			 xtiles);
    sqlite3_free (xtiles);
    free (xxtiles);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT shadedRelief tiles SQL error: %s\n",
................................................................................
	  /* executing in a single thread */
	  p_out = sr_mask;
	  for (row = 0; row < height; row++)
	    {
		for (col = 0; col < width; col++)
		    *p_out++ =
			shaded_relief_value (relief_factor, scale_factor,
					     altRadians, azRadians, rawbuf, row,
					     col, row_stride, sample_type,
					     no_data);
	    }
      }
    else
      {
	  /* executing as many concurrent threads */
	  rl2AuxShadowerPtr aux = NULL;
	  rl2AuxShadowerPtr shadower;







|
>







 







|
>







 







|







 







|
>






<







 







>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
>
|
|
|
>
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







 







|
>
|
|

|
|







 







|
>







 







|
>







 







|
|
>
|







 







|
|
|
|
|
|
|







 







|
>
|
|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
>
|
|







 







|
>
|
|


<
<







 







|
>







 







|
|
>










|
>
|
|







 







|
|







 







|
|
|
|
>







 







|
|
|
|







 







|
|
|
>








|
|
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|







 







|
|
|







 







|
>
|
>
|
|
<
|







 







>
|







 







>
|
<
|
|
|
<







 







|
|
|







690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
...
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
...
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
...
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
...
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
...
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
....
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
....
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
....
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
....
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
....
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
....
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
....
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
....
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
....
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
....
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192


4193
4194
4195
4196
4197
4198
4199
....
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
....
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
....
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
....
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
....
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
....
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
....
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
....
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
....
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047

5048
5049
5050
5051
5052
5053
5054
5055
....
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
....
5096
5097
5098
5099
5100
5101
5102
5103
5104

5105
5106
5107

5108
5109
5110
5111
5112
5113
5114
....
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
			    for (ib = 0; ib < out_num_bands; ib++)
				p_out++;
			}
		      else
			{
			    /* opaque pixel */
			    p_out =
				mono_int8_pixel_handler (p_in, p_out,
							 mono_band,
							 mono_handling);
			}
		  }
		else
		  {
		      /* testing for NO-DATA values */
		      int match = 0;
................................................................................
		      rl2_get_pixel_sample_int8 (no_data, &sample);
		      if (sample == *p_save++)
			  match++;
		      if (match != 1)
			{
			    /* opaque pixel */
			    p_out =
				mono_int8_pixel_handler (p_in, p_out,
							 mono_band,
							 mono_handling);
			}
		      else
			{
			    /* NO-DATA pixel */
			    for (ib = 0; ib < out_num_bands; ib++)
				p_out++;
................................................................................
static void
copy_uint8_raw_pixels (const unsigned char *buffer, const unsigned char *mask,
		       unsigned char *outbuf, unsigned short width,
		       unsigned short height, unsigned char num_bands,
		       double x_res, double y_res, double minx, double maxy,
		       double tile_minx, double tile_maxy,
		       unsigned short tile_width, unsigned short tile_height,
		       rl2PixelPtr no_data, unsigned char raster_type)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
    int b;
    int out_x;
    int out_y;
................................................................................
      {
	  ignore_no_data = 0;
	  if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands)
	      != RL2_OK)
	      ignore_no_data = 1;
	  if (nbands != num_bands)
	      ignore_no_data = 1;
	  if (sample_type == RL2_SAMPLE_1_BIT
	      || sample_type == RL2_SAMPLE_2_BIT
	      || sample_type == RL2_SAMPLE_4_BIT
	      || sample_type == RL2_SAMPLE_UINT8)
	      ;
	  else
	      ignore_no_data = 1;
      }

    geo_y = tile_maxy + y_res2;
    for (y = 0; y < tile_height; y++)
      {
	  geo_y -= y_res;
	  out_y = (maxy - geo_y) / y_res;
	  if (out_y < 0 || out_y >= height)
	    {
................................................................................
			}
		  }
		else
		  {
		      /* testing for NO-DATA values */
		      int match = 0;
		      const unsigned char *p_save = p_in;
		      if (raster_type == RL2_SAMPLE_1_BIT && num_bands == 1)
			{
			    /* special case: MONOCHROME */
			    if (*p_in++ == 1)
				*p_out++ = 0;
			    else
				p_out++;
			    match++;
			}
		      else
			{
			    for (b = 0; b < num_bands; b++)
			      {
				  unsigned char sample = 0;
				  switch (sample_type)
				    {
				    case RL2_SAMPLE_1_BIT:
					rl2_get_pixel_sample_1bit (no_data,
								   &sample);
					break;
				    case RL2_SAMPLE_2_BIT:
					rl2_get_pixel_sample_2bit (no_data,
								   &sample);
					break;
				    case RL2_SAMPLE_4_BIT:
					rl2_get_pixel_sample_4bit (no_data,
								   &sample);
					break;
				    case RL2_SAMPLE_UINT8:
					rl2_get_pixel_sample_uint8 (no_data, b,
								    &sample);
					break;
				    };
				  if (sample == *p_in++)
				      match++;
			      }
			    if (match != num_bands)
			      {
				  /* opaque pixel */
				  p_in = p_save;
				  for (b = 0; b < num_bands; b++)
				      *p_out++ = *p_in++;
			      }
			    else
			      {
				  /* NO-DATA pixel */
				  for (b = 0; b < num_bands; b++)
				      p_out++;
			      }
			}
		  }
	    }
      }
}

static unsigned char *
................................................................................
    return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
}

static void
copy_uint8_raw_selected_pixels (const unsigned char *buffer,
				const unsigned char *mask,
				unsigned char *outbuf, unsigned short width,
				unsigned short height,
				unsigned char num_bands, double x_res,
				double y_res, double minx, double maxy,
				double tile_minx, double tile_maxy,
				unsigned short tile_width,
				unsigned short tile_height,
				rl2PixelPtr no_data, unsigned char red_band,
				unsigned char green_band,
				unsigned char blue_band,
				rl2BandHandlingPtr red_handling,
				rl2BandHandlingPtr green_handling,
				rl2BandHandlingPtr blue_handling)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
................................................................................
			    /* skipping a transparent pixel */
			    p_out += 3;
			}
		      else
			{
			    /* opaque pixel */
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  red_band,
							  red_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  green_band,
							  green_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
			    if (sample == *p_save++)
				match++;
			}
		      if (match != num_bands)
			{
			    /* opaque pixel */
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  red_band,
							  red_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
							  green_band,
							  green_handling);
			    p_out =
				mono_uint8_pixel_handler (p_in, p_out,
................................................................................
}

static void
copy_uint8_raw_mono_pixels (const unsigned char *buffer,
			    const unsigned char *mask, unsigned char *outbuf,
			    unsigned short width, unsigned short height,
			    unsigned char out_num_bands,
			    unsigned char num_bands, double x_res,
			    double y_res, double minx, double maxy,
			    double tile_minx, double tile_maxy,
			    unsigned short tile_width,
			    unsigned short tile_height, rl2PixelPtr no_data,
			    unsigned char mono_band,
			    rl2BandHandlingPtr mono_handling)
{
/* copying UINT8 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
................................................................................
		  }
		p_in++;
	    }
      }
}

static void
copy_uint16_raw_pixels (const unsigned short *buffer,
			const unsigned char *mask, unsigned short *outbuf,
			unsigned short width, unsigned short height,
			unsigned char num_bands, double x_res, double y_res,
			double minx, double maxy, double tile_minx,
			double tile_maxy, unsigned short tile_width,
			unsigned short tile_height, rl2PixelPtr no_data)
{
/* copying UINT16 raw pixels from the DBMS tile into the output image */
    int x;
    int y;
    int b;
    int out_x;
    int out_y;
................................................................................
    return apply_contrast_enhancement ((double) mono, p_out, mono_handling);
}

static void
copy_uint16_raw_selected_pixels (const unsigned short *buffer,
				 const unsigned char *mask,
				 unsigned char *outbuf, unsigned short width,
				 unsigned short height,
				 unsigned char num_bands, double x_res,
				 double y_res, double minx, double maxy,
				 double tile_minx, double tile_maxy,
				 unsigned short tile_width,
				 unsigned short tile_height,
				 rl2PixelPtr no_data, unsigned char red_band,
				 unsigned char green_band,
				 unsigned char blue_band,
				 rl2BandHandlingPtr red_handling,
				 rl2BandHandlingPtr green_handling,
				 rl2BandHandlingPtr blue_handling)
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      r = malloc (sizeof (rl2BandHandling));
		      r->colorMap = NULL;
		      r->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(r->minValue),
					  &(r->maxValue), &(r->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      r = malloc (sizeof (rl2BandHandling));
		      r->colorMap = NULL;
		      r->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(g->minValue),
					  &(g->maxValue), &(g->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      b = malloc (sizeof (rl2BandHandling));
		      b->colorMap = NULL;
		      b->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(b->minValue),
					  &(b->maxValue), &(b->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      b = malloc (sizeof (rl2BandHandling));
		      b->colorMap = NULL;
		      b->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
		if (style->contrastEnhancement ==
		    RL2_CONTRAST_ENHANCEMENT_NORMALIZE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement =
			  RL2_CONTRAST_ENHANCEMENT_NORMALIZE;
		      compute_stretching (band, &(g->minValue),
					  &(g->maxValue), &(g->scaleFactor));
		  }
		else if (style->contrastEnhancement ==
			 RL2_CONTRAST_ENHANCEMENT_NONE)
		  {
		      g = malloc (sizeof (rl2BandHandling));
		      g->colorMap = NULL;
		      g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NONE;
................................................................................
}

static int
do_copy_raw_selected_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
			     unsigned int width, unsigned int height,
			     double x_res, double y_res, double minx,
			     double maxy, double tile_minx, double tile_maxy,
			     unsigned int tile_width,
			     unsigned int tile_height, rl2PixelPtr no_data,
			     unsigned char red_band, unsigned char green_band,
			     unsigned char blue_band,
			     rl2BandHandlingPtr red_handling,
			     rl2BandHandlingPtr green_handling,
			     rl2BandHandlingPtr blue_handling)
{
    switch (rst->sampleType)
      {
      case RL2_SAMPLE_UINT8:
................................................................................
      };
    return 0;
}

static int
do_copy_raw_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf,
		    unsigned int width, unsigned int height,
		    unsigned char raster_type, unsigned char sample_type,
		    unsigned char num_bands, double x_res, double y_res,
		    double minx, double maxy, double tile_minx,
		    double tile_maxy, unsigned int tile_width,
		    unsigned int tile_height, rl2PixelPtr no_data)
{


    switch (sample_type)
      {
      case RL2_SAMPLE_INT8:
	  copy_int8_raw_pixels ((const char *) (rst->rasterBuffer),
				(const unsigned char *) (rst->maskBuffer),
				(char *) outbuf, width, height,
				x_res, y_res, minx, maxy, tile_minx,
................................................................................
	  copy_int16_raw_pixels ((const short *) (rst->rasterBuffer),
				 (const unsigned char *) (rst->maskBuffer),
				 (short *) outbuf, width, height,
				 x_res, y_res, minx, maxy, tile_minx,
				 tile_maxy, tile_width, tile_height, no_data);
	  return 1;
      case RL2_SAMPLE_UINT16:
	  copy_uint16_raw_pixels ((const unsigned short
				   *) (rst->rasterBuffer),
				  (const unsigned char *) (rst->maskBuffer),
				  (unsigned short *) outbuf, width, height,
				  num_bands, x_res, y_res, minx, maxy,
				  tile_minx, tile_maxy, tile_width,
				  tile_height, no_data);
	  return 1;
      case RL2_SAMPLE_INT32:
................................................................................
				  tile_minx, tile_maxy, tile_width,
				  tile_height, no_data);
	  return 1;
      default:
	  copy_uint8_raw_pixels ((const unsigned char *) (rst->rasterBuffer),
				 (const unsigned char *) (rst->maskBuffer),
				 (unsigned char *) outbuf, width, height,
				 num_bands, x_res, y_res, minx, maxy,
				 tile_minx, tile_maxy, tile_width,
				 tile_height, no_data, raster_type);
	  return 1;
      };
    return 0;
}

RL2_PRIVATE int
rl2_copy_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf,
		     unsigned int width,
		     unsigned int height, unsigned char sample_type,
		     unsigned char num_bands, unsigned char auto_ndvi,
		     unsigned char red_band_index,
		     unsigned char nir_band_index, double x_res, double y_res,
		     double minx, double maxy, double tile_minx,
		     double tile_maxy, rl2PixelPtr no_data,
		     rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats)
{
/* copying raw pixels into the output buffer */
    unsigned int tile_width;
    unsigned int tile_height;
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;

................................................................................
	return 0;
    if (style != NULL && stats != NULL)
      {
	  /* attempting to apply a RasterSymbolizer */
	  int yes_no;
	  int categorize;
	  int interpolate;
	  if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no)
	      == RL2_OK)
	    {
		if ((rst->sampleType == RL2_SAMPLE_UINT8
		     || rst->sampleType == RL2_SAMPLE_UINT16)
		    && (rst->pixelType == RL2_PIXEL_RGB
			|| rst->pixelType == RL2_PIXEL_MULTIBAND) && yes_no)
		  {
		      /* triple band selection - false color RGB */
................................................................................
						  blue_band, &red_handling,
						  &green_handling,
						  &blue_handling);
		      if (red_handling == NULL || green_handling == NULL
			  || blue_handling == NULL)
			  return 0;
		      if (do_copy_raw_selected_pixels
			  (rst, outbuf, width, height, x_res, y_res, minx,
			   maxy, tile_minx, tile_maxy, tile_width,
			   tile_height, no_data, red_band, green_band,
			   blue_band, red_handling, green_handling,
			   blue_handling))
			  return 1;
		      if (red_handling != NULL)
			  free (red_handling);
		      if (green_handling != NULL)
			  free (green_handling);
		      if (blue_handling != NULL)
			  free (blue_handling);
................................................................................
		      /* applying Auto NDVI */
		      rl2BandHandlingPtr ndvi_handling = NULL;
		      build_ndvi_handling ((rl2PrivRasterSymbolizerPtr)
					   style, &ndvi_handling);
		      if (ndvi_handling == NULL)
			  return 0;
		      if (do_auto_ndvi_pixels
			  (rst, outbuf, width, height, num_bands, x_res,
			   y_res, minx, maxy, tile_minx, tile_maxy,
			   tile_width, tile_height, no_data, red_band_index,
			   nir_band_index, ndvi_handling))
			  return 1;
		      if (ndvi_handling != NULL)
			  destroy_ndvi_handling (ndvi_handling);
		  }
		if (((rst->sampleType == RL2_SAMPLE_UINT8
		      || rst->sampleType == RL2_SAMPLE_UINT16)
		     || rst->pixelType == RL2_PIXEL_DATAGRID) && yes_no)
................................................................................
						style,
						(rl2PrivRasterStatisticsPtr)
						stats, mono_band,
						&mono_handling);
		      if (mono_handling == NULL)
			  return 0;
		      if (do_copy_raw_mono_pixels
			  (rst, outbuf, width, height, num_bands, x_res,
			   y_res, minx, maxy, tile_minx, tile_maxy,
			   tile_width, tile_height, no_data, mono_band,
			   mono_handling))
			  return 1;
		      if (mono_handling != NULL)
			  destroy_mono_handling (mono_handling);
		  }
	    }
      }

    if (do_copy_raw_pixels
	(rst, outbuf, width, height, rst->sampleType, sample_type, num_bands,
	 x_res, y_res, minx, maxy, tile_minx, tile_maxy, tile_width,
	 tile_height, no_data))
	return 1;

    return 0;
}

static void
do_copy_raw_mask (rl2PrivRasterPtr rst, unsigned char *maskbuf,
		  unsigned int width, unsigned int height, double x_res,
		  double y_res, double minx, double maxy, double tile_minx,
		  double tile_maxy, unsigned int tile_width,
		  unsigned int tile_height)
{
/* copying mask pixels from the DBMS tile into the output mask */
    unsigned int x;
    unsigned int y;
    int out_x;
    int out_y;
    double geo_x;
    double geo_y;
    const unsigned char *p_in = rst->maskBuffer;
    unsigned char *p_out;
    double y_res2 = y_res / 2.0;
    double x_res2 = x_res / 2.0;

    geo_y = tile_maxy + y_res2;
    for (y = 0; y < tile_height; y++)
      {
	  geo_y -= y_res;
	  out_y = (maxy - geo_y) / y_res;
	  if (out_y < 0 || out_y >= (int) height)
	    {
		p_in += tile_width;
		continue;
	    }
	  geo_x = tile_minx - x_res2;
	  for (x = 0; x < tile_width; x++)
	    {
		geo_x += x_res;
		out_x = (geo_x - minx) / x_res;
		if (out_x < 0 || out_x >= (int) width)
		  {
		      p_in++;
		      continue;
		  }
		p_out = maskbuf + (out_y * width) + out_x;
		if (*p_in++ == 0)
		    *p_out++ = 255;
	    }
      }
}

RL2_PRIVATE int
rl2_copy_raw_mask (rl2RasterPtr raster, unsigned char *maskbuf,
		   unsigned int width,
		   unsigned int height, double x_res, double y_res,
		   double minx, double maxy, double tile_minx, double tile_maxy)
{
/* copying a raw transparency mask into the output buffer */
    unsigned int tile_width;
    unsigned int tile_height;
    rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster;

    if (rl2_get_raster_size (raster, &tile_width, &tile_height) != RL2_OK)
	return 0;

    if (rst->maskBuffer == NULL)
      {
	  /* tile without mask - ok */
	  return 1;
      }
    do_copy_raw_mask (rst, maskbuf, width, height, x_res, y_res, minx, maxy,
		      tile_minx, tile_maxy, tile_width, tile_height);
    return 1;
}

static void
get_int8_ennuple (const char *rawbuf, unsigned short row, unsigned short col,
		  unsigned short row_stride, rl2PixelPtr no_data,
		  double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - INT8 */
................................................................................
	  /* checking for NoData values */
	  if (ennuple[i] == nd_val)
	      *has_no_data = 1;
      }
}

static void
get_int16_ennuple (const short *rawbuf, unsigned short row,
		   unsigned short col, unsigned short row_stride,
		   rl2PixelPtr no_data, double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - INT16 */
    const short *p_in;
    short nd_val = 0;
    int i;

    if (no_data != NULL)
................................................................................
	  /* checking for NoData values */
	  if (ennuple[i] == nd_val)
	      *has_no_data = 1;
      }
}

static void
get_float_ennuple (const float *rawbuf, unsigned short row,
		   unsigned short col, unsigned short row_stride,
		   rl2PixelPtr no_data, double ennuple[], int *has_no_data)
{
/* extracting a 3x3 "super-pixel" - FLOAT */
    const float *p_in;
    float nd_val = 0.0;
    int i;

    if (no_data != NULL)
................................................................................
	      free (shadower->opaque_thread_id);
	  shadower->opaque_thread_id = NULL;
      }
}

RL2_PRIVATE int
rl2_build_shaded_relief_mask (sqlite3 * handle, int max_threads,
			      rl2CoveragePtr cvg,
			      int by_section, sqlite3_int64 section_id,
			      double relief_factor, double scale_factor,
			      unsigned int width, unsigned int height,
			      double minx, double miny, double maxx,
			      double maxy, double x_res, double y_res,

			      float **shaded_relief, int *shaded_relief_sz)
{
/* attempting to return a Shaded Relief mask from the DBMS Coverage */
    rl2PixelPtr no_data = NULL;
    const char *coverage;
    unsigned char level;
    unsigned char scale;
    double xx_res = x_res;
................................................................................

    if (cvg == NULL || handle == NULL)
	goto error;
    coverage = rl2_get_coverage_name (cvg);
    if (coverage == NULL)
	goto error;
    if (rl2_find_matching_resolution
	(handle, cvg, by_section, section_id, &xx_res, &yy_res, &level,
	 &scale) != RL2_OK)
	goto error;
    if (rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands) !=
	RL2_OK)
	goto error;
    if (pixel_type != RL2_PIXEL_DATAGRID && num_bands != 1)
	goto error;
    no_data = rl2_get_coverage_no_data (cvg);
................................................................................
    if (no_data == NULL)
	goto error;

/* preparing the "tiles" SQL query */
    xtiles = sqlite3_mprintf ("%s_tiles", coverage);
    xxtiles = rl2_double_quoted_sql (xtiles);
    sql =
	sqlite3_mprintf
	("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) "

	 "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( "
	 "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q "
	 "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles);

    sqlite3_free (xtiles);
    free (xxtiles);
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  printf ("SELECT shadedRelief tiles SQL error: %s\n",
................................................................................
	  /* executing in a single thread */
	  p_out = sr_mask;
	  for (row = 0; row < height; row++)
	    {
		for (col = 0; col < width; col++)
		    *p_out++ =
			shaded_relief_value (relief_factor, scale_factor,
					     altRadians, azRadians, rawbuf,
					     row, col, row_stride,
					     sample_type, no_data);
	    }
      }
    else
      {
	  /* executing as many concurrent threads */
	  rl2AuxShadowerPtr aux = NULL;
	  rl2AuxShadowerPtr shadower;

Changes to src/rl2raw.c.

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
....
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
....
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
....
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
....
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
....
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
....
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
....
2309
2310
2311
2312
2313
2314
2315

2316
2317
2318
2319
2320
2321
2322
2323
....
2349
2350
2351
2352
2353
2354
2355
2356
2357

2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368

2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379

2380
2381
2382
2383
2384

2385
2386
2387
2388
2389
2390
2391
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
					    &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
					    &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND,
					    &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................

    *buffer = buf;
    *buf_size = sz;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band, unsigned short **buffer,
			   int *buf_size)
{
/* attempting to export Raster BAND data as a UINT-16 array */
    unsigned short *buf;
    int sz;
    unsigned int row;
    unsigned int col;
    int nBand;
................................................................................
	    }
      }
}

RL2_PRIVATE unsigned char *
rl2_copy_endian_raw_pixels (const unsigned char *pixels, int pixels_sz,
			    unsigned int width, unsigned int height,
			    unsigned char sample_type, unsigned char num_bands,
			    int big_endian)
{
/* copying RAW pixels (in endian safe mode) */
    int sample_bytes = 0;
    int outsize = width * height * num_bands;
    unsigned char *outbuf = NULL;

    switch (sample_type)
................................................................................
	  copy_endian_raw_u8 (outbuf, pixels, width, height, num_bands);
	  break;
      case RL2_SAMPLE_INT8:
	  copy_endian_raw_i8 ((char *) outbuf, (const char *) pixels, width,
			      height, num_bands);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels, width,
			       height, num_bands, big_endian);
	  break;
      case RL2_SAMPLE_UINT16:
	  copy_endian_raw_u16 ((unsigned short *) outbuf,
			       (const unsigned short *) pixels, width, height,
			       num_bands, big_endian);
	  break;
      case RL2_SAMPLE_INT32:
................................................................................
	  break;
      case RL2_SAMPLE_UINT32:
	  copy_endian_raw_u32 ((unsigned int *) outbuf,
			       (const unsigned int *) pixels, width, height,
			       num_bands, big_endian);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_endian_raw_flt ((float *) outbuf, (const float *) pixels, width,
			       height, num_bands, big_endian);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_endian_raw_dbl ((double *) outbuf, (const double *) pixels,
			       width, height, num_bands, big_endian);
	  break;
      };
    return outbuf;
................................................................................
	&& coverage->nBands == raster->nBands)
	return 1;
    fprintf (stderr, "Mismatching RAW pixels !!!\n");
    return 0;
}

static void
copy_tile_raw_i8 (const char *in, unsigned int in_width, unsigned int in_height,
		  unsigned int startRow, unsigned int startCol, char *out,
		  unsigned int tileWidth, unsigned int tileHeight,
		  unsigned char num_bands)
{
/* signed int8 */
    unsigned int x;
    unsigned int y;
    unsigned char b;
    for (y = 0; y < tileHeight; y++)
      {
................................................................................
		for (b = 0; b < num_bands; b++)
		    *p_out++ = *p_in++;
	    }
      }
}

static void
copy_tile_raw_i32 (const int *in, unsigned int in_width, unsigned int in_height,
		   unsigned int startRow, unsigned int startCol, int *out,
		   unsigned int tileWidth, unsigned int tileHeight,
		   unsigned char num_bands)
{
/* signed int32 */
    unsigned int x;
    unsigned int y;
    unsigned char b;
    for (y = 0; y < tileHeight; y++)
      {
................................................................................
		    *p_out++ = *p_in++;
	    }
      }
}

static int
build_tile_from_raw_pixels (rl2PrivRasterPtr origin, unsigned int tileWidth,

			    unsigned int tileHeight, unsigned char sample_type,
			    unsigned char num_bands, unsigned int startRow,
			    unsigned int startCol, rl2PixelPtr no_data,
			    unsigned char **pixels, int *pixels_sz)
{
/* extracting a Tile from the RAW buffer */
    unsigned char *out;
    int outsz = tileWidth * tileHeight * num_bands;
................................................................................
      case RL2_SAMPLE_INT8:
	  copy_tile_raw_i8 ((const char *) (origin->rasterBuffer),
			    origin->width, origin->height, startRow, startCol,
			    (char *) out, tileWidth, tileHeight, num_bands);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_tile_raw_i16 ((const short *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (short *) out, tileWidth, tileHeight, num_bands);

	  break;
      case RL2_SAMPLE_UINT16:
	  copy_tile_raw_u16 ((const unsigned short *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (unsigned short *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      case RL2_SAMPLE_INT32:
	  copy_tile_raw_i32 ((const int *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (int *) out, tileWidth, tileHeight, num_bands);

	  break;
      case RL2_SAMPLE_UINT32:
	  copy_tile_raw_u32 ((const unsigned int *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (unsigned int *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_tile_raw_flt ((const float *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (float *) out, tileWidth, tileHeight, num_bands);

	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_tile_raw_dbl ((const double *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow, startCol,
			     (double *) out, tileWidth, tileHeight, num_bands);

	  break;
      default:
	  copy_tile_raw_u8 ((const unsigned char *) (origin->rasterBuffer),
			    origin->width, origin->height, startRow, startCol,
			    (unsigned char *) out, tileWidth, tileHeight,
			    num_bands);
	  break;







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|
|
|







 







|
|
|
|







 







>
|







 







|
|
>



|
|
|



|
|
>



|
|
|



|
|
>



|
|
>







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
....
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
....
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
....
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
....
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
....
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
....
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
....
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
....
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_RED_BAND, &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_RED_BAND, &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................
		  }
		break;
	    case RL2_PIXEL_GRAYSCALE:
		grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8,
				  &transpR, &transpG, &transpB);
		break;
	    case RL2_PIXEL_RGB:
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_RED_BAND, &transpR);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_GREEN_BAND, &transpG);
		rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data,
					    RL2_BLUE_BAND, &transpB);
		break;
	    };
      }
................................................................................

    *buffer = buf;
    *buf_size = sz;
    return RL2_OK;
}

RL2_DECLARE int
rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band,
			   unsigned short **buffer, int *buf_size)
{
/* attempting to export Raster BAND data as a UINT-16 array */
    unsigned short *buf;
    int sz;
    unsigned int row;
    unsigned int col;
    int nBand;
................................................................................
	    }
      }
}

RL2_PRIVATE unsigned char *
rl2_copy_endian_raw_pixels (const unsigned char *pixels, int pixels_sz,
			    unsigned int width, unsigned int height,
			    unsigned char sample_type,
			    unsigned char num_bands, int big_endian)
{
/* copying RAW pixels (in endian safe mode) */
    int sample_bytes = 0;
    int outsize = width * height * num_bands;
    unsigned char *outbuf = NULL;

    switch (sample_type)
................................................................................
	  copy_endian_raw_u8 (outbuf, pixels, width, height, num_bands);
	  break;
      case RL2_SAMPLE_INT8:
	  copy_endian_raw_i8 ((char *) outbuf, (const char *) pixels, width,
			      height, num_bands);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels,
			       width, height, num_bands, big_endian);
	  break;
      case RL2_SAMPLE_UINT16:
	  copy_endian_raw_u16 ((unsigned short *) outbuf,
			       (const unsigned short *) pixels, width, height,
			       num_bands, big_endian);
	  break;
      case RL2_SAMPLE_INT32:
................................................................................
	  break;
      case RL2_SAMPLE_UINT32:
	  copy_endian_raw_u32 ((unsigned int *) outbuf,
			       (const unsigned int *) pixels, width, height,
			       num_bands, big_endian);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_endian_raw_flt ((float *) outbuf, (const float *) pixels,
			       width, height, num_bands, big_endian);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_endian_raw_dbl ((double *) outbuf, (const double *) pixels,
			       width, height, num_bands, big_endian);
	  break;
      };
    return outbuf;
................................................................................
	&& coverage->nBands == raster->nBands)
	return 1;
    fprintf (stderr, "Mismatching RAW pixels !!!\n");
    return 0;
}

static void
copy_tile_raw_i8 (const char *in, unsigned int in_width,
		  unsigned int in_height, unsigned int startRow,
		  unsigned int startCol, char *out, unsigned int tileWidth,
		  unsigned int tileHeight, unsigned char num_bands)
{
/* signed int8 */
    unsigned int x;
    unsigned int y;
    unsigned char b;
    for (y = 0; y < tileHeight; y++)
      {
................................................................................
		for (b = 0; b < num_bands; b++)
		    *p_out++ = *p_in++;
	    }
      }
}

static void
copy_tile_raw_i32 (const int *in, unsigned int in_width,
		   unsigned int in_height, unsigned int startRow,
		   unsigned int startCol, int *out, unsigned int tileWidth,
		   unsigned int tileHeight, unsigned char num_bands)
{
/* signed int32 */
    unsigned int x;
    unsigned int y;
    unsigned char b;
    for (y = 0; y < tileHeight; y++)
      {
................................................................................
		    *p_out++ = *p_in++;
	    }
      }
}

static int
build_tile_from_raw_pixels (rl2PrivRasterPtr origin, unsigned int tileWidth,
			    unsigned int tileHeight,
			    unsigned char sample_type,
			    unsigned char num_bands, unsigned int startRow,
			    unsigned int startCol, rl2PixelPtr no_data,
			    unsigned char **pixels, int *pixels_sz)
{
/* extracting a Tile from the RAW buffer */
    unsigned char *out;
    int outsz = tileWidth * tileHeight * num_bands;
................................................................................
      case RL2_SAMPLE_INT8:
	  copy_tile_raw_i8 ((const char *) (origin->rasterBuffer),
			    origin->width, origin->height, startRow, startCol,
			    (char *) out, tileWidth, tileHeight, num_bands);
	  break;
      case RL2_SAMPLE_INT16:
	  copy_tile_raw_i16 ((const short *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (short *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      case RL2_SAMPLE_UINT16:
	  copy_tile_raw_u16 ((const unsigned short *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (unsigned short *) out, tileWidth,
			     tileHeight, num_bands);
	  break;
      case RL2_SAMPLE_INT32:
	  copy_tile_raw_i32 ((const int *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (int *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      case RL2_SAMPLE_UINT32:
	  copy_tile_raw_u32 ((const unsigned int *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (unsigned int *) out, tileWidth,
			     tileHeight, num_bands);
	  break;
      case RL2_SAMPLE_FLOAT:
	  copy_tile_raw_flt ((const float *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (float *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  copy_tile_raw_dbl ((const double *) (origin->rasterBuffer),
			     origin->width, origin->height, startRow,
			     startCol, (double *) out, tileWidth, tileHeight,
			     num_bands);
	  break;
      default:
	  copy_tile_raw_u8 ((const unsigned char *) (origin->rasterBuffer),
			    origin->width, origin->height, startRow, startCol,
			    (unsigned char *) out, tileWidth, tileHeight,
			    num_bands);
	  break;

Changes to src/rl2sql.c.

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
....
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
....
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
....
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
....
4047
4048
4049
4050
4051
4052
4053
4054

4055
4056
4057
4058
4059
4060
4061
....
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120

4121
4122
4123
4124
4125
4126
4127
....
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
....
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525

4526
4527
4528
4529
4530
4531
4532
....
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
....
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911

4912
4913
4914
4915
4916
4917
4918
4919
4920
....
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
....
5268
5269
5270
5271
5272
5273
5274
5275

5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
....
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
....
5621
5622
5623
5624
5625
5626
5627

5628
5629
5630
5631
5632

5633
5634
5635
5636
5637
5638
5639
5640
....
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
....
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
....
5989
5990
5991
5992
5993
5994
5995
5996
5997

5998
5999
6000
6001
6002
6003
6004
6005
....
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
....
6397
6398
6399
6400
6401
6402
6403
6404

6405
6406
6407
6408
6409
6410
6411
....
6425
6426
6427
6428
6429
6430
6431
6432

6433

6434
6435
6436
6437
6438
6439
6440
....
6441
6442
6443
6444
6445
6446
6447
6448
6449

6450
6451
6452
6453
6454
6455
6456
6457
....
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
....
6850
6851
6852
6853
6854
6855
6856
6857
6858

6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873

6874
6875
6876
6877
6878
6879
6880
....
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
....
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
....
7220
7221
7222
7223
7224
7225
7226
7227
7228

7229
7230
7231
7232
7233
7234
7235
7236
....
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
....
7496
7497
7498
7499
7500
7501
7502
7503

7504
7505
7506
7507
7508
7509

7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
....
7579
7580
7581
7582
7583
7584
7585























































7586
7587
7588
7589
7590
7591
7592
....
7641
7642
7643
7644
7645
7646
7647

7648
7649
7650
7651
7652
7653
7654
....
7790
7791
7792
7793
7794
7795
7796

7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807

7808
7809





7810


7811
7812
7813
7814
7815
7816
7817
....
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
....
8096
8097
8098
8099
8100
8101
8102


8103
8104
8105
8106
8107
8108
8109
....
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
....
8219
8220
8221
8222
8223
8224
8225

8226
8227
8228
8229
8230
8231
8232
....
8300
8301
8302
8303
8304
8305
8306

8307
8308
8309
8310
8311
8312
8313
....
8501
8502
8503
8504
8505
8506
8507
8508

8509
8510
8511
8512
8513
8514
8515
....
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544

8545
8546
8547
8548
8549
8550
8551
....
8805
8806
8807
8808
8809
8810
8811
8812

8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
....
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
....
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
....
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
....
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
....
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
....
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
....
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
....
9268
9269
9270
9271
9272
9273
9274
9275
9276

9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
....
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683

9684
9685
9686
9687
9688
9689
9690
9691
9692
....
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
....
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
....
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
.....
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146

10147
10148
10149

10150
10151
10152

10153
10154
10155

10156
10157
10158
10159
10160
10161
10162
10163
10164
.....
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
.....
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
.....
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
.....
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
.....
10667
10668
10669
10670
10671
10672
10673
10674

10675
10676

10677
10678

10679
10680

10681
10682

10683
10684

10685
10686
10687
10688

10689
10690
10691
10692

10693
10694
10695
10696

10697
10698
10699
10700

10701
10702
10703
10704

10705
10706
10707
10708
10709

10710
10711
10712
10713
10714
10715
10716
.....
10813
10814
10815
10816
10817
10818
10819
10820

10821
10822
10823
10824
10825
10826
10827
10828
.....
10866
10867
10868
10869
10870
10871
10872
10873

10874
10875
10876
10877
10878
10879
10880
10881
10882
.....
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
.....
10941
10942
10943
10944
10945
10946
10947
10948
10949

10950
10951
10952
10953
10954

10955
10956
10957
10958
10959
10960
10961
.....
10981
10982
10983
10984
10985
10986
10987
10988

10989
10990
10991
10992
10993
10994
10995
10996
10997
.....
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
.....
11068
11069
11070
11071
11072
11073
11074
11075

11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
.....
11119
11120
11121
11122
11123
11124
11125
11126

11127
11128
11129
11130

11131
11132
11133
11134

11135
11136
11137
11138

11139
11140
11141
11142
11143
11144
11145
11146
.....
11169
11170
11171
11172
11173
11174
11175
11176

11177
11178
11179
11180
11181
11182

11183
11184
11185
11186
11187

11188
11189
11190
11191
11192
11193

11194
11195
11196
11197

11198
11199
11200
11201
11202
11203
11204
11205
    else
      {
	  blob_even = sqlite3_value_blob (argv[3]);
	  blob_even_sz = sqlite3_value_bytes (argv[3]);
      }

    if (!get_coverage_defs
	(sqlite, coverage, &tile_width, &tile_height, &sample_type, &pixel_type,
	 &num_bands, &compression))
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    ret =
	rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height, blob_odd,
				       blob_odd_sz, blob_even, blob_even_sz,
				       sample_type, pixel_type, num_bands,
				       compression);
    if (ret == RL2_OK)
	sqlite3_result_int (context, 1);
    else
	sqlite3_result_int (context, 0);
}

static void
................................................................................
    if (pxl1 != NULL)
	rl2_destroy_pixel (pxl1);
    if (pxl2 != NULL)
	rl2_destroy_pixel (pxl2);
}

static void
fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context, int argc,
					    sqlite3_value ** argv)
{
/* SQL function:
/ GetRasterStatistics_NoDataPixelsCount(BLOBencoded statistics)
/
/ will return the total count of NoData pixels
/ or NULL (INVALID ARGS)
/
................................................................................
      }
    st = (rl2PrivRasterStatisticsPtr) stats;
    sqlite3_result_int64 (context, st->no_data);
    rl2_destroy_raster_statistics (stats);
}

static void
fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context, int argc,
					   sqlite3_value ** argv)
{
/* SQL function:
/ GetRasterStatistics_ValidPixelsCount(BLOBencoded statistics)
/
/ will return the total count of valid pixels
/ or NULL (INVALID ARGS)
/
................................................................................
	  return;
      }
    if (rl2_get_coverage_srid (coverage, &srid) != RL2_OK)
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands)
	!= RL2_OK)
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    no_data = rl2_get_coverage_no_data (coverage);
    if (rl2_get_coverage_compression (coverage, &compression, &quality)
	!= RL2_OK)
................................................................................
    cvg = (rl2PrivCoveragePtr) coverage;
    for (y = maxy; y > miny; y -= tileh)
      {
	  for (x = minx; x < maxx; x += tilew)
	    {
		char *err_msg = NULL;
		unsigned char *rgba_tile =
		    do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer,

				       wms_crs, swap_xy, x, y - tileh,
				       x + tilew, y, tile_width, tile_height,
				       wms_style, wms_format, opaque, 0,
				       &err_msg);
		if (rgba_tile == NULL)
		  {
		      add_retry (retry_list, x, y - tileh, x + tilew, y);
................................................................................
		if (retry->done)
		  {
		      retry = retry->next;
		      continue;
		  }
		retry->count += 1;
		rgba_tile =
		    do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer,
				       wms_crs, swap_xy, retry->minx,
				       retry->miny, retry->maxx, retry->maxy,
				       tile_width, tile_height, wms_style,
				       wms_format, opaque, 0, &err_msg);

		if (rgba_tile == NULL)
		  {
		      retry = retry->next;
		      continue;
		  }

		params.sqlite = sqlite;
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
						    height, compression,
						    tile_sz, worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_geotiff_from_dbms (sqlite, max_threads, path, coverage,
					    horz_res, vert_res, minx, miny,
					    maxx, maxy, width, height,
					    compression, tile_sz, worldfile);

      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
    rl2_destroy_coverage (coverage);
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
      {
	  /* single Section */
	  ret =
	      rl2_export_section_triple_band_geotiff_from_dbms (sqlite, path,
								coverage,
								section_id,
								horz_res,
								vert_res, minx,
								miny, maxx,
								maxy, width,
								height,
								red_band,
								green_band,
								blue_band,
								compression,
								tile_sz,
								worldfile);
      }
    else
      {
	  /* whole Coverage */

	  ret =
	      rl2_export_triple_band_geotiff_from_dbms (sqlite, path, coverage,
							horz_res, vert_res,

							minx, miny, maxx, maxy,
							width, height, red_band,
							green_band, blue_band,
							compression, tile_sz,
							worldfile);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  /* single Section */
	  ret =
	      rl2_export_section_mono_band_geotiff_from_dbms (sqlite, path,
							      coverage,
							      section_id,
							      horz_res,
							      vert_res, minx,
							      miny, maxx, maxy,

							      width, height,
							      mono_band,
							      compression,
							      tile_sz,
							      worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_mono_band_geotiff_from_dbms (sqlite, path, coverage,
						      horz_res, vert_res, minx,
						      miny, maxx, maxy, width,
						      height, mono_band,
						      compression, tile_sz,
						      worldfile);
      }

    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  /* only a single Section */
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_section_tiff_worldfile_from_dbms (sqlite,
								 max_threads,

								 path, coverage,
								 section_id,
								 horz_res,
								 vert_res, minx,
								 miny, maxx,

								 maxy, width,
								 height,
								 compression,
								 tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
................................................................................
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_tiff_worldfile_from_dbms (sqlite, max_threads,
							 path, coverage,
							 horz_res, vert_res,
							 minx, miny, maxx, maxy,
							 width, height,
							 compression, tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_tiff_from_dbms (sqlite, max_threads, path,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
      }

    if (by_section)
      {
	  /* single Section */
	  ret =
	      rl2_export_section_jpeg_from_dbms (sqlite, max_threads, path,
						 coverage, section_id, horz_res,
						 vert_res, minx, miny, maxx,

						 maxy, width, height, quality,
						 with_worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_jpeg_from_dbms (sqlite, max_threads, path, coverage,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
		     minx, miny, maxx, maxy, width, height, red_band,
		     green_band, blue_band, compression, tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_section_triple_band_tiff_from_dbms (sqlite, path,

								   coverage,
								   section_id,
								   horz_res,
								   vert_res,
								   minx, miny,
								   maxx, maxy,
								   width,
................................................................................
		/* TIFF + Worldfile */
		ret =
		    rl2_export_triple_band_tiff_worldfile_from_dbms (sqlite,
								     path,
								     coverage,
								     horz_res,
								     vert_res,
								     minx, miny,

								     maxx, maxy,

								     width,
								     height,
								     red_band,
								     green_band,
								     blue_band,
								     compression,
								     tile_sz);
................................................................................
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_triple_band_tiff_from_dbms (sqlite, path,
							   coverage, horz_res,
							   vert_res, minx, miny,
							   maxx, maxy, width,

							   height, red_band,
							   green_band,
							   blue_band,
							   compression,
							   tile_sz);
	    }
      }
    if (ret != RL2_OK)
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_section_mono_band_tiff_from_dbms (sqlite, path,
								 coverage,
								 section_id,
								 horz_res,
								 vert_res, minx,
								 miny, maxx,

								 maxy, width,
								 height,
								 mono_band,
								 compression,
								 tile_sz);
	    }
      }
    else
      {
	  /* whole Coverage */
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite, path,

								   coverage,
								   horz_res,
								   vert_res,
								   minx, miny,
								   maxx, maxy,
								   width,
								   height,
................................................................................
								   compression,
								   tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_mono_band_tiff_from_dbms (sqlite, path, coverage,
							 horz_res, vert_res,
							 minx, miny, maxx, maxy,
							 width, height,
							 mono_band, compression,
							 tile_sz);
	    }
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
	  double ext_x = (double) width * resolution;
	  double ext_y = (double) height * resolution;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
						       decimal_digits);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_ascii_grid_from_dbms (sqlite, max_threads, path,
					       coverage, resolution, minx, miny,
					       maxx, maxy, width, height,

					       is_centered, decimal_digits);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
    rl2_destroy_coverage (coverage);
................................................................................
	  double ext_x = (double) width * resolution;
	  double ext_y = (double) height * resolution;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  return;
      }

    if (by_section)
      {
	  /* single Section */
	  ret =
	      rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite, max_threads,

							    path, coverage,
							    section_id,
							    resolution, minx,
							    miny, maxx, maxy,
							    width, height,
							    red_band, nir_band,

							    is_centered,
							    decimal_digits);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_ndvi_ascii_grid_from_dbms (sqlite, max_threads, path,
						    coverage, resolution, minx,
						    miny, maxx, maxy, width,
						    height, red_band, nir_band,
						    is_centered,
						    decimal_digits);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
/
/ will return 1 (TRUE, success) or 0 (FALSE, failure)
/ or -1 (INVALID ARGS)
/
*/
    common_write_ndvi_ascii_grid (1, context, argc, argv);
}
























































static void
fnct_GetMapImageFromRaster (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
/* SQL function:
/ GetMapImageFromRaster(text coverage, BLOB geom, int width, int height)
................................................................................
    double ext_y;
    double x_res;
    double y_res;
    int srid;
    int level_id;
    int scale;
    int xscale;

    double xx_res;
    double yy_res;
    double aspect_org;
    double aspect_dst;
    int ok_style;
    int ok_format;
    unsigned char *outbuf = NULL;
................................................................................
	  aux.reaspect = reaspect;
	  rl2_aux_group_renderer (&aux);
	  return;
      }

    x_res = ext_x / (double) width;
    y_res = ext_y / (double) height;

/* validating the style */
    ok_style = 0;
    if (strcasecmp (style, "default") == 0)
	ok_style = 1;
    else
      {
	  /* attempting to get a Coverage Style */
	  cvg_stl =
	      rl2_create_coverage_style_from_dbms (sqlite, cvg_name, style);
	  if (cvg_stl == NULL)
	      goto error;

	  symbolizer = rl2_get_symbolizer_from_coverage_style (cvg_stl, 1.0);
	  if (symbolizer == NULL)





	      goto error;


	  stats = rl2_create_raster_statistics_from_dbms (sqlite, cvg_name);
	  if (stats == NULL)
	      goto error;
	  ok_style = 1;
      }
    if (!ok_style)
	goto error;
................................................................................
      }
    else
      {
	  /* ordinary Coverage */
	  by_section = 0;
	  /* retrieving the optimal resolution level */
	  if (!rl2_find_best_resolution_level
	      (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale, &xscale,
	       &xx_res, &yy_res))
	      goto error;
      }
    base_width = (int) (ext_x / xx_res);
    base_height = (int) (ext_y / yy_res);
    if ((base_width <= 0 && base_width >= USHRT_MAX)
	|| (base_height <= 0 && base_height >= USHRT_MAX))
	goto error;
................................................................................
    aux.symbolizer = symbolizer;
    aux.stats = stats;
    aux.outbuf = outbuf;
    aux.palette = palette;
    aux.out_pixel = out_pixel;
    if (!rl2_aux_render_image (&aux, &image, &image_size))
	goto error;


    sqlite3_result_blob (context, image, image_size, free);
    rl2_destroy_coverage (coverage);
    if (palette != NULL)
	rl2_destroy_palette (palette);
    if (cvg_stl != NULL)
	rl2_destroy_coverage_style (cvg_stl);
    if (stats != NULL)
................................................................................
    if (cvg_stl != NULL)
	rl2_destroy_coverage_style (cvg_stl);
    if (stats != NULL)
	rl2_destroy_raster_statistics (stats);
    sqlite3_result_null (context);
}

static int
test_geographic_srid (sqlite3 * handle, int srid)
{
/* testing if some SRID is of the Geographic type */
    int ret;
    int is_geographic = 0;
    sqlite3_stmt *stmt = NULL;
    const char *sql;

    sql = "SELECT SridIsGeographic(?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return 0;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_int (stmt, 1, srid);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	      is_geographic = sqlite3_column_int (stmt, 0);
      }
    sqlite3_finalize (stmt);
    return is_geographic;
}

static double
standard_scale (sqlite3 * handle, int srid, int width, int height, double ext_x,
		double ext_y)
{
/* computing the standard (normalized) scale */
    double linear_res;
    double factor;
    int is_geographic = test_geographic_srid (handle, srid);
    if (is_geographic)
      {
	  /* geographic (long/lat) CRS */
	  double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0;
	  linear_res = metres / (double) width;
      }
    else
      {
	  /* planar (projected) CRS */
	  double x_res = ext_x / (double) width;
	  double y_res = ext_y / (double) height;
	  linear_res = sqrt (x_res * y_res);
      }
    factor = linear_res / 0.000254;
    return factor * (0.28 / 0.254);
}

static void
fnct_GetMapImageFromVector (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
/* SQL function:
/ GetMapImageFromVector(text coverage, BLOB geom, int width, int height)
/ GetMapImageFromVector(text coverage, BLOB geom, int width, int height,
................................................................................
    unsigned char bg_green;
    unsigned char bg_blue;
    int transparent = 0;
    int quality = 80;
    int reaspect = 0;
    sqlite3 *sqlite;
    sqlite3_stmt *stmt = NULL;

    double minx;
    double maxx;
    double miny;
    double maxy;
    double ext_x;
    double ext_y;
    double x_res;
................................................................................
    if (argc > 8)
	quality = sqlite3_value_int (argv[8]);
    if (argc > 9)
	reaspect = sqlite3_value_int (argv[9]);

/* coarse args validation */
    sqlite = sqlite3_context_db_handle (context);

    if (width < 64)
	goto error;
    if (height < 64)
	goto error;
/* validating the format */
    ok_format = 0;
    if (strcmp (format, "image/png") == 0)
................................................................................
			      {
			      case SQLITE_INTEGER:
				  rl2_set_variant_int (variant, i, col_name,
						       sqlite3_column_int64
						       (stmt, i + 1));
				  break;
			      case SQLITE_FLOAT:
				  rl2_set_variant_double (variant, i, col_name,

							  sqlite3_column_double
							  (stmt, i + 1));
				  break;
			      case SQLITE_TEXT:
				  rl2_set_variant_text (variant, i, col_name,
							(const char *)
							sqlite3_column_text
................................................................................
				  break;
			      };
			}
		  }
		if (geom != NULL)
		  {
		      /* drawing a styled Feature */
		      int scale_forbidden;
		      symbolizer = NULL;
		      if (lyr_stl != NULL)
			  symbolizer =
			      rl2_get_symbolizer_from_feature_type_style
			      (lyr_stl, scale, variant, &scale_forbidden);
		      if (!scale_forbidden)
			  rl2_draw_vector_feature (ctx, sqlite, symbolizer,
						   height, minx, miny, x_res,

						   y_res, geom, variant);
		      rl2_destroy_geometry (geom);
		  }
	    }
      }
    sqlite3_finalize (stmt);

................................................................................
			    *p_rgba++ = 0;	/* transparent */
			}
		  }
		switch (pixel_type)
		  {
		  case RL2_PIXEL_MONOCHROME:
		      ret =
			  get_rgba_from_monochrome_mask (width, height, buffer,

							 mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						      mask, palette, no_data,
						      rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
			  get_rgba_from_grayscale_mask (width, height, buffer,
							mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						       sample_type, buffer,
						       mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
			}
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_PIXEL_RGB:
		      if (sample_type == RL2_SAMPLE_UINT16)
			{
			    ret =
				get_rgba_from_multiband16 (width, height, 0, 1,
							   2, 3,
							   (unsigned short *)
							   buffer, mask,
							   no_data, rgba);
			}
		      else
			{
			    ret =
................................................................................
							mask, no_data, rgba);
			}
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
				goto error;
			}
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_PIXEL_MULTIBAND:
		      ret =
			  get_rgba_from_multiband_mask (width, height,
							sample_type, num_bands,
							buffer, mask, no_data,
							rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						    num_bands, buffer, mask,
						    no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_SAMPLE_UINT16:
		      ret =
			  get_rgba_from_multiband16 (width, height, red_band,
						     green_band, blue_band,
						     num_bands,
						     (unsigned short *) buffer,
						     mask, no_data, rgba);

		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red, bg_green,
			   bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy)
	     != RL2_OK)
	goto error;

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
    if (coverage == NULL)
	goto error;
    if (by_section)
      {
	  /* only a single Section */
	  ret =
	      rl2_export_section_raw_pixels_from_dbms (sqlite, max_threads,
						       coverage, section_id,
						       horz_res, vert_res, minx,
						       miny, maxx, maxy, width,

						       height, big_endian,
						       &xblob, &xblob_sz);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_raw_pixels_from_dbms (sqlite, max_threads, coverage,
					       horz_res, vert_res, minx, miny,
................................................................................
    if (rl2_parse_bbox_srid
	(sqlite, blob, blob_sz, &srid, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

    if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands)
	!= RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }
    if (rl2_get_coverage_srid (coverage, &cov_srid) != RL2_OK)
      {
	  errcode = -1;
................................................................................
    no_data = NULL;
    if (raster == NULL)
      {
	  errcode = -1;
	  goto error;
      }
/* georeferencing the raster */
    if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy) !=
	RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Raster into the DBMS */
    if (transaction)
................................................................................
	    {
		rl2_destroy_coverage (coverage);
		sqlite3_result_int (context, -1);
		return;
	    }
      }
    ret =
	rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage, sctn_name,
				       raster, pyramidize);
    rl2_destroy_coverage (coverage);
    rl2_destroy_raster (raster);
    if (ret != RL2_OK)
      {
	  if (transaction)
	    {
		/* invalidating the pending transaction */
................................................................................
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "DropRasterCoverage", 2,
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "RL2_DropRasterCoverage", 2,
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "SetRasterCoverageInfos", 3,
			     SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0);
    sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3,
			     SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0);
    sqlite3_create_function (db, "SetRasterCoverageDefaultBands", 5,

			     SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands,
			     0, 0);
    sqlite3_create_function (db, "RL2_SetRasterCoverageDefaultBands", 5,

			     SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands,
			     0, 0);
    sqlite3_create_function (db, "EnableRasterCoverageAutoNDVI", 2,

			     SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI,
			     0, 0);
    sqlite3_create_function (db, "RL2_EnableRasterCoverageAutoNDVI", 2,

			     SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI,
			     0, 0);
    sqlite3_create_function (db, "IsRasterCoverageAutoNdviEnabled", 1,
			     SQLITE_UTF8, 0,
			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
    sqlite3_create_function (db, "RL2_IsRasterCoverageAutoNdviEnabled", 1,
			     SQLITE_UTF8, 0,
			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
    sqlite3_create_function (db, "GetPaletteNumEntries", 1,
................................................................................
			     fnct_IsFontItalic, 0, 0);
    sqlite3_create_function (db, "RL2_IsFontItalic", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_IsFontItalic, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_NoDataPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_ValidPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_SampleType", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_SampleType, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_SampleType", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_SampleType, 0, 0);
................................................................................
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "Pyramidize", 4, SQLITE_UTF8, priv_data,
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_Pyramidize", 4, SQLITE_UTF8, priv_data,
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 1, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 2, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 3, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "DePyramidize", 1, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_DePyramidize", 1, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "DePyramidize", 2, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_DePyramidize", 2, SQLITE_UTF8, 0,
................................................................................
    sqlite3_create_function (db, "GetMapImageFromRaster", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromRaster, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromRaster", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromRaster, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 4,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 4,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 5,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 5,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 6,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 6,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 7,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 7,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 8,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 8,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 9,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 9,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 10,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 10,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetTileImage", 2,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetTileImage, 0, 0);
    sqlite3_create_function (db, "RL2_GetTileImage", 2,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetTileImage, 0, 0);
................................................................................
				   fnct_LoadFontFromFile, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadFontFromFile", 1, SQLITE_UTF8,
				   0, fnct_LoadFontFromFile, 0, 0);
	  sqlite3_create_function (db, "ExportFontToFile", 2, SQLITE_UTF8, 0,
				   fnct_ExportFontToFile, 0, 0);
	  sqlite3_create_function (db, "RL2_ExportFontToFile", 2, SQLITE_UTF8,
				   0, fnct_ExportFontToFile, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8, priv_data,
				   fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8, priv_data,
				   fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8, priv_data,
				   fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8, priv_data,
				   fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8, priv_data,
				   fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 2, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 3, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 4, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 5, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 5, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 6, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 7, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7, SQLITE_UTF8,

				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 9, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9, SQLITE_UTF8,

				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 10, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10, SQLITE_UTF8,

				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 11, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11, SQLITE_UTF8,

				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 12, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12, SQLITE_UTF8,

				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 13, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13, SQLITE_UTF8,

				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 14, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14, SQLITE_UTF8,
				   0, fnct_LoadRasterFromWMS, 0, 0);

	  sqlite3_create_function (db, "WriteGeoTiff", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteGeoTiff", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 7, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTiff", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 10, SQLITE_UTF8,

				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteJpegJgw", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "WriteJpegJgw", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 7, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "WriteSectionJpeg", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9, SQLITE_UTF8,

				   priv_data, fnct_WriteTripleBandGeoTiff, 0,
				   0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 10,
................................................................................
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 10,
				   SQLITE_UTF8, 0,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 14,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 14,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 7, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 8, SQLITE_UTF8,
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 9, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 8,
................................................................................
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9, SQLITE_UTF8,

				   priv_data, fnct_WriteTripleBandTiffTfw, 0,
				   0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 10,
................................................................................
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiffTfw", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiffTfw", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10, SQLITE_UTF8,

				   priv_data, fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8, 0,
				   fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiff", 10, SQLITE_UTF8,
				   0, fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 10,
				   SQLITE_UTF8, priv_data,
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 7, SQLITE_UTF8, 0,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7, SQLITE_UTF8,

				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 8, SQLITE_UTF8, 0,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8, SQLITE_UTF8,

				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9, SQLITE_UTF8,

				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10, SQLITE_UTF8,

				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 9,
................................................................................
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 7, SQLITE_UTF8,

				   priv_data, fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 8, SQLITE_UTF8,
				   0, fnct_WriteSectionAsciiGrid, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 9, SQLITE_UTF8,
				   0, fnct_WriteSectionAsciiGrid, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8, SQLITE_UTF8,

				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9, SQLITE_UTF8,

				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionNdviAsciiGrid", 9,
				   SQLITE_UTF8, priv_data,







|
|





|
|
|
|







 







|
|







 







|
|







 







|
|







 







|
>







 







|
|
|
|
|
>







 







|
|







 







|
|
|
|
>







 







|
|







 







|
|
|
|












|
|
>
|
|







 







|
|







 







|
>
|










|
|
|
|
|







 







|
|







 







>
|


|
|
>
|







 







|
|







 







|
|







 







|
|
>
|







 







|
|







 







|
>







 







|
>
|
>







 







|
|
>
|







 







|
|







 







|
|
>
|













|
>







 







|
|
|
|
|
|







 







|
|







 







|
|
>
|







 







|
|







 







|
>
|




|
>








|
|
|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>











>
|

>
>
>
>
>
|
>
>







 







|
|







 







>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>







 







>







 







|
>







 







|






|
|
>







 







|
>
|





|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|
|





|
|







 







|
|







 







|
|
>

|
|







 







|
|












|
|
>
|
|







 







|
|







 







|
|







 







|
|







 







|
|

>
|
<

>
|
<

>
|
<

>
|
<







 







|
|




|
|







 







|
|


|
|


|
|







 







|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|







 







|
|
|
|
|
|
|
|
|
|







 







|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|


|
>
|


|
>
|


|
>
|


|
>
|


|
>
|


|
|
>







 







|
>
|







 







|
>
|
<







 







|
|




|
|




|
|




|
|




|
|







 







|
|
>



|
|
>







 







|
>
|
<







 







|
|




|
|




|
|




|
|







 







|
>
|



|
|







 







|
>
|


|
>
|


|
>
|


|
>
|







 







|
>
|



|
|
>



|
|
>





|
>
|


|
>
|







657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
....
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
....
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
....
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
....
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
....
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
....
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
....
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
....
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
....
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
....
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
....
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
....
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
....
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
....
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
....
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
....
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
....
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
....
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
....
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
....
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
....
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
....
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
....
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
....
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
....
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
....
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
....
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
....
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
....
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
....
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
....
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
....
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
....
8202
8203
8204
8205
8206
8207
8208























































8209
8210
8211
8212
8213
8214
8215
....
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
....
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
....
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
....
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
....
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
....
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
....
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
....
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
....
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
....
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
....
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
....
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
....
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
....
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
....
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
....
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
.....
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
.....
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184

10185
10186
10187

10188
10189
10190

10191
10192
10193

10194
10195
10196
10197
10198
10199
10200
.....
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
.....
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
.....
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
.....
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
.....
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
.....
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
.....
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924

10925
10926
10927
10928
10929
10930
10931
.....
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
.....
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
.....
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041

11042
11043
11044
11045
11046
11047
11048
.....
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
.....
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
.....
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
.....
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
    else
      {
	  blob_even = sqlite3_value_blob (argv[3]);
	  blob_even_sz = sqlite3_value_bytes (argv[3]);
      }

    if (!get_coverage_defs
	(sqlite, coverage, &tile_width, &tile_height, &sample_type,
	 &pixel_type, &num_bands, &compression))
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    ret =
	rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height,
				       blob_odd, blob_odd_sz, blob_even,
				       blob_even_sz, sample_type, pixel_type,
				       num_bands, compression);
    if (ret == RL2_OK)
	sqlite3_result_int (context, 1);
    else
	sqlite3_result_int (context, 0);
}

static void
................................................................................
    if (pxl1 != NULL)
	rl2_destroy_pixel (pxl1);
    if (pxl2 != NULL)
	rl2_destroy_pixel (pxl2);
}

static void
fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context,
					    int argc, sqlite3_value ** argv)
{
/* SQL function:
/ GetRasterStatistics_NoDataPixelsCount(BLOBencoded statistics)
/
/ will return the total count of NoData pixels
/ or NULL (INVALID ARGS)
/
................................................................................
      }
    st = (rl2PrivRasterStatisticsPtr) stats;
    sqlite3_result_int64 (context, st->no_data);
    rl2_destroy_raster_statistics (stats);
}

static void
fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context,
					   int argc, sqlite3_value ** argv)
{
/* SQL function:
/ GetRasterStatistics_ValidPixelsCount(BLOBencoded statistics)
/
/ will return the total count of valid pixels
/ or NULL (INVALID ARGS)
/
................................................................................
	  return;
      }
    if (rl2_get_coverage_srid (coverage, &srid) != RL2_OK)
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    if (rl2_get_coverage_type
	(coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK)
      {
	  sqlite3_result_int (context, -1);
	  return;
      }
    no_data = rl2_get_coverage_no_data (coverage);
    if (rl2_get_coverage_compression (coverage, &compression, &quality)
	!= RL2_OK)
................................................................................
    cvg = (rl2PrivCoveragePtr) coverage;
    for (y = maxy; y > miny; y -= tileh)
      {
	  for (x = minx; x < maxx; x += tilew)
	    {
		char *err_msg = NULL;
		unsigned char *rgba_tile =
		    do_wms_GetMap_get (NULL, url, proxy, wms_version,
				       wms_layer,
				       wms_crs, swap_xy, x, y - tileh,
				       x + tilew, y, tile_width, tile_height,
				       wms_style, wms_format, opaque, 0,
				       &err_msg);
		if (rgba_tile == NULL)
		  {
		      add_retry (retry_list, x, y - tileh, x + tilew, y);
................................................................................
		if (retry->done)
		  {
		      retry = retry->next;
		      continue;
		  }
		retry->count += 1;
		rgba_tile =
		    do_wms_GetMap_get (NULL, url, proxy, wms_version,
				       wms_layer, wms_crs, swap_xy,
				       retry->minx, retry->miny, retry->maxx,
				       retry->maxy, tile_width, tile_height,
				       wms_style, wms_format, opaque, 0,
				       &err_msg);
		if (rgba_tile == NULL)
		  {
		      retry = retry->next;
		      continue;
		  }

		params.sqlite = sqlite;
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
						    height, compression,
						    tile_sz, worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_geotiff_from_dbms (sqlite, max_threads, path,
					    coverage, horz_res, vert_res,
					    minx, miny, maxx, maxy, width,
					    height, compression, tile_sz,
					    worldfile);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
    rl2_destroy_coverage (coverage);
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
      {
	  /* single Section */
	  ret =
	      rl2_export_section_triple_band_geotiff_from_dbms (sqlite, path,
								coverage,
								section_id,
								horz_res,
								vert_res,
								minx, miny,
								maxx, maxy,
								width, height,
								red_band,
								green_band,
								blue_band,
								compression,
								tile_sz,
								worldfile);
      }
    else
      {
	  /* whole Coverage */

	  ret =
	      rl2_export_triple_band_geotiff_from_dbms (sqlite, path,
							coverage, horz_res,
							vert_res, minx, miny,
							maxx, maxy, width,
							height, red_band,
							green_band, blue_band,
							compression, tile_sz,
							worldfile);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  /* single Section */
	  ret =
	      rl2_export_section_mono_band_geotiff_from_dbms (sqlite, path,
							      coverage,
							      section_id,
							      horz_res,
							      vert_res, minx,
							      miny, maxx,
							      maxy, width,
							      height,
							      mono_band,
							      compression,
							      tile_sz,
							      worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_mono_band_geotiff_from_dbms (sqlite, path, coverage,
						      horz_res, vert_res,
						      minx, miny, maxx, maxy,
						      width, height,
						      mono_band, compression,
						      tile_sz, worldfile);
      }

    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  /* only a single Section */
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_section_tiff_worldfile_from_dbms (sqlite,
								 max_threads,
								 path,
								 coverage,
								 section_id,
								 horz_res,
								 vert_res,
								 minx, miny,
								 maxx, maxy,
								 width,
								 height,
								 compression,
								 tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
................................................................................
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_tiff_worldfile_from_dbms (sqlite, max_threads,
							 path, coverage,
							 horz_res, vert_res,
							 minx, miny, maxx,
							 maxy, width, height,
							 compression, tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_tiff_from_dbms (sqlite, max_threads, path,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
      }

    if (by_section)
      {
	  /* single Section */
	  ret =
	      rl2_export_section_jpeg_from_dbms (sqlite, max_threads, path,
						 coverage, section_id,
						 horz_res, vert_res, minx,
						 miny, maxx, maxy, width,
						 height, quality,
						 with_worldfile);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_jpeg_from_dbms (sqlite, max_threads, path, coverage,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
		     minx, miny, maxx, maxy, width, height, red_band,
		     green_band, blue_band, compression, tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_section_triple_band_tiff_from_dbms (sqlite,
								   path,
								   coverage,
								   section_id,
								   horz_res,
								   vert_res,
								   minx, miny,
								   maxx, maxy,
								   width,
................................................................................
		/* TIFF + Worldfile */
		ret =
		    rl2_export_triple_band_tiff_worldfile_from_dbms (sqlite,
								     path,
								     coverage,
								     horz_res,
								     vert_res,
								     minx,
								     miny,
								     maxx,
								     maxy,
								     width,
								     height,
								     red_band,
								     green_band,
								     blue_band,
								     compression,
								     tile_sz);
................................................................................
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_triple_band_tiff_from_dbms (sqlite, path,
							   coverage, horz_res,
							   vert_res, minx,
							   miny, maxx, maxy,
							   width, height,
							   red_band,
							   green_band,
							   blue_band,
							   compression,
							   tile_sz);
	    }
      }
    if (ret != RL2_OK)
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_section_mono_band_tiff_from_dbms (sqlite, path,
								 coverage,
								 section_id,
								 horz_res,
								 vert_res,
								 minx, miny,
								 maxx, maxy,
								 width,
								 height,
								 mono_band,
								 compression,
								 tile_sz);
	    }
      }
    else
      {
	  /* whole Coverage */
	  if (with_worldfile)
	    {
		/* TIFF + Worldfile */
		ret =
		    rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite,
								   path,
								   coverage,
								   horz_res,
								   vert_res,
								   minx, miny,
								   maxx, maxy,
								   width,
								   height,
................................................................................
								   compression,
								   tile_sz);
	    }
	  else
	    {
		/* plain TIFF, no Worldfile */
		ret =
		    rl2_export_mono_band_tiff_from_dbms (sqlite, path,
							 coverage, horz_res,
							 vert_res, minx, miny,
							 maxx, maxy, width,
							 height, mono_band,
							 compression, tile_sz);
	    }
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
	  double ext_x = (double) width * resolution;
	  double ext_y = (double) height * resolution;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
						       decimal_digits);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_ascii_grid_from_dbms (sqlite, max_threads, path,
					       coverage, resolution, minx,
					       miny, maxx, maxy, width,
					       height, is_centered,
					       decimal_digits);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
    rl2_destroy_coverage (coverage);
................................................................................
	  double ext_x = (double) width * resolution;
	  double ext_y = (double) height * resolution;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
................................................................................
	  return;
      }

    if (by_section)
      {
	  /* single Section */
	  ret =
	      rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite,
							    max_threads, path,
							    coverage,
							    section_id,
							    resolution, minx,
							    miny, maxx, maxy,
							    width, height,
							    red_band,
							    nir_band,
							    is_centered,
							    decimal_digits);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_ndvi_ascii_grid_from_dbms (sqlite, max_threads, path,
						    coverage, resolution,
						    minx, miny, maxx, maxy,
						    width, height, red_band,
						    nir_band, is_centered,
						    decimal_digits);
      }
    if (ret != RL2_OK)
      {
	  errcode = 0;
	  goto error;
      }
................................................................................
/
/ will return 1 (TRUE, success) or 0 (FALSE, failure)
/ or -1 (INVALID ARGS)
/
*/
    common_write_ndvi_ascii_grid (1, context, argc, argv);
}

static int
test_geographic_srid (sqlite3 * handle, int srid)
{
/* testing if some SRID is of the Geographic type */
    int ret;
    int is_geographic = 0;
    sqlite3_stmt *stmt = NULL;
    const char *sql;

    sql = "SELECT SridIsGeographic(?)";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return 0;

    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_int (stmt, 1, srid);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	      is_geographic = sqlite3_column_int (stmt, 0);
      }
    sqlite3_finalize (stmt);
    return is_geographic;
}

static double
standard_scale (sqlite3 * handle, int srid, int width, int height,
		double ext_x, double ext_y)
{
/* computing the standard (normalized) scale */
    double linear_res;
    double factor;
    int is_geographic = test_geographic_srid (handle, srid);
    if (is_geographic)
      {
	  /* geographic (long/lat) CRS */
	  double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0;
	  linear_res = metres / (double) width;
      }
    else
      {
	  /* planar (projected) CRS */
	  double x_res = ext_x / (double) width;
	  double y_res = ext_y / (double) height;
	  linear_res = sqrt (x_res * y_res);
      }
    factor = linear_res / 0.000254;
    return factor * (0.28 / 0.254);
}

static void
fnct_GetMapImageFromRaster (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
/* SQL function:
/ GetMapImageFromRaster(text coverage, BLOB geom, int width, int height)
................................................................................
    double ext_y;
    double x_res;
    double y_res;
    int srid;
    int level_id;
    int scale;
    int xscale;
    double map_scale;
    double xx_res;
    double yy_res;
    double aspect_org;
    double aspect_dst;
    int ok_style;
    int ok_format;
    unsigned char *outbuf = NULL;
................................................................................
	  aux.reaspect = reaspect;
	  rl2_aux_group_renderer (&aux);
	  return;
      }

    x_res = ext_x / (double) width;
    y_res = ext_y / (double) height;
    map_scale = standard_scale (sqlite, out_srid, width, height, ext_x, ext_y);
/* validating the style */
    ok_style = 0;
    if (strcasecmp (style, "default") == 0)
	ok_style = 1;
    else
      {
	  /* attempting to get a Coverage Style */
	  cvg_stl =
	      rl2_create_coverage_style_from_dbms (sqlite, cvg_name, style);
	  if (cvg_stl == NULL)
	      goto error;
	  symbolizer =
	      rl2_get_symbolizer_from_coverage_style (cvg_stl, map_scale);
	  if (symbolizer == NULL)
	    {
		/* invisible at the currect scale */
		if (!rl2_aux_default_image
		    (width, height, bg_red, bg_green, bg_blue, format_id,
		     transparent, quality, &image, &image_size))
		    goto error;
		goto done;
	    }
	  stats = rl2_create_raster_statistics_from_dbms (sqlite, cvg_name);
	  if (stats == NULL)
	      goto error;
	  ok_style = 1;
      }
    if (!ok_style)
	goto error;
................................................................................
      }
    else
      {
	  /* ordinary Coverage */
	  by_section = 0;
	  /* retrieving the optimal resolution level */
	  if (!rl2_find_best_resolution_level
	      (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale,
	       &xscale, &xx_res, &yy_res))
	      goto error;
      }
    base_width = (int) (ext_x / xx_res);
    base_height = (int) (ext_y / yy_res);
    if ((base_width <= 0 && base_width >= USHRT_MAX)
	|| (base_height <= 0 && base_height >= USHRT_MAX))
	goto error;
................................................................................
    aux.symbolizer = symbolizer;
    aux.stats = stats;
    aux.outbuf = outbuf;
    aux.palette = palette;
    aux.out_pixel = out_pixel;
    if (!rl2_aux_render_image (&aux, &image, &image_size))
	goto error;

  done:
    sqlite3_result_blob (context, image, image_size, free);
    rl2_destroy_coverage (coverage);
    if (palette != NULL)
	rl2_destroy_palette (palette);
    if (cvg_stl != NULL)
	rl2_destroy_coverage_style (cvg_stl);
    if (stats != NULL)
................................................................................
    if (cvg_stl != NULL)
	rl2_destroy_coverage_style (cvg_stl);
    if (stats != NULL)
	rl2_destroy_raster_statistics (stats);
    sqlite3_result_null (context);
}
























































static void
fnct_GetMapImageFromVector (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
/* SQL function:
/ GetMapImageFromVector(text coverage, BLOB geom, int width, int height)
/ GetMapImageFromVector(text coverage, BLOB geom, int width, int height,
................................................................................
    unsigned char bg_green;
    unsigned char bg_blue;
    int transparent = 0;
    int quality = 80;
    int reaspect = 0;
    sqlite3 *sqlite;
    sqlite3_stmt *stmt = NULL;
    const void *data;
    double minx;
    double maxx;
    double miny;
    double maxy;
    double ext_x;
    double ext_y;
    double x_res;
................................................................................
    if (argc > 8)
	quality = sqlite3_value_int (argv[8]);
    if (argc > 9)
	reaspect = sqlite3_value_int (argv[9]);

/* coarse args validation */
    sqlite = sqlite3_context_db_handle (context);
    data = sqlite3_user_data (context);
    if (width < 64)
	goto error;
    if (height < 64)
	goto error;
/* validating the format */
    ok_format = 0;
    if (strcmp (format, "image/png") == 0)
................................................................................
			      {
			      case SQLITE_INTEGER:
				  rl2_set_variant_int (variant, i, col_name,
						       sqlite3_column_int64
						       (stmt, i + 1));
				  break;
			      case SQLITE_FLOAT:
				  rl2_set_variant_double (variant, i,
							  col_name,
							  sqlite3_column_double
							  (stmt, i + 1));
				  break;
			      case SQLITE_TEXT:
				  rl2_set_variant_text (variant, i, col_name,
							(const char *)
							sqlite3_column_text
................................................................................
				  break;
			      };
			}
		  }
		if (geom != NULL)
		  {
		      /* drawing a styled Feature */
		      int scale_forbidden = 0;
		      symbolizer = NULL;
		      if (lyr_stl != NULL)
			  symbolizer =
			      rl2_get_symbolizer_from_feature_type_style
			      (lyr_stl, scale, variant, &scale_forbidden);
		      if (!scale_forbidden)
			  rl2_draw_vector_feature (ctx, sqlite, data,
						   symbolizer, height, minx,
						   miny, maxx, maxy, x_res,
						   y_res, geom, variant);
		      rl2_destroy_geometry (geom);
		  }
	    }
      }
    sqlite3_finalize (stmt);

................................................................................
			    *p_rgba++ = 0;	/* transparent */
			}
		  }
		switch (pixel_type)
		  {
		  case RL2_PIXEL_MONOCHROME:
		      ret =
			  get_rgba_from_monochrome_mask (width, height,
							 buffer, mask,
							 no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						      mask, palette, no_data,
						      rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
			  get_rgba_from_grayscale_mask (width, height, buffer,
							mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						       sample_type, buffer,
						       mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
			}
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_PIXEL_RGB:
		      if (sample_type == RL2_SAMPLE_UINT16)
			{
			    ret =
				get_rgba_from_multiband16 (width, height, 0,
							   1, 2, 3,
							   (unsigned short *)
							   buffer, mask,
							   no_data, rgba);
			}
		      else
			{
			    ret =
................................................................................
							mask, no_data, rgba);
			}
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
				goto error;
			}
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_PIXEL_MULTIBAND:
		      ret =
			  get_rgba_from_multiband_mask (width, height,
							sample_type,
							num_bands, buffer,
							mask, no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_gray_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
						    num_bands, buffer, mask,
						    no_data, rgba);
		      buffer = NULL;
		      mask = NULL;
		      if (!ret)
			  goto error;
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
		      sqlite3_result_blob (context, image, image_size, free);
		      break;
		  case RL2_SAMPLE_UINT16:
		      ret =
			  get_rgba_from_multiband16 (width, height, red_band,
						     green_band, blue_band,
						     num_bands,
						     (unsigned short *)
						     buffer, mask, no_data,
						     rgba);
		      if (!build_rgb_alpha
			  (width, height, rgba, &rgb, &alpha, bg_red,
			   bg_green, bg_blue))
			  goto error;
		      free (rgba);
		      rgba = NULL;
		      if (transparent)
			{
			    if (!get_payload_from_rgb_rgba_transparent
				(width, height, rgb, alpha,
................................................................................
	  double ext_x = (double) width * horz_res;
	  double ext_y = (double) height * vert_res;
	  minx = pt_x - ext_x / 2.0;
	  maxx = minx + ext_x;
	  miny = pt_y - ext_y / 2.0;
	  maxy = miny + ext_y;
      }
    else if (rl2_parse_bbox
	     (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK)
	goto error;

/* attempting to load the Coverage definitions from the DBMS */
    coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name);
    if (coverage == NULL)
	goto error;
    if (by_section)
      {
	  /* only a single Section */
	  ret =
	      rl2_export_section_raw_pixels_from_dbms (sqlite, max_threads,
						       coverage, section_id,
						       horz_res, vert_res,
						       minx, miny, maxx, maxy,
						       width, height,
						       big_endian, &xblob,
						       &xblob_sz);
      }
    else
      {
	  /* whole Coverage */
	  ret =
	      rl2_export_raw_pixels_from_dbms (sqlite, max_threads, coverage,
					       horz_res, vert_res, minx, miny,
................................................................................
    if (rl2_parse_bbox_srid
	(sqlite, blob, blob_sz, &srid, &minx, &miny, &maxx, &maxy) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

    if (rl2_get_coverage_type
	(coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }
    if (rl2_get_coverage_srid (coverage, &cov_srid) != RL2_OK)
      {
	  errcode = -1;
................................................................................
    no_data = NULL;
    if (raster == NULL)
      {
	  errcode = -1;
	  goto error;
      }
/* georeferencing the raster */
    if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy)
	!= RL2_OK)
      {
	  errcode = -1;
	  goto error;
      }

/* attempting to load the Raster into the DBMS */
    if (transaction)
................................................................................
	    {
		rl2_destroy_coverage (coverage);
		sqlite3_result_int (context, -1);
		return;
	    }
      }
    ret =
	rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage,
				       sctn_name, raster, pyramidize);
    rl2_destroy_coverage (coverage);
    rl2_destroy_raster (raster);
    if (ret != RL2_OK)
      {
	  if (transaction)
	    {
		/* invalidating the pending transaction */
................................................................................
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "DropRasterCoverage", 2,
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "RL2_DropRasterCoverage", 2,
			     SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0);
    sqlite3_create_function (db, "SetRasterCoverageInfos", 3,
			     SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0);
    sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3, SQLITE_UTF8,
			     0, fnct_SetRasterCoverageInfos, 0, 0);
    sqlite3_create_function (db, "SetRasterCoverageDefaultBands", 5,
			     SQLITE_UTF8, 0,
			     fnct_SetRasterCoverageDefaultBands, 0, 0);

    sqlite3_create_function (db, "RL2_SetRasterCoverageDefaultBands", 5,
			     SQLITE_UTF8, 0,
			     fnct_SetRasterCoverageDefaultBands, 0, 0);

    sqlite3_create_function (db, "EnableRasterCoverageAutoNDVI", 2,
			     SQLITE_UTF8, 0,
			     fnct_EnableRasterCoverageAutoNDVI, 0, 0);

    sqlite3_create_function (db, "RL2_EnableRasterCoverageAutoNDVI", 2,
			     SQLITE_UTF8, 0,
			     fnct_EnableRasterCoverageAutoNDVI, 0, 0);

    sqlite3_create_function (db, "IsRasterCoverageAutoNdviEnabled", 1,
			     SQLITE_UTF8, 0,
			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
    sqlite3_create_function (db, "RL2_IsRasterCoverageAutoNdviEnabled", 1,
			     SQLITE_UTF8, 0,
			     fnct_IsRasterCoverageAutoNdviEnabled, 0, 0);
    sqlite3_create_function (db, "GetPaletteNumEntries", 1,
................................................................................
			     fnct_IsFontItalic, 0, 0);
    sqlite3_create_function (db, "RL2_IsFontItalic", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_IsFontItalic, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_NoDataPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount",
			     1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_ValidPixelsCount", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount",
			     1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_ValidPixelsCount, 0, 0);
    sqlite3_create_function (db, "GetRasterStatistics_SampleType", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_SampleType, 0, 0);
    sqlite3_create_function (db, "RL2_GetRasterStatistics_SampleType", 1,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
			     fnct_GetRasterStatistics_SampleType, 0, 0);
................................................................................
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "Pyramidize", 4, SQLITE_UTF8, priv_data,
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_Pyramidize", 4, SQLITE_UTF8, priv_data,
			     fnct_Pyramidize, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 1, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8,
			     0, fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 2, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8,
			     0, fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "PyramidizeMonolithic", 3, SQLITE_UTF8, 0,
			     fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8,
			     0, fnct_PyramidizeMonolithic, 0, 0);
    sqlite3_create_function (db, "DePyramidize", 1, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_DePyramidize", 1, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "DePyramidize", 2, SQLITE_UTF8, 0,
			     fnct_DePyramidize, 0, 0);
    sqlite3_create_function (db, "RL2_DePyramidize", 2, SQLITE_UTF8, 0,
................................................................................
    sqlite3_create_function (db, "GetMapImageFromRaster", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromRaster, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromRaster", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromRaster, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 4,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 4,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 5,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 5,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 6,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 6,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 7,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 7,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 8,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 8,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 9,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 9,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 10,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 10,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetMapImageFromVector", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "RL2_GetMapImageFromVector", 11,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetMapImageFromVector, 0, 0);
    sqlite3_create_function (db, "GetTileImage", 2,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetTileImage, 0, 0);
    sqlite3_create_function (db, "RL2_GetTileImage", 2,
			     SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data,
			     fnct_GetTileImage, 0, 0);
................................................................................
				   fnct_LoadFontFromFile, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadFontFromFile", 1, SQLITE_UTF8,
				   0, fnct_LoadFontFromFile, 0, 0);
	  sqlite3_create_function (db, "ExportFontToFile", 2, SQLITE_UTF8, 0,
				   fnct_ExportFontToFile, 0, 0);
	  sqlite3_create_function (db, "RL2_ExportFontToFile", 2, SQLITE_UTF8,
				   0, fnct_ExportFontToFile, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 2, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 3, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 4, SQLITE_UTF8,
				   priv_data, fnct_LoadRaster, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRaster", 5, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 5, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 6, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRastersFromDir", 7, SQLITE_UTF8,
				   priv_data, fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRastersFromDir, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 9, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 10, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 11, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 12, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 13, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "LoadRasterFromWMS", 14, SQLITE_UTF8,
				   priv_data, fnct_LoadRasterFromWMS, 0, 0);
	  sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14,
				   SQLITE_UTF8, 0, fnct_LoadRasterFromWMS, 0,
				   0);
	  sqlite3_create_function (db, "WriteGeoTiff", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteGeoTiff", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteGeoTiff", 7, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTiff", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTiff, 0, 0);
	  sqlite3_create_function (db, "WriteJpegJgw", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 6, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "WriteJpegJgw", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteJpegJgw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteJpegJgw", 7, SQLITE_UTF8,
................................................................................
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "WriteSectionJpeg", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionJpeg", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteSectionJpeg, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandGeoTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 10,
................................................................................
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 10,
				   SQLITE_UTF8, 0,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
				   10, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
				   11, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
				   12, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
				   13, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 14,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff",
				   14, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 7, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 8, SQLITE_UTF8,
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 9, SQLITE_UTF8,
				   0, fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10,
				   SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff,
				   0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11,
				   SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff,
				   0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 8,
................................................................................
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandGeoTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);

	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 10,
................................................................................
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
				   10, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 11,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
				   11, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 12,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
				   12, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw",
				   13, SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiffTfw", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiffTfw", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiffTfw, 0, 0);
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiffTfw, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8,
				   0, fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteTripleBandTiff", 10, SQLITE_UTF8,
				   0, fnct_WriteTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 10,
				   SQLITE_UTF8, priv_data,
................................................................................
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiff", 13,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionTripleBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 7, SQLITE_UTF8, 0,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 8, SQLITE_UTF8, 0,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteMonoBandTiff", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiff", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionMonoBandTiff, 0, 0);
	  sqlite3_create_function (db, "WriteSectionMonoBandTiff", 9,
................................................................................
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 7, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 7,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 8,
				   SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid,
				   0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionAsciiGrid", 9,
				   SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid,
				   0, 0);
	  sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteSectionAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 8, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 9, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteNdviAsciiGrid", 10, SQLITE_UTF8,
				   priv_data, fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 10,
				   SQLITE_UTF8, priv_data,
				   fnct_WriteNdviAsciiGrid, 0, 0);
	  sqlite3_create_function (db, "WriteSectionNdviAsciiGrid", 9,
				   SQLITE_UTF8, priv_data,

Changes to src/rl2sqlaux.c.

81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
...
734
735
736
737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
...
999
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009
1010
1011
1012
1013
1014
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
....
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
....
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
....
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
....
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
....
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
....
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
....
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
....
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
....
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
....
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
....
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
....
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
....
2521
2522
2523
2524
2525
2526
2527

2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
....
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
....
2768
2769
2770
2771
2772
2773
2774
2775

2776
2777
2778
2779
2780
2781
2782
2783
....
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
....
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
....
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
....
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
....
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
....
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
....
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
....
4511
4512
4513
4514
4515
4516
4517

4518
4519
4520
4521
4522
4523
4524
4525
    int ret;
    const char *sample;
    int bands;
    unsigned char xsample_type = RL2_SAMPLE_UNKNOWN;
    unsigned char xnum_bands = RL2_BANDS_UNKNOWN;

    sql =

	sqlite3_mprintf ("SELECT sample_type, num_bands FROM raster_coverages "
			 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_get_table (sqlite, sql, &results, &rows, &columns, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 0;
    if (rows < 1)
	;
    else
................................................................................
  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}

static int
do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd, int blob_odd_sz,
		    unsigned char *blob_even, int blob_even_sz,
		    sqlite3_int64 section_id, int srid, double res_x,
		    double res_y, unsigned int tile_w, unsigned int tile_h,
		    double miny, double maxx, double tile_minx,
		    double tile_miny, double tile_maxx, double tile_maxy,
		    rl2PalettePtr aux_palette, rl2PixelPtr no_data,

		    sqlite3_stmt * stmt_tils, sqlite3_stmt * stmt_data,
		    rl2RasterStatisticsPtr section_stats)
{
/* INSERTing the tile */
    int ret;
    sqlite3_int64 tile_id;
    rl2RasterStatisticsPtr stats = NULL;

................................................................................
}

RL2_PRIVATE int
rl2_do_insert_section (sqlite3 * handle, const char *src_path,
		       const char *section, int srid, unsigned int width,
		       unsigned int height, double minx, double miny,
		       double maxx, double maxy, char *xml_summary,
		       int section_paths, int section_md5, int section_summary,

		       sqlite3_stmt * stmt_sect, sqlite3_int64 * id)
{
/* INSERTing the section */
    int ret;
    unsigned char *blob;
    int blob_size;
    sqlite3_int64 section_id;

................................................................................
      {
	  sqlite3_bind_null (stmt_sect, 4);
	  if (xml_summary != NULL)
	      free (xml_summary);
      }
    sqlite3_bind_int (stmt_sect, 5, width);
    sqlite3_bind_int (stmt_sect, 6, height);
    if (rl2_build_bbox (handle, srid, minx, miny, maxx, maxy, &blob, &blob_size)
	!= RL2_OK)
	goto error;
    sqlite3_bind_blob (stmt_sect, 7, blob, blob_size, free);
    ret = sqlite3_step (stmt_sect);
    if (ret == SQLITE_DONE || ret == SQLITE_ROW)
	section_id = sqlite3_last_insert_rowid (handle);
    else
      {
................................................................................
    int blob_odd_sz;
    unsigned char *blob_even;
    int blob_even_sz;
    rl2RasterPtr raster = NULL;
    double base_res_x;
    double base_res_y;

    if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y) !=
	RL2_OK)
	goto error;
    if (*first)
      {
	  /* INSERTing the section */
	  *first = 0;
	  if (!rl2_do_insert_section
	      (ptr->sqlite, "WMS Service", ptr->sect_name, ptr->srid,
	       ptr->width, ptr->height, ptr->minx, ptr->miny, ptr->maxx,
	       ptr->maxy, ptr->xml_summary, ptr->sectionPaths, ptr->sectionMD5,
	       ptr->sectionSummary, ptr->stmt_sect, section_id))

	      goto error;
	  *section_stats =
	      rl2_create_raster_statistics (ptr->sample_type, ptr->num_bands);
	  if (*section_stats == NULL)
	      goto error;
	  /* INSERTing the base-levels */
	  if (ptr->mixedResolutions)
................................................................................
    /* INSERTing the tile */
    tile_minx = ptr->x;
    tile_maxx = tile_minx + ptr->tilew;
    tile_maxy = ptr->y;
    tile_miny = tile_maxy - ptr->tileh;
    if (!do_insert_wms_tile
	(ptr->sqlite, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
	 *section_id, ptr->srid, ptr->horz_res, ptr->vert_res, ptr->tile_width,
	 ptr->tile_height, ptr->miny, ptr->maxx, tile_minx, tile_miny,
	 tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils,
	 ptr->stmt_data, *section_stats))
	goto error;
    blob_odd = NULL;
    blob_even = NULL;
    rl2_destroy_raster (raster);
    free (ptr->rgba_tile);
    ptr->rgba_tile = NULL;
................................................................................
	  xxcoverage = rl2_double_quoted_sql (xcoverage);
	  sqlite3_free (xcoverage);
	  sql =
	      sqlite3_mprintf
	      ("SELECT pyramid_level, x_resolution_1_8, y_resolution_1_8, "
	       "x_resolution_1_4, y_resolution_1_4, x_resolution_1_2, y_resolution_1_2, "
	       "x_resolution_1_1, y_resolution_1_1 FROM \"%s\" "
	       "WHERE section_id = %s ORDER BY pyramid_level DESC", xxcoverage,
	       sctn);
      }
    else
      {
	  /* ordinary Coverage */
	  xcoverage = sqlite3_mprintf ("%s_levels", coverage);
	  xxcoverage = rl2_double_quoted_sql (xcoverage);
	  sqlite3_free (xcoverage);
................................................................................
	    }
      }
    return rgba;
}

RL2_PRIVATE int
get_payload_from_monochrome_opaque (unsigned int width, unsigned int height,
				    sqlite3 * handle, double minx, double miny,
				    double maxx, double maxy, int srid,
				    unsigned char *pixels, unsigned char format,
				    int quality, unsigned char **image,
				    int *image_sz)
{
/* input: Monochrome    output: Grayscale */
    int ret;
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned char *gray = NULL;
    unsigned int row;
................................................................................
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_TIFF)
      {
	  if (srid > 0)
	    {
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid, gray,
		     image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
		    RL2_OK)
		    goto error;
................................................................................
		    goto error;
	    }
	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
	    {
		if (srid > 0)
		  {
		      if (rl2_rgb_to_geotiff
			  (width, height, handle, minx, miny, maxx, maxy, srid,
			   rgb, image, image_sz) != RL2_OK)
			  goto error;
		  }
		else
		  {
		      if (rl2_rgb_to_tiff (width, height, rgb, image, image_sz)
			  != RL2_OK)
			  goto error;
		  }
	    }
	  else if (format == RL2_OUTPUT_FORMAT_PDF)
	    {
		rgba = rgb_to_rgba (width, height, rgb);
		if (rgba == NULL)
................................................................................
		    goto error;
	    }
	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
	    {
		if (srid > 0)
		  {
		      if (rl2_gray_to_geotiff
			  (width, height, handle, minx, miny, maxx, maxy, srid,
			   gray, image, image_sz) != RL2_OK)
			  goto error;
		  }
		else
		  {
		      if (rl2_gray_to_tiff
			  (width, height, gray, image, image_sz) != RL2_OK)
			  goto error;
................................................................................
    return 0;
}

RL2_PRIVATE int
get_payload_from_grayscale_opaque (unsigned int width, unsigned int height,
				   sqlite3 * handle, double minx, double miny,
				   double maxx, double maxy, int srid,
				   unsigned char *pixels, unsigned char format,
				   int quality, unsigned char **image,
				   int *image_sz)
{
/* input: Grayscale    output: Grayscale */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_gray_to_jpeg (width, height, pixels, quality, image, image_sz)
	      != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_gray_to_png (width, height, pixels, image, image_sz) !=
	      RL2_OK)
	      goto error;
................................................................................
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     pixels, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, pixels, image, image_sz) !=
		    RL2_OK)
		    goto error;
	    }
      }
    else if (format == RL2_OUTPUT_FORMAT_PDF)
      {
	  rgba = gray_to_rgba (width, height, pixels);
	  if (rgba == NULL)
................................................................................
{
/* input: RGB    output: RGB */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_rgb_to_jpeg (width, height, pixels, quality, image, image_sz)
	      != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_rgb_to_png (width, height, pixels, image, image_sz) != RL2_OK)
	      goto error;
      }
................................................................................
		if (rl2_rgb_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     pixels, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz) !=
		    RL2_OK)
		    goto error;
	    }
      }
    else if (format == RL2_OUTPUT_FORMAT_PDF)
      {
	  rgba = rgb_to_rgba (width, height, pixels);
	  if (rgba == NULL)
................................................................................
}

RL2_PRIVATE int
get_payload_from_rgb_transparent (unsigned int width, unsigned int height,
				  unsigned char *pixels, unsigned char format,
				  int quality, unsigned char **image,
				  int *image_sz, unsigned char bg_red,
				  unsigned char bg_green, unsigned char bg_blue,
				  double opacity)
{
/* input: RGB    output: RGB */
    unsigned char *p_in;
    unsigned char *p_msk;
    unsigned char *mask = NULL;
    unsigned int row;
    unsigned int col;
................................................................................
				 unsigned char *pixels, unsigned char *rgba)
{
/* input: Monochrome    output: Grayscale */
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned int row;
    unsigned int col;

    p_in = pixels;
    p_out = rgba;
    for (row = 0; row < height; row++)
      {
	  for (col = 0; col < width; col++)
	    {
		if (*p_in++ == 1)
		  {
		      *p_out++ = 0;	/* Black */
		      *p_out++ = 0;
		      *p_out++ = 0;
		      *p_out++ = 255;	/* alpha */
		  }
		else
................................................................................

    p_in = pixels;
    p_out = rgba;
    for (row = 0; row < height; row++)
      {
	  for (col = 0; col < width; col++)
	    {
		if (*p_in++ == 1)
		  {
		      *p_out++ = 0;	/* Black */
		      *p_out++ = 0;
		      *p_out++ = 0;
		      *p_out++ = 255;	/* alpha */
		  }
		else
................................................................................
  error:
    free (pixels);
    return 0;
}

RL2_PRIVATE int
get_rgba_from_palette_transparent (unsigned int width, unsigned int height,
				   unsigned char *pixels, rl2PalettePtr palette,

				   unsigned char *rgba, unsigned char bg_red,
				   unsigned char bg_green,
				   unsigned char bg_blue)
{
/* input: Palette    output: Grayscale or RGB */
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
    unsigned char *p_in;
    unsigned char *p_out;
................................................................................
    free (pixels);
    return 1;
}

RL2_PRIVATE int
get_rgba_from_grayscale_transparent (unsigned int width,
				     unsigned int height,
				     unsigned char *pixels, unsigned char *rgba,
				     unsigned char bg_gray)
{
/* input: Grayscale    output: Grayscale */
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned int row;
    unsigned int col;

................................................................................
    if (mask != NULL)
	free (mask);
    return 1;
}

RL2_PRIVATE int
rgba_from_double (unsigned int width, unsigned int height,
		  double *pixels, unsigned char *mask, rl2PrivPixelPtr no_data,
		  unsigned char *rgba)
{
/* input: DataGrid DOUBLE   output: Grayscale */
    double *p_in;
    unsigned char *p_out;
    unsigned char *p_msk;
    unsigned int row;
    unsigned int col;
................................................................................
      case RL2_SAMPLE_INT16:
	  ret =
	      rgba_from_int16 (width, height, (short *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_UINT16:
	  ret =
	      rgba_from_uint16 (width, height, (unsigned short *) pixels, mask,
				no_data, rgba);
	  break;
      case RL2_SAMPLE_INT32:
	  ret =
	      rgba_from_int32 (width, height, (int *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_UINT32:
................................................................................
      case RL2_SAMPLE_FLOAT:
	  ret =
	      rgba_from_float (width, height, (float *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  ret =
	      rgba_from_double (width, height, (double *) pixels, mask, no_data,
				rgba);
	  break;
      };
    return ret;
}

RL2_PRIVATE int
rgba_from_multi_uint8 (unsigned int width, unsigned int height,
................................................................................
	      rgba_from_multi_uint8 (width, height, num_bands,
				     (unsigned char *) pixels, mask, no_data,
				     rgba);
	  break;
      case RL2_SAMPLE_UINT16:
	  ret =
	      rgba_from_multi_uint16 (width, height, num_bands,
				      (unsigned short *) pixels, mask, no_data,
				      rgba);
	  break;
      };
    return ret;
}

RL2_PRIVATE int
get_payload_from_gray_rgba_opaque (unsigned int width, unsigned int height,
................................................................................
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_TIFF)
      {
	  if (srid > 0)
	    {
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid, gray,
		     image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
		    RL2_OK)
		    goto error;
................................................................................
{
/* RGB, Opaque */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz) !=
	      RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_rgb_to_png (width, height, rgb, image, image_sz) != RL2_OK)
	      goto error;
      }
................................................................................
	free (rgba);
    return 0;
}

RL2_PRIVATE int
get_payload_from_rgb_rgba_transparent (unsigned int width,
				       unsigned int height,

				       unsigned char *rgb, unsigned char *alpha,
				       unsigned char format, int quality,
				       unsigned char **image, int *image_sz,
				       double opacity, int half_transparency)
{
/* RGB, Transparent */
    int ret;
    unsigned char *p_msk;







>
|
|







 







|
|
|
|
|
|
|
>
|







 







|
>
|







 







|
|







 







|
|








|
|
>







 







|
|
|







 







|
|







 







|
|
|
|
|







 







|
|







 







|
|




|
|







 







|
|







 







|
|
|







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







>






|







 







|







 







|
>
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







>
|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
....
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
....
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
....
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
....
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
....
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
....
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
....
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
....
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
....
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
....
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
....
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
....
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
....
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
....
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
....
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
....
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
....
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
....
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
....
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
....
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
....
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
....
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
....
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
....
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
    int ret;
    const char *sample;
    int bands;
    unsigned char xsample_type = RL2_SAMPLE_UNKNOWN;
    unsigned char xnum_bands = RL2_BANDS_UNKNOWN;

    sql =
	sqlite3_mprintf
	("SELECT sample_type, num_bands FROM raster_coverages "
	 "WHERE Lower(coverage_name) = Lower(%Q)", coverage);
    ret = sqlite3_get_table (sqlite, sql, &results, &rows, &columns, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
	return 0;
    if (rows < 1)
	;
    else
................................................................................
  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return RL2_ERROR;
}

static int
do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd,
		    int blob_odd_sz, unsigned char *blob_even,
		    int blob_even_sz, sqlite3_int64 section_id, int srid,
		    double res_x, double res_y, unsigned int tile_w,
		    unsigned int tile_h, double miny, double maxx,
		    double tile_minx, double tile_miny, double tile_maxx,
		    double tile_maxy, rl2PalettePtr aux_palette,
		    rl2PixelPtr no_data, sqlite3_stmt * stmt_tils,
		    sqlite3_stmt * stmt_data,
		    rl2RasterStatisticsPtr section_stats)
{
/* INSERTing the tile */
    int ret;
    sqlite3_int64 tile_id;
    rl2RasterStatisticsPtr stats = NULL;

................................................................................
}

RL2_PRIVATE int
rl2_do_insert_section (sqlite3 * handle, const char *src_path,
		       const char *section, int srid, unsigned int width,
		       unsigned int height, double minx, double miny,
		       double maxx, double maxy, char *xml_summary,
		       int section_paths, int section_md5,
		       int section_summary, sqlite3_stmt * stmt_sect,
		       sqlite3_int64 * id)
{
/* INSERTing the section */
    int ret;
    unsigned char *blob;
    int blob_size;
    sqlite3_int64 section_id;

................................................................................
      {
	  sqlite3_bind_null (stmt_sect, 4);
	  if (xml_summary != NULL)
	      free (xml_summary);
      }
    sqlite3_bind_int (stmt_sect, 5, width);
    sqlite3_bind_int (stmt_sect, 6, height);
    if (rl2_build_bbox
	(handle, srid, minx, miny, maxx, maxy, &blob, &blob_size) != RL2_OK)
	goto error;
    sqlite3_bind_blob (stmt_sect, 7, blob, blob_size, free);
    ret = sqlite3_step (stmt_sect);
    if (ret == SQLITE_DONE || ret == SQLITE_ROW)
	section_id = sqlite3_last_insert_rowid (handle);
    else
      {
................................................................................
    int blob_odd_sz;
    unsigned char *blob_even;
    int blob_even_sz;
    rl2RasterPtr raster = NULL;
    double base_res_x;
    double base_res_y;

    if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y)
	!= RL2_OK)
	goto error;
    if (*first)
      {
	  /* INSERTing the section */
	  *first = 0;
	  if (!rl2_do_insert_section
	      (ptr->sqlite, "WMS Service", ptr->sect_name, ptr->srid,
	       ptr->width, ptr->height, ptr->minx, ptr->miny, ptr->maxx,
	       ptr->maxy, ptr->xml_summary, ptr->sectionPaths,
	       ptr->sectionMD5, ptr->sectionSummary, ptr->stmt_sect,
	       section_id))
	      goto error;
	  *section_stats =
	      rl2_create_raster_statistics (ptr->sample_type, ptr->num_bands);
	  if (*section_stats == NULL)
	      goto error;
	  /* INSERTing the base-levels */
	  if (ptr->mixedResolutions)
................................................................................
    /* INSERTing the tile */
    tile_minx = ptr->x;
    tile_maxx = tile_minx + ptr->tilew;
    tile_maxy = ptr->y;
    tile_miny = tile_maxy - ptr->tileh;
    if (!do_insert_wms_tile
	(ptr->sqlite, blob_odd, blob_odd_sz, blob_even, blob_even_sz,
	 *section_id, ptr->srid, ptr->horz_res, ptr->vert_res,
	 ptr->tile_width, ptr->tile_height, ptr->miny, ptr->maxx, tile_minx,
	 tile_miny, tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils,
	 ptr->stmt_data, *section_stats))
	goto error;
    blob_odd = NULL;
    blob_even = NULL;
    rl2_destroy_raster (raster);
    free (ptr->rgba_tile);
    ptr->rgba_tile = NULL;
................................................................................
	  xxcoverage = rl2_double_quoted_sql (xcoverage);
	  sqlite3_free (xcoverage);
	  sql =
	      sqlite3_mprintf
	      ("SELECT pyramid_level, x_resolution_1_8, y_resolution_1_8, "
	       "x_resolution_1_4, y_resolution_1_4, x_resolution_1_2, y_resolution_1_2, "
	       "x_resolution_1_1, y_resolution_1_1 FROM \"%s\" "
	       "WHERE section_id = %s ORDER BY pyramid_level DESC",
	       xxcoverage, sctn);
      }
    else
      {
	  /* ordinary Coverage */
	  xcoverage = sqlite3_mprintf ("%s_levels", coverage);
	  xxcoverage = rl2_double_quoted_sql (xcoverage);
	  sqlite3_free (xcoverage);
................................................................................
	    }
      }
    return rgba;
}

RL2_PRIVATE int
get_payload_from_monochrome_opaque (unsigned int width, unsigned int height,
				    sqlite3 * handle, double minx,
				    double miny, double maxx, double maxy,
				    int srid, unsigned char *pixels,
				    unsigned char format, int quality,
				    unsigned char **image, int *image_sz)
{
/* input: Monochrome    output: Grayscale */
    int ret;
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned char *gray = NULL;
    unsigned int row;
................................................................................
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_TIFF)
      {
	  if (srid > 0)
	    {
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     gray, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
		    RL2_OK)
		    goto error;
................................................................................
		    goto error;
	    }
	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
	    {
		if (srid > 0)
		  {
		      if (rl2_rgb_to_geotiff
			  (width, height, handle, minx, miny, maxx, maxy,
			   srid, rgb, image, image_sz) != RL2_OK)
			  goto error;
		  }
		else
		  {
		      if (rl2_rgb_to_tiff
			  (width, height, rgb, image, image_sz) != RL2_OK)
			  goto error;
		  }
	    }
	  else if (format == RL2_OUTPUT_FORMAT_PDF)
	    {
		rgba = rgb_to_rgba (width, height, rgb);
		if (rgba == NULL)
................................................................................
		    goto error;
	    }
	  else if (format == RL2_OUTPUT_FORMAT_TIFF)
	    {
		if (srid > 0)
		  {
		      if (rl2_gray_to_geotiff
			  (width, height, handle, minx, miny, maxx, maxy,
			   srid, gray, image, image_sz) != RL2_OK)
			  goto error;
		  }
		else
		  {
		      if (rl2_gray_to_tiff
			  (width, height, gray, image, image_sz) != RL2_OK)
			  goto error;
................................................................................
    return 0;
}

RL2_PRIVATE int
get_payload_from_grayscale_opaque (unsigned int width, unsigned int height,
				   sqlite3 * handle, double minx, double miny,
				   double maxx, double maxy, int srid,
				   unsigned char *pixels,
				   unsigned char format, int quality,
				   unsigned char **image, int *image_sz)
{
/* input: Grayscale    output: Grayscale */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_gray_to_jpeg
	      (width, height, pixels, quality, image, image_sz) != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_gray_to_png (width, height, pixels, image, image_sz) !=
	      RL2_OK)
	      goto error;
................................................................................
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     pixels, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, pixels, image, image_sz)
		    != RL2_OK)
		    goto error;
	    }
      }
    else if (format == RL2_OUTPUT_FORMAT_PDF)
      {
	  rgba = gray_to_rgba (width, height, pixels);
	  if (rgba == NULL)
................................................................................
{
/* input: RGB    output: RGB */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_rgb_to_jpeg
	      (width, height, pixels, quality, image, image_sz) != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_rgb_to_png (width, height, pixels, image, image_sz) != RL2_OK)
	      goto error;
      }
................................................................................
		if (rl2_rgb_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     pixels, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz)
		    != RL2_OK)
		    goto error;
	    }
      }
    else if (format == RL2_OUTPUT_FORMAT_PDF)
      {
	  rgba = rgb_to_rgba (width, height, pixels);
	  if (rgba == NULL)
................................................................................
}

RL2_PRIVATE int
get_payload_from_rgb_transparent (unsigned int width, unsigned int height,
				  unsigned char *pixels, unsigned char format,
				  int quality, unsigned char **image,
				  int *image_sz, unsigned char bg_red,
				  unsigned char bg_green,
				  unsigned char bg_blue, double opacity)
{
/* input: RGB    output: RGB */
    unsigned char *p_in;
    unsigned char *p_msk;
    unsigned char *mask = NULL;
    unsigned int row;
    unsigned int col;
................................................................................
				 unsigned char *pixels, unsigned char *rgba)
{
/* input: Monochrome    output: Grayscale */
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned int row;
    unsigned int col;

    p_in = pixels;
    p_out = rgba;
    for (row = 0; row < height; row++)
      {
	  for (col = 0; col < width; col++)
	    {
		if (*p_in++ == 0)
		  {
		      *p_out++ = 0;	/* Black */
		      *p_out++ = 0;
		      *p_out++ = 0;
		      *p_out++ = 255;	/* alpha */
		  }
		else
................................................................................

    p_in = pixels;
    p_out = rgba;
    for (row = 0; row < height; row++)
      {
	  for (col = 0; col < width; col++)
	    {
		if (*p_in++ == 0)
		  {
		      *p_out++ = 0;	/* Black */
		      *p_out++ = 0;
		      *p_out++ = 0;
		      *p_out++ = 255;	/* alpha */
		  }
		else
................................................................................
  error:
    free (pixels);
    return 0;
}

RL2_PRIVATE int
get_rgba_from_palette_transparent (unsigned int width, unsigned int height,
				   unsigned char *pixels,
				   rl2PalettePtr palette, unsigned char *rgba,
				   unsigned char bg_red,
				   unsigned char bg_green,
				   unsigned char bg_blue)
{
/* input: Palette    output: Grayscale or RGB */
    rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette;
    unsigned char *p_in;
    unsigned char *p_out;
................................................................................
    free (pixels);
    return 1;
}

RL2_PRIVATE int
get_rgba_from_grayscale_transparent (unsigned int width,
				     unsigned int height,
				     unsigned char *pixels,
				     unsigned char *rgba, unsigned char bg_gray)
{
/* input: Grayscale    output: Grayscale */
    unsigned char *p_in;
    unsigned char *p_out;
    unsigned int row;
    unsigned int col;

................................................................................
    if (mask != NULL)
	free (mask);
    return 1;
}

RL2_PRIVATE int
rgba_from_double (unsigned int width, unsigned int height,
		  double *pixels, unsigned char *mask,
		  rl2PrivPixelPtr no_data, unsigned char *rgba)
{
/* input: DataGrid DOUBLE   output: Grayscale */
    double *p_in;
    unsigned char *p_out;
    unsigned char *p_msk;
    unsigned int row;
    unsigned int col;
................................................................................
      case RL2_SAMPLE_INT16:
	  ret =
	      rgba_from_int16 (width, height, (short *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_UINT16:
	  ret =
	      rgba_from_uint16 (width, height, (unsigned short *) pixels,
				mask, no_data, rgba);
	  break;
      case RL2_SAMPLE_INT32:
	  ret =
	      rgba_from_int32 (width, height, (int *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_UINT32:
................................................................................
      case RL2_SAMPLE_FLOAT:
	  ret =
	      rgba_from_float (width, height, (float *) pixels, mask, no_data,
			       rgba);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  ret =
	      rgba_from_double (width, height, (double *) pixels, mask,
				no_data, rgba);
	  break;
      };
    return ret;
}

RL2_PRIVATE int
rgba_from_multi_uint8 (unsigned int width, unsigned int height,
................................................................................
	      rgba_from_multi_uint8 (width, height, num_bands,
				     (unsigned char *) pixels, mask, no_data,
				     rgba);
	  break;
      case RL2_SAMPLE_UINT16:
	  ret =
	      rgba_from_multi_uint16 (width, height, num_bands,
				      (unsigned short *) pixels, mask,
				      no_data, rgba);
	  break;
      };
    return ret;
}

RL2_PRIVATE int
get_payload_from_gray_rgba_opaque (unsigned int width, unsigned int height,
................................................................................
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_TIFF)
      {
	  if (srid > 0)
	    {
		if (rl2_gray_to_geotiff
		    (width, height, handle, minx, miny, maxx, maxy, srid,
		     gray, image, image_sz) != RL2_OK)
		    goto error;
	    }
	  else
	    {
		if (rl2_gray_to_tiff (width, height, gray, image, image_sz) !=
		    RL2_OK)
		    goto error;
................................................................................
{
/* RGB, Opaque */
    int ret;
    unsigned char *rgba = NULL;

    if (format == RL2_OUTPUT_FORMAT_JPEG)
      {
	  if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz)
	      != RL2_OK)
	      goto error;
      }
    else if (format == RL2_OUTPUT_FORMAT_PNG)
      {
	  if (rl2_rgb_to_png (width, height, rgb, image, image_sz) != RL2_OK)
	      goto error;
      }
................................................................................
	free (rgba);
    return 0;
}

RL2_PRIVATE int
get_payload_from_rgb_rgba_transparent (unsigned int width,
				       unsigned int height,
				       unsigned char *rgb,
				       unsigned char *alpha,
				       unsigned char format, int quality,
				       unsigned char **image, int *image_sz,
				       double opacity, int half_transparency)
{
/* RGB, Transparent */
    int ret;
    unsigned char *p_msk;

Changes to src/rl2svg.c.

227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
242
...
257
258
259
260
261
262
263
264


265
266
267
268
269
270
271
272
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
310
311
312
313
314
315
316
317


318
319
320
321
322
323
324
325
...
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
345
...
846
847
848
849
850
851
852

853
854
855

856
857
858
859
860
861
862
863
864
...
943
944
945
946
947
948
949

950
951
952

953
954
955
956
957
958
959
960
961
		pattern =
		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
						 grad->y2);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,


							 stop->red, stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
		pattern =
		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
						 grad->fx, grad->fy, grad->r);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,


							 stop->red, stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
			   style->stroke_opacity * style->opacity);
    cairo_set_line_cap (cairo, style->stroke_linecap);
    cairo_set_line_join (cairo, style->stroke_linejoin);
    cairo_set_miter_limit (cairo, style->stroke_miterlimit);
    if (style->stroke_dashitems == 0 || style->stroke_dasharray == NULL)
	cairo_set_dash (cairo, lengths, 0, 0.0);
    else
	cairo_set_dash (cairo, style->stroke_dasharray, style->stroke_dashitems,
			style->stroke_dashoffset);
}

static void
svg_set_brush (cairo_t * cairo, rl2PrivSvgStylePtr style)
{
/* setting up a Brush for Cairo */
    cairo_pattern_t *pattern;
................................................................................
		pattern =
		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
						 grad->y2);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,


							 stop->red, stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_pattern_destroy (pattern);
................................................................................
		pattern =
		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
						 grad->fx, grad->fy, grad->r);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,


							 stop->red, stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_pattern_destroy (pattern);
................................................................................
		bezier = item->data;
		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
				bezier->y2, bezier->x, bezier->y);
		break;
	    case RL2_SVG_CURVE_4:
		bezier = item->data;
		cairo_get_current_point (cairo, &x0, &y0);

		cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2,

				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2,
				bezier->y1, bezier->y2);
		break;
	    case RL2_SVG_ELLIPT_ARC:
		arc = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
				  &radii_ratio, &angle1, &angle2);
		cairo_save (cairo);
................................................................................
		bezier = item->data;
		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
				bezier->y2, bezier->x, bezier->y);
		break;
	    case RL2_SVG_CURVE_4:
		bezier = item->data;
		cairo_get_current_point (cairo, &x0, &y0);

		cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2,

				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2,
				bezier->y1, bezier->y2);
		break;
	    case RL2_SVG_ELLIPT_ARC:
		arc = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
				  &radii_ratio, &angle1, &angle2);
		cairo_save (cairo);







|
>
>
|







 







|
>
>
|







 







|
|







 







|
>
>
|







 







|
>
>
|







 







>
|

|
>
|
|







 







>
|

|
>
|
|







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
...
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
		pattern =
		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
						 grad->y2);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern,
							 stop->offset,
							 stop->red,
							 stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
		pattern =
		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
						 grad->fx, grad->fy, grad->r);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern,
							 stop->offset,
							 stop->red,
							 stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_set_line_cap (cairo, style->stroke_linecap);
................................................................................
			   style->stroke_opacity * style->opacity);
    cairo_set_line_cap (cairo, style->stroke_linecap);
    cairo_set_line_join (cairo, style->stroke_linejoin);
    cairo_set_miter_limit (cairo, style->stroke_miterlimit);
    if (style->stroke_dashitems == 0 || style->stroke_dasharray == NULL)
	cairo_set_dash (cairo, lengths, 0, 0.0);
    else
	cairo_set_dash (cairo, style->stroke_dasharray,
			style->stroke_dashitems, style->stroke_dashoffset);
}

static void
svg_set_brush (cairo_t * cairo, rl2PrivSvgStylePtr style)
{
/* setting up a Brush for Cairo */
    cairo_pattern_t *pattern;
................................................................................
		pattern =
		    cairo_pattern_create_linear (grad->x1, grad->y1, grad->x2,
						 grad->y2);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern,
							 stop->offset,
							 stop->red,
							 stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_pattern_destroy (pattern);
................................................................................
		pattern =
		    cairo_pattern_create_radial (grad->cx, grad->cy, 0.0,
						 grad->fx, grad->fy, grad->r);
		svg_apply_gradient_transformations (pattern, grad);
		stop = grad->first_stop;
		while (stop)
		  {
		      cairo_pattern_add_color_stop_rgba (pattern,
							 stop->offset,
							 stop->red,
							 stop->green,
							 stop->blue,
							 stop->opacity *
							 style->opacity);
		      stop = stop->next;
		  }
		cairo_set_source (cairo, pattern);
		cairo_pattern_destroy (pattern);
................................................................................
		bezier = item->data;
		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
				bezier->y2, bezier->x, bezier->y);
		break;
	    case RL2_SVG_CURVE_4:
		bezier = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		cairo_curve_to (cairo,
				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
				2.0 / 3.0 * bezier->x1 +
				1.0 / 3.0 * bezier->x2,
				2.0 / 3.0 * bezier->y1 +
				1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2);
		break;
	    case RL2_SVG_ELLIPT_ARC:
		arc = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
				  &radii_ratio, &angle1, &angle2);
		cairo_save (cairo);
................................................................................
		bezier = item->data;
		cairo_curve_to (cairo, bezier->x1, bezier->y1, bezier->x2,
				bezier->y2, bezier->x, bezier->y);
		break;
	    case RL2_SVG_CURVE_4:
		bezier = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		cairo_curve_to (cairo,
				2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0,
				2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0,
				2.0 / 3.0 * bezier->x1 +
				1.0 / 3.0 * bezier->x2,
				2.0 / 3.0 * bezier->y1 +
				1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2);
		break;
	    case RL2_SVG_ELLIPT_ARC:
		arc = item->data;
		cairo_get_current_point (cairo, &x0, &y0);
		svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation,
				  &radii_ratio, &angle1, &angle2);
		cairo_save (cairo);

Changes to src/rl2symbaux.c.

782
783
784
785
786
787
788


789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
...
824
825
826
827
828
829
830
831

832
833
834
835
836
837
838
...
845
846
847
848
849
850
851

852
853

854
855
856
857
858
859
860
...
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879

880
881
882
883
884
885
886
...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
...
907
908
909
910
911
912
913





914
915
916
917
918
919
920
....
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
1118
....
1171
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
....
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1216
1217
....
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
....
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
....
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
....
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
....
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
....
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
....
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
....
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
....
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
....
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
....
2437
2438
2439
2440
2441
2442
2443
2444

2445
2446
2447
2448
2449
2450
2451
2452
....
3111
3112
3113
3114
3115
3116
3117

3118
3119
3120
3121
3122
3123
3124
3125
....
3188
3189
3190
3191
3192
3193
3194
3195

3196
3197
3198
3199
3200
3201
3202
3203
....
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
....
3370
3371
3372
3373
3374
3375
3376
3377

3378
3379
3380
3381
3382
3383
3384
3385
....
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
....
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209

static int
eval_filter (rl2PrivStyleRulePtr rule, rl2VariantArrayPtr variant)
{
/* evaluating a Rule Filter */
    int i;
    rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;


    if (rule == NULL || var == NULL)
	return 1;
    for (i = 0; i < var->count; i++)
      {
	  rl2PrivVariantValuePtr val = *(var->array + i);
	  if (val == NULL)
	      return 0;
	  if (rule->column_name == NULL || val->column_name == NULL)
	      return 0;
	  if (strcasecmp (rule->column_name, val->column_name) != 0)
	      continue;
	  switch (rule->comparison_op)
	    {
	    case RL2_COMPARISON_EQ:
		return eval_filter_eq (rule, val);
................................................................................
      }
    return 0;
}

RL2_DECLARE rl2VectorSymbolizerPtr
rl2_get_symbolizer_from_feature_type_style (rl2FeatureTypeStylePtr style,
					    double scale,
					    rl2VariantArrayPtr variant, int *scale_forbidden)

{
/* return the VectorSymbolizer matching a given scale/filter from a FeatureTypeStyle */
    rl2PrivVectorSymbolizerPtr symbolizer = NULL;
    rl2PrivStyleRulePtr pR;
    rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
    *scale_forbidden = 0;
    if (stl == NULL)
................................................................................
	      ;
	  else
	    {
		/* skipping any invalid rule */
		pR = pR->next;
		continue;
	    }

	  if (eval_filter (pR, variant))
	    {

		if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
		  {
		      if (scale >= pR->min_scale && scale < pR->max_scale)
			  symbolizer = pR->style;
		  }
		else if (pR->min_scale != DBL_MAX)
		  {
................................................................................
		else if (pR->max_scale != DBL_MAX)
		  {
		      if (scale < pR->max_scale)
			  symbolizer = pR->style;
		  }
		else
		    symbolizer = pR->style;
		    if (symbolizer == NULL)
		    *scale_forbidden = 1;

		return (rl2VectorSymbolizerPtr) symbolizer;
	    }
	  pR = pR->next;
      }
    if (stl->else_rule != NULL)
      {
	  /* applyhing the ELSE rule */

	  pR = stl->else_rule;
	  if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
	    {
		if (scale >= pR->min_scale && scale < pR->max_scale)
		    symbolizer = pR->style;
	    }
	  else if (pR->min_scale != DBL_MAX)
................................................................................
	  else if (pR->max_scale != DBL_MAX)
	    {
		if (scale < pR->max_scale)
		    symbolizer = pR->style;
	    }
	  else
	      symbolizer = pR->style;
		    if (symbolizer == NULL)
		    *scale_forbidden = 1;
      }
    return (rl2VectorSymbolizerPtr) symbolizer;
}

RL2_DECLARE int
rl2_is_visible_style (rl2FeatureTypeStylePtr style, double scale)
{
................................................................................
/* test visibility at a given scale/filter from a FeatureTypeStyle */
    int count = 0;
    int visible;
    rl2PrivStyleRulePtr pR;
    rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
    if (stl == NULL)
	return 0;






    pR = stl->first_rule;
    while (pR != NULL)
      {
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	      ;
	  else
................................................................................
	    {
		/* Interpolate Color Map */
		*selected = 1;
		*categorize = 0;
		*interpolate = 1;
		return RL2_OK;
	    }
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||

	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*selected = 1;
		*categorize = 0;
		*interpolate = 0;
		return RL2_OK;
	    }
................................................................................
{
/* return if the RasterSymbolizer has a TripleBand selection */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
      {
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||

	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*selected = 1;
		return RL2_OK;
	    }
      }
    if (stl->bandSelection == NULL)
................................................................................
{
/* return the RasterSymbolizer TripleBand selection */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
      {
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE ||

	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM ||
	      stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*red_band = 0;
		*green_band = 1;
		*blue_band = 2;
		return RL2_OK;
	    }
................................................................................
	return RL2_ERROR;
    *contrast_enhancement = stl->contrastEnhancement;
    *gamma_value = stl->gammaValue;
    return RL2_OK;
}

RL2_DECLARE int
rl2_get_raster_symbolizer_red_band_contrast_enhancement (rl2RasterSymbolizerPtr
							 style,
							 unsigned char
							 *contrast_enhancement,
							 double *gamma_value)
{
/* return the RasterSymbolizer RedBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *gamma_value = stl->bandSelection->greenGamma;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raster_symbolizer_blue_band_contrast_enhancement (rl2RasterSymbolizerPtr
							  style,
							  unsigned char
							  *contrast_enhancement,
							  double *gamma_value)
{
/* return the RasterSymbolizer BlueBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *gamma_value = stl->bandSelection->blueGamma;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raster_symbolizer_gray_band_contrast_enhancement (rl2RasterSymbolizerPtr
							  style,
							  unsigned char
							  *contrast_enhancement,
							  double *gamma_value)
{
/* return the RasterSymbolizer GrayBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *relief_factor = stl->reliefFactor;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr style,
						  int *interpolated)
{
/* return if the RasterSymbolizer has an Interpolated ColorMap */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->interpolate != NULL)
	*interpolated = 1;
................................................................................
	  *blue = stl->categorize->dfltBlue;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr style,
						   unsigned char *red,
						   unsigned char *green,
						   unsigned char *blue)
{
/* return the RasterSymbolizer ColorMap Category base-color */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
................................................................................
/* creating a default Graphic object) */
    rl2PrivGraphicPtr graphic = malloc (sizeof (rl2PrivGraphic));
    graphic->first = NULL;
    graphic->last = NULL;
    graphic->opacity = 1.0;
    graphic->size = 10.0;
    graphic->rotation = 0.0;
    graphic->anchor_point_x = 0.0;
    graphic->anchor_point_y = 0.0;
    graphic->displacement_x = 0.0;
    graphic->displacement_y = 0.0;
    return graphic;
}

RL2_PRIVATE rl2PrivStrokePtr
rl2_create_default_stroke ()
................................................................................
}

RL2_PRIVATE rl2PrivPointPlacementPtr
rl2_create_default_point_placement ()
{
/* creating a default PointPlacement object */
    rl2PrivPointPlacementPtr place = malloc (sizeof (rl2PrivPointPlacement));
    place->anchor_point_x = 0.0;
    place->anchor_point_y = 0.0;
    place->displacement_x = 0.0;
    place->displacement_y = 0.0;
    place->rotation = 0.0;
    return place;
}

RL2_PRIVATE rl2PrivLinePlacementPtr
................................................................................
    if (sym->stroke->graphic->first->type != RL2_EXTERNAL_GRAPHIC)
	return NULL;
    ext = (rl2PrivExternalGraphicPtr) (sym->stroke->graphic->first->item);
    return ext->xlink_href;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_graphic_stroke_recode_count (rl2PolygonSymbolizerPtr
							symbolizer, int *count)
{
/* return how many ColorReplacement items are in a Graphic Stroke (PolygonSymbolizer) */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    *count = 0;
    if (sym->stroke != NULL)
................................................................................
		  }
	    }
      }
    return RL2_OK;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_graphic_stroke_recode_color (rl2PolygonSymbolizerPtr
							symbolizer, int index,
							int *color_index,
							unsigned char *red,
							unsigned char *green,
							unsigned char *blue)
{
/* return a ColorReplacement item from a Graphic Stroke (PolygonSymbolizer) */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke != NULL)
      {
................................................................................
    if (sym->stroke == NULL)
	return RL2_ERROR;
    *width = sym->stroke->width;
    return RL2_OK;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr symbolizer,
					    unsigned char *linejoin)
{
/* return the Polygon Symbolizer Stroke Linejoin mode */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke == NULL)
	return RL2_ERROR;
................................................................................
    if (sym->stroke == NULL)
	return RL2_ERROR;
    *count = sym->stroke->dash_count;
    return RL2_OK;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr symbolizer,

					     int index, double *item)
{
/* return a Polygon Symbolizer Stroke Dash item */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke == NULL)
	return RL2_ERROR;
................................................................................
      }
    return NULL;
}

RL2_DECLARE int
rl2_point_symbolizer_get_graphic_recode_color (rl2PointSymbolizerPtr
					       symbolizer, int index,

					       int repl_index, int *color_index,
					       unsigned char *red,
					       unsigned char *green,
					       unsigned char *blue)
{
/* return a ColorReplacement item from an External Graphic (PointSymbolizer) */
    int count = 0;
    rl2PrivExternalGraphicPtr ext;
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr symbolizer,

					       int index, unsigned char *type)
{
/* return the Point Symbolizer Mark WellKnownType */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr symbolizer,
					       int index,
					       unsigned char *linejoin)
{
/* return the Point Symbolizer Mark Stroke Linejoin mode */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr symbolizer,

					      int index, unsigned char *linecap)
{
/* return the Point Symbolizer Stroke Mark Linecap mode */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
	  count++;
	  itm = itm->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer, int index,
				    int *fill)
{
/* checks if a Point Symbolizer Mark has a Fill */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
    if (*(var->array + index) != NULL)
	rl2_destroy_variant_value (*(var->array + index));
    *(var->array + index) = val;
    return RL2_OK;
}

RL2_DECLARE int
rl2_set_variant_double (rl2VariantArrayPtr variant, int index, const char *name,
			double value)
{
/* setting a DOUBLE VariantValue into a VariantArray object */
    rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;
    rl2PrivVariantValuePtr val;
    if (var == NULL)
	return RL2_ERROR;
    if (index >= 0 && index < var->count)







>
>
|
|





|







 







|
>







 







>


>







 







|

>
|






>







 







|
|







 







>
>
>
>
>







 







|
>
|
|







 







|
>
|
|







 







|
>
|
|







 







|
<
<
|
|







 







|
<
<
|
|







 







|
<
<
|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|
<
<
|
<







 







|
|







 







|
>
|







 







>
|







 







|
>
|







 







|
|







 







|
>
|







 







|
|







 







|
|







782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
...
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
...
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
...
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
...
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
....
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
....
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
....
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
....
1257
1258
1259
1260
1261
1262
1263
1264


1265
1266
1267
1268
1269
1270
1271
1272
1273
....
1297
1298
1299
1300
1301
1302
1303
1304


1305
1306
1307
1308
1309
1310
1311
1312
1313
....
1317
1318
1319
1320
1321
1322
1323
1324


1325
1326
1327
1328
1329
1330
1331
1332
1333
....
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
....
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
....
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
....
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
....
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
....
2310
2311
2312
2313
2314
2315
2316
2317
2318


2319

2320
2321
2322
2323
2324
2325
2326
....
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
....
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
....
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
....
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
....
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
....
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
....
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
....
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219

static int
eval_filter (rl2PrivStyleRulePtr rule, rl2VariantArrayPtr variant)
{
/* evaluating a Rule Filter */
    int i;
    rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;
    if (rule->column_name == NULL)
	return 1;		/* there is no comparison: surely true */
    if (var == NULL)
	return 0;
    for (i = 0; i < var->count; i++)
      {
	  rl2PrivVariantValuePtr val = *(var->array + i);
	  if (val == NULL)
	      return 0;
	  if (val->column_name == NULL)
	      return 0;
	  if (strcasecmp (rule->column_name, val->column_name) != 0)
	      continue;
	  switch (rule->comparison_op)
	    {
	    case RL2_COMPARISON_EQ:
		return eval_filter_eq (rule, val);
................................................................................
      }
    return 0;
}

RL2_DECLARE rl2VectorSymbolizerPtr
rl2_get_symbolizer_from_feature_type_style (rl2FeatureTypeStylePtr style,
					    double scale,
					    rl2VariantArrayPtr variant,
					    int *scale_forbidden)
{
/* return the VectorSymbolizer matching a given scale/filter from a FeatureTypeStyle */
    rl2PrivVectorSymbolizerPtr symbolizer = NULL;
    rl2PrivStyleRulePtr pR;
    rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
    *scale_forbidden = 0;
    if (stl == NULL)
................................................................................
	      ;
	  else
	    {
		/* skipping any invalid rule */
		pR = pR->next;
		continue;
	    }

	  if (eval_filter (pR, variant))
	    {
		*scale_forbidden = 0;
		if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
		  {
		      if (scale >= pR->min_scale && scale < pR->max_scale)
			  symbolizer = pR->style;
		  }
		else if (pR->min_scale != DBL_MAX)
		  {
................................................................................
		else if (pR->max_scale != DBL_MAX)
		  {
		      if (scale < pR->max_scale)
			  symbolizer = pR->style;
		  }
		else
		    symbolizer = pR->style;
		if (symbolizer == NULL)
		    *scale_forbidden = 1;
		else
		    return (rl2VectorSymbolizerPtr) symbolizer;
	    }
	  pR = pR->next;
      }
    if (stl->else_rule != NULL)
      {
	  /* applyhing the ELSE rule */
	  *scale_forbidden = 0;
	  pR = stl->else_rule;
	  if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX)
	    {
		if (scale >= pR->min_scale && scale < pR->max_scale)
		    symbolizer = pR->style;
	    }
	  else if (pR->min_scale != DBL_MAX)
................................................................................
	  else if (pR->max_scale != DBL_MAX)
	    {
		if (scale < pR->max_scale)
		    symbolizer = pR->style;
	    }
	  else
	      symbolizer = pR->style;
	  if (symbolizer == NULL)
	      *scale_forbidden = 1;
      }
    return (rl2VectorSymbolizerPtr) symbolizer;
}

RL2_DECLARE int
rl2_is_visible_style (rl2FeatureTypeStylePtr style, double scale)
{
................................................................................
/* test visibility at a given scale/filter from a FeatureTypeStyle */
    int count = 0;
    int visible;
    rl2PrivStyleRulePtr pR;
    rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style;
    if (stl == NULL)
	return 0;
    if (stl->first_rule == NULL)
      {
	  /* there are no rules: unconditional visibility */
	  return 1;
      }

    pR = stl->first_rule;
    while (pR != NULL)
      {
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	      ;
	  else
................................................................................
	    {
		/* Interpolate Color Map */
		*selected = 1;
		*categorize = 0;
		*interpolate = 1;
		return RL2_OK;
	    }
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
	      || stl->contrastEnhancement ==
	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*selected = 1;
		*categorize = 0;
		*interpolate = 0;
		return RL2_OK;
	    }
................................................................................
{
/* return if the RasterSymbolizer has a TripleBand selection */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
      {
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
	      || stl->contrastEnhancement ==
	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*selected = 1;
		return RL2_OK;
	    }
      }
    if (stl->bandSelection == NULL)
................................................................................
{
/* return the RasterSymbolizer TripleBand selection */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
      {
	  if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE
	      || stl->contrastEnhancement ==
	      RL2_CONTRAST_ENHANCEMENT_HISTOGRAM
	      || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA)
	    {
		/* Contrast Enhancement */
		*red_band = 0;
		*green_band = 1;
		*blue_band = 2;
		return RL2_OK;
	    }
................................................................................
	return RL2_ERROR;
    *contrast_enhancement = stl->contrastEnhancement;
    *gamma_value = stl->gammaValue;
    return RL2_OK;
}

RL2_DECLARE int
    rl2_get_raster_symbolizer_red_band_contrast_enhancement


    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
     double *gamma_value)
{
/* return the RasterSymbolizer RedBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *gamma_value = stl->bandSelection->greenGamma;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
    rl2_get_raster_symbolizer_blue_band_contrast_enhancement


    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
     double *gamma_value)
{
/* return the RasterSymbolizer BlueBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *gamma_value = stl->bandSelection->blueGamma;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
    rl2_get_raster_symbolizer_gray_band_contrast_enhancement


    (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement,
     double *gamma_value)
{
/* return the RasterSymbolizer GrayBand ContrastEnhancement */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->bandSelection == NULL)
	return RL2_ERROR;
................................................................................
	  *relief_factor = stl->reliefFactor;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr
						  style, int *interpolated)
{
/* return if the RasterSymbolizer has an Interpolated ColorMap */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
    if (stl->interpolate != NULL)
	*interpolated = 1;
................................................................................
	  *blue = stl->categorize->dfltBlue;
	  return RL2_OK;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr
						   style, unsigned char *red,
						   unsigned char *green,
						   unsigned char *blue)
{
/* return the RasterSymbolizer ColorMap Category base-color */
    rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style;
    if (stl == NULL)
	return RL2_ERROR;
................................................................................
/* creating a default Graphic object) */
    rl2PrivGraphicPtr graphic = malloc (sizeof (rl2PrivGraphic));
    graphic->first = NULL;
    graphic->last = NULL;
    graphic->opacity = 1.0;
    graphic->size = 10.0;
    graphic->rotation = 0.0;
    graphic->anchor_point_x = 0.5;
    graphic->anchor_point_y = 0.5;
    graphic->displacement_x = 0.0;
    graphic->displacement_y = 0.0;
    return graphic;
}

RL2_PRIVATE rl2PrivStrokePtr
rl2_create_default_stroke ()
................................................................................
}

RL2_PRIVATE rl2PrivPointPlacementPtr
rl2_create_default_point_placement ()
{
/* creating a default PointPlacement object */
    rl2PrivPointPlacementPtr place = malloc (sizeof (rl2PrivPointPlacement));
    place->anchor_point_x = 0.5;
    place->anchor_point_y = 0.5;
    place->displacement_x = 0.0;
    place->displacement_y = 0.0;
    place->rotation = 0.0;
    return place;
}

RL2_PRIVATE rl2PrivLinePlacementPtr
................................................................................
    if (sym->stroke->graphic->first->type != RL2_EXTERNAL_GRAPHIC)
	return NULL;
    ext = (rl2PrivExternalGraphicPtr) (sym->stroke->graphic->first->item);
    return ext->xlink_href;
}

RL2_DECLARE int
    rl2_polygon_symbolizer_get_graphic_stroke_recode_count
    (rl2PolygonSymbolizerPtr symbolizer, int *count)
{
/* return how many ColorReplacement items are in a Graphic Stroke (PolygonSymbolizer) */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    *count = 0;
    if (sym->stroke != NULL)
................................................................................
		  }
	    }
      }
    return RL2_OK;
}

RL2_DECLARE int
    rl2_polygon_symbolizer_get_graphic_stroke_recode_color
    (rl2PolygonSymbolizerPtr symbolizer, int index, int *color_index,


     unsigned char *red, unsigned char *green, unsigned char *blue)

{
/* return a ColorReplacement item from a Graphic Stroke (PolygonSymbolizer) */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke != NULL)
      {
................................................................................
    if (sym->stroke == NULL)
	return RL2_ERROR;
    *width = sym->stroke->width;
    return RL2_OK;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr
					    symbolizer, unsigned char *linejoin)
{
/* return the Polygon Symbolizer Stroke Linejoin mode */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke == NULL)
	return RL2_ERROR;
................................................................................
    if (sym->stroke == NULL)
	return RL2_ERROR;
    *count = sym->stroke->dash_count;
    return RL2_OK;
}

RL2_DECLARE int
rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr
					     symbolizer, int index,
					     double *item)
{
/* return a Polygon Symbolizer Stroke Dash item */
    rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer;
    if (sym == NULL)
	return RL2_ERROR;
    if (sym->stroke == NULL)
	return RL2_ERROR;
................................................................................
      }
    return NULL;
}

RL2_DECLARE int
rl2_point_symbolizer_get_graphic_recode_color (rl2PointSymbolizerPtr
					       symbolizer, int index,
					       int repl_index,
					       int *color_index,
					       unsigned char *red,
					       unsigned char *green,
					       unsigned char *blue)
{
/* return a ColorReplacement item from an External Graphic (PointSymbolizer) */
    int count = 0;
    rl2PrivExternalGraphicPtr ext;
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr
					       symbolizer, int index,
					       unsigned char *type)
{
/* return the Point Symbolizer Mark WellKnownType */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr
					       symbolizer, int index,
					       unsigned char *linejoin)
{
/* return the Point Symbolizer Mark Stroke Linejoin mode */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
................................................................................
	  count++;
	  item = item->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr
					      symbolizer, int index,
					      unsigned char *linecap)
{
/* return the Point Symbolizer Stroke Mark Linecap mode */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
	  count++;
	  itm = itm->next;
      }
    return RL2_ERROR;
}

RL2_DECLARE int
rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer,
				    int index, int *fill)
{
/* checks if a Point Symbolizer Mark has a Fill */
    int count = 0;
    rl2PrivMarkPtr mark;
    rl2PrivGraphicItemPtr item;
    rl2PrivPointSymbolizerPtr sym = (rl2PrivPointSymbolizerPtr) symbolizer;
    if (sym == NULL)
................................................................................
    if (*(var->array + index) != NULL)
	rl2_destroy_variant_value (*(var->array + index));
    *(var->array + index) = val;
    return RL2_OK;
}

RL2_DECLARE int
rl2_set_variant_double (rl2VariantArrayPtr variant, int index,
			const char *name, double value)
{
/* setting a DOUBLE VariantValue into a VariantArray object */
    rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant;
    rl2PrivVariantValuePtr val;
    if (var == NULL)
	return RL2_ERROR;
    if (index >= 0 && index < var->count)

Changes to src/rl2symbolizer.c.

540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
....
1056
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
....
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
....
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556

1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
....
1825
1826
1827
1828
1829
1830
1831

1832
1833
1834
1835
1836
1837
1838
1839

1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855

1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
....
2024
2025
2026
2027
2028
2029
2030

2031
2032
2033
2034
2035
2036
2037
2038

2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054

2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
....
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
....
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
....
3016
3017
3018
3019
3020
3021
3022
3023

3024
3025
3026

3027
3028
3029
3030
3031
3032
3033
....
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
....
4059
4060
4061
4062
4063
4064
4065

4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
....
4096
4097
4098
4099
4100
4101
4102

4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
....
4434
4435
4436
4437
4438
4439
4440

4441
4442
4443
4444
4445
4446
4447
4448
	  break;
      };
    *val = value;
    return 1;
}

static int
parse_sld_se_color (const char *color, unsigned char *red, unsigned char *green,
		    unsigned char *blue)
{
/* attempting to parse a #RRGGBB hexadecimal color */
    unsigned char r;
    unsigned char g;
    unsigned char b;
    if (strlen (color) != 7)
	return 0;
................................................................................
					    (color, &red, &green, &blue))
					  {
					      if (style->categorize->last ==
						  NULL)
						{
						    style->categorize->baseRed =
							red;
						    style->
							categorize->baseGreen =
							green;
						    style->
							categorize->baseBlue =
							blue;
						}
					      else
						{
						    style->categorize->
................................................................................
					  {
					      if (text->type == XML_TEXT_NODE)
						{
						    const char *value =
							(const char
							 *) (text->content);
						    if (value != NULL)
							style->brightnessOnly =
							    atoi (value);
						}
					      text = text->next;
					  }
				    }
				  if (strcmp (xmode, "ReliefFactor") == 0)
				    {
					text = child->children;
................................................................................
			    if (child->type == XML_ELEMENT_NODE)
			      {
				  name = (const char *) (child->name);
				  if (strcmp (name, "RasterSymbolizer") == 0)
				    {
					rl2PrivStyleRulePtr rule =
					    rl2_create_default_style_rule ();
					rl2PrivRasterSymbolizerPtr symbolizer =

					    rl2_create_default_raster_symbolizer
					    ();
					if (symbolizer == NULL || rule == NULL)
					  {
					      if (symbolizer != NULL)
						  rl2_destroy_raster_symbolizer
						      (symbolizer);
................................................................................
		      if (child->type == XML_TEXT_NODE
			  && child->content != NULL)
			{
			    unsigned char red;
			    unsigned char green;
			    unsigned char blue;
			    if (parse_sld_se_color
				((const char *) (child->content), &red, &green,
				 &blue))
			      {
				  repl->red = red;
				  repl->green = green;
				  repl->blue = blue;
			      }
			    ok_value = 1;
			}
................................................................................
						   &blue))
						{
						    mark->stroke->red = red;
						    mark->stroke->green = green;
						    mark->stroke->blue = blue;
						}
					  }
					if (strcmp (svg_name, "stroke-width") ==
					    0)
					    mark->stroke->width =
						atof ((const char *) svg_value);

					if (strcmp (svg_name, "stroke-linejoin")
					    == 0)
					  {
					      if (strcmp (svg_value, "mitre") ==
						  0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round") ==
						  0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel") ==
						  0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }

					if (strcmp (svg_name, "stroke-linecap")
					    == 0)
					  {
					      if (strcmp (svg_value, "butt") ==
						  0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round") ==
						  0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->stroke->red = red;
						    sym->stroke->green = green;
						    sym->stroke->blue = blue;
						}
					  }

					if (strcmp (svg_name, "stroke-opacity")
					    == 0)
					    sym->stroke->opacity =
						atof ((const char *) svg_value);
					if (strcmp (svg_name, "stroke-width") ==
					    0)
					    sym->stroke->width =
						atof ((const char *) svg_value);

					if (strcmp (svg_name, "stroke-linejoin")
					    == 0)
					  {
					      if (strcmp (svg_value, "mitre") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }

					if (strcmp (svg_name, "stroke-linecap")
					    == 0)
					  {
					      if (strcmp (svg_value, "butt") ==
						  0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round") ==
						  0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->stroke->red = red;
						    sym->stroke->green = green;
						    sym->stroke->blue = blue;
						}
					  }

					if (strcmp (svg_name, "stroke-opacity")
					    == 0)
					    sym->stroke->opacity =
						atof ((const char *) svg_value);
					if (strcmp (svg_name, "stroke-width") ==
					    0)
					    sym->stroke->width =
						atof ((const char *) svg_value);

					if (strcmp (svg_name, "stroke-linejoin")
					    == 0)
					  {
					      if (strcmp (svg_value, "mitre") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel") ==
						  0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }

					if (strcmp (svg_name, "stroke-linecap")
					    == 0)
					  {
					      if (strcmp (svg_value, "butt") ==
						  0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round") ==
						  0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->fill->red = red;
						    sym->fill->green = green;
						    sym->fill->blue = blue;
						}
					  }
					if (strcmp (svg_name, "fill-opacity") ==
					    0)
					    sym->fill->opacity =
						atof (svg_value);
				    }
			      }
			    child = child->next;
			}
		  }
................................................................................
					const char *svg_value;
					if (!svg_parameter_name
					    (child, &svg_name, &svg_value))
					  {
					      child = child->next;
					      continue;
					  }
					if (strcmp (svg_name, "font-family") ==
					    0)
					  {
					      if (sym->font_families_count <
						  RL2_MAX_FONT_FAMILIES)
						{
						    int idx =
							sym->font_families_count++;
						    int len =
................................................................................
						  sym->font_style =
						      RL2_FONT_STYLE_ITALIC;
					      if (strcasecmp
						  (svg_value, "oblique") == 0)
						  sym->font_style =
						      RL2_FONT_STYLE_OBLIQUE;
					  }
					if (strcmp (svg_name, "font-weight") ==
					    0)
					  {
					      if (strcasecmp
						  (svg_value, "normal") == 0)
						  sym->font_weight =
						      RL2_FONT_WEIGHT_NORMAL;
					      if (strcasecmp (svg_value, "bold")
						  == 0)
						  sym->font_weight =
						      RL2_FONT_WEIGHT_BOLD;
					  }
					if (strcmp (svg_name, "font-size") == 0)
					    sym->font_size = atof (svg_value);
				    }
			      }
................................................................................
      {
	  if (node->type == XML_ELEMENT_NODE)
	    {
		const char *name = (const char *) (node->name);
		if (strcmp (name, "LabelPlacement") == 0)
		  {
		      xmlNodePtr child = node->children;
		      if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT

			  && sym->label_placement != NULL)
			  rl2_destroy_point_placement ((rl2PrivPointPlacementPtr) (sym->label_placement));
		      if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE

			  && sym->label_placement != NULL)
			  rl2_destroy_line_placement ((rl2PrivLinePlacementPtr)
						      (sym->label_placement));
		      sym->label_placement_type = RL2_LABEL_PLACEMENT_UNKNOWN;
		      sym->label_placement = NULL;
		      while (child)
			{
................................................................................
    rl2PrivTextSymbolizerPtr text;

    pR = style->first_rule;
    while (pR != NULL)
      {
	  /* counting max column names */
	  if (pR->column_name != NULL)
	    {
		count++;
		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
		  {
		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		      item = pV->first;
		      while (item != NULL)
			{
			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
				&& item->symbolizer != NULL)
			      {
				  text =
				      (rl2PrivTextSymbolizerPtr)
				      (item->symbolizer);
				  if (text->label != NULL)
				      count++;
			      }
			    item = item->next;
			}
		  }
	    }
	  pR = pR->next;
      }
    pR = style->else_rule;
    if (pR != NULL)
      {
	  if (pR->column_name != NULL)
	    {
		count++;
		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
		  {
		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		      item = pV->first;
		      while (item != NULL)
			{
			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
				&& item->symbolizer != NULL)
			      {
				  text =
				      (rl2PrivTextSymbolizerPtr)
				      (item->symbolizer);
				  if (text->label != NULL)
				      count++;
			      }
			    item = item->next;
			}
		  }
	    }
      }
    if (count == 0)
	return;

    strings = malloc (sizeof (char *) * count);
................................................................................
	  if (pR->column_name != NULL)
	    {
		len = strlen (pR->column_name);
		*(strings + i) = malloc (len + 1);
		strcpy (*(strings + i), pR->column_name);
		*(dupl + i) = 'N';
		i++;

		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
		  {
		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		      item = pV->first;
		      while (item != NULL)
			{
			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
				&& item->symbolizer != NULL)
			      {
				  text =
				      (rl2PrivTextSymbolizerPtr)
				      (item->symbolizer);
				  if (text->label != NULL)
				    {
					len = strlen (text->label);
					*(strings + i) = malloc (len + 1);
					strcpy (*(strings + i), text->label);
					*(dupl + i) = 'N';
					i++;
				    }
			      }
			    item = item->next;
			}
		  }
	    }
	  pR = pR->next;
      }
    pR = style->else_rule;
    if (pR != NULL)
      {
................................................................................
	  if (pR->column_name != NULL)
	    {
		len = strlen (pR->column_name);
		*(strings + i) = malloc (len + 1);
		strcpy (*(strings + i), pR->column_name);
		*(dupl + i) = 'N';
		i++;

		if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
		  {
		      pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		      item = pV->first;
		      while (item != NULL)
			{
			    if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
				&& item->symbolizer != NULL)
			      {
				  text =
				      (rl2PrivTextSymbolizerPtr)
				      (item->symbolizer);
				  if (text->label != NULL)
				    {
					len = strlen (text->label);
					*(strings + i) = malloc (len + 1);
					strcpy (*(strings + i), text->label);
					*(dupl + i) = 'N';
					i++;
				    }
			      }
			    item = item->next;
			}
		  }
	    }
      }

    for (i = 0; i < count; i++)
      {
	  /* identifying all duplicates */
................................................................................
	  lyr->raster_stats = NULL;
      }
    return ptr;
}

static int
rl2_group_renderer_set_raster (rl2PrivGroupRendererPtr group, int index,

			       const char *layer_name, rl2CoveragePtr coverage,
			       sqlite3_int64 style_id,
			       rl2RasterSymbolizerPtr symbolizer,
			       rl2RasterStatisticsPtr stats)
{
/* setting up one of the Layers within the Group */
    int len;
    rl2PrivGroupRendererLayerPtr lyr;







|
|







 







<
|
|







 







|
|







 







|
>







 







|
|







 







|
|


>
|
<

|
|


|
|


|
|



>
|
<

|
|


|
|







 







>
|
<


|
|


>
|
<

|
|


|
|


|
|



>
|
<

|
|


|
|







 







>
|
<


|
|


>
|
<

|
|


|
|


|
|



>
|
<

|
|


|
|







 







|
|







 







|
|







 







|
|





|
|







 







|
>


|
>







 







<
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
<








<
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
<







 







>
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
<







 







>
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
<







 







>
|







540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
...
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
....
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
....
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
....
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574

1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
....
1825
1826
1827
1828
1829
1830
1831
1832
1833

1834
1835
1836
1837
1838
1839
1840
1841

1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857

1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
....
2024
2025
2026
2027
2028
2029
2030
2031
2032

2033
2034
2035
2036
2037
2038
2039
2040

2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056

2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
....
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
....
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
....
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
....
3995
3996
3997
3998
3999
4000
4001

4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013

4014
4015
4016
4017

4018
4019
4020
4021
4022
4023
4024
4025

4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037

4038
4039
4040
4041

4042
4043
4044
4045
4046
4047
4048
....
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073

4074
4075
4076
4077
4078
4079
4080
4081
4082
4083

4084
4085
4086
4087
4088
4089
4090
....
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109

4110
4111
4112
4113
4114
4115
4116
4117
4118
4119

4120
4121
4122
4123
4124
4125
4126
....
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
	  break;
      };
    *val = value;
    return 1;
}

static int
parse_sld_se_color (const char *color, unsigned char *red,
		    unsigned char *green, unsigned char *blue)
{
/* attempting to parse a #RRGGBB hexadecimal color */
    unsigned char r;
    unsigned char g;
    unsigned char b;
    if (strlen (color) != 7)
	return 0;
................................................................................
					    (color, &red, &green, &blue))
					  {
					      if (style->categorize->last ==
						  NULL)
						{
						    style->categorize->baseRed =
							red;

						    style->categorize->baseGreen
							= green;
						    style->
							categorize->baseBlue =
							blue;
						}
					      else
						{
						    style->categorize->
................................................................................
					  {
					      if (text->type == XML_TEXT_NODE)
						{
						    const char *value =
							(const char
							 *) (text->content);
						    if (value != NULL)
							style->brightnessOnly
							    = atoi (value);
						}
					      text = text->next;
					  }
				    }
				  if (strcmp (xmode, "ReliefFactor") == 0)
				    {
					text = child->children;
................................................................................
			    if (child->type == XML_ELEMENT_NODE)
			      {
				  name = (const char *) (child->name);
				  if (strcmp (name, "RasterSymbolizer") == 0)
				    {
					rl2PrivStyleRulePtr rule =
					    rl2_create_default_style_rule ();
					rl2PrivRasterSymbolizerPtr symbolizer
					    =
					    rl2_create_default_raster_symbolizer
					    ();
					if (symbolizer == NULL || rule == NULL)
					  {
					      if (symbolizer != NULL)
						  rl2_destroy_raster_symbolizer
						      (symbolizer);
................................................................................
		      if (child->type == XML_TEXT_NODE
			  && child->content != NULL)
			{
			    unsigned char red;
			    unsigned char green;
			    unsigned char blue;
			    if (parse_sld_se_color
				((const char *) (child->content), &red,
				 &green, &blue))
			      {
				  repl->red = red;
				  repl->green = green;
				  repl->blue = blue;
			      }
			    ok_value = 1;
			}
................................................................................
						   &blue))
						{
						    mark->stroke->red = red;
						    mark->stroke->green = green;
						    mark->stroke->blue = blue;
						}
					  }
					if (strcmp (svg_name, "stroke-width")
					    == 0)
					    mark->stroke->width =
						atof ((const char *) svg_value);
					if (strcmp
					    (svg_name, "stroke-linejoin") == 0)

					  {
					      if (strcmp (svg_value, "mitre")
						  == 0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round")
						  == 0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel")
						  == 0)
						  mark->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }
					if (strcmp
					    (svg_name, "stroke-linecap") == 0)

					  {
					      if (strcmp (svg_value, "butt")
						  == 0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round")
						  == 0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  mark->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->stroke->red = red;
						    sym->stroke->green = green;
						    sym->stroke->blue = blue;
						}
					  }
					if (strcmp
					    (svg_name, "stroke-opacity") == 0)

					    sym->stroke->opacity =
						atof ((const char *) svg_value);
					if (strcmp (svg_name, "stroke-width")
					    == 0)
					    sym->stroke->width =
						atof ((const char *) svg_value);
					if (strcmp
					    (svg_name, "stroke-linejoin") == 0)

					  {
					      if (strcmp (svg_value, "mitre")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }
					if (strcmp
					    (svg_name, "stroke-linecap") == 0)

					  {
					      if (strcmp (svg_value, "butt")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->stroke->red = red;
						    sym->stroke->green = green;
						    sym->stroke->blue = blue;
						}
					  }
					if (strcmp
					    (svg_name, "stroke-opacity") == 0)

					    sym->stroke->opacity =
						atof ((const char *) svg_value);
					if (strcmp (svg_name, "stroke-width")
					    == 0)
					    sym->stroke->width =
						atof ((const char *) svg_value);
					if (strcmp
					    (svg_name, "stroke-linejoin") == 0)

					  {
					      if (strcmp (svg_value, "mitre")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_MITRE;
					      if (strcmp (svg_value, "round")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_ROUND;
					      if (strcmp (svg_value, "bevel")
						  == 0)
						  sym->stroke->linejoin =
						      RL2_STROKE_LINEJOIN_BEVEL;
					  }
					if (strcmp
					    (svg_name, "stroke-linecap") == 0)

					  {
					      if (strcmp (svg_value, "butt")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_BUTT;
					      if (strcmp (svg_value, "round")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_ROUND;
					      if (strcmp (svg_value, "square")
						  == 0)
						  sym->stroke->linecap =
						      RL2_STROKE_LINECAP_SQUARE;
					  }
................................................................................
						   &blue))
						{
						    sym->fill->red = red;
						    sym->fill->green = green;
						    sym->fill->blue = blue;
						}
					  }
					if (strcmp (svg_name, "fill-opacity")
					    == 0)
					    sym->fill->opacity =
						atof (svg_value);
				    }
			      }
			    child = child->next;
			}
		  }
................................................................................
					const char *svg_value;
					if (!svg_parameter_name
					    (child, &svg_name, &svg_value))
					  {
					      child = child->next;
					      continue;
					  }
					if (strcmp (svg_name, "font-family")
					    == 0)
					  {
					      if (sym->font_families_count <
						  RL2_MAX_FONT_FAMILIES)
						{
						    int idx =
							sym->font_families_count++;
						    int len =
................................................................................
						  sym->font_style =
						      RL2_FONT_STYLE_ITALIC;
					      if (strcasecmp
						  (svg_value, "oblique") == 0)
						  sym->font_style =
						      RL2_FONT_STYLE_OBLIQUE;
					  }
					if (strcmp (svg_name, "font-weight")
					    == 0)
					  {
					      if (strcasecmp
						  (svg_value, "normal") == 0)
						  sym->font_weight =
						      RL2_FONT_WEIGHT_NORMAL;
					      if (strcasecmp
						  (svg_value, "bold") == 0)
						  sym->font_weight =
						      RL2_FONT_WEIGHT_BOLD;
					  }
					if (strcmp (svg_name, "font-size") == 0)
					    sym->font_size = atof (svg_value);
				    }
			      }
................................................................................
      {
	  if (node->type == XML_ELEMENT_NODE)
	    {
		const char *name = (const char *) (node->name);
		if (strcmp (name, "LabelPlacement") == 0)
		  {
		      xmlNodePtr child = node->children;
		      if (sym->label_placement_type ==
			  RL2_LABEL_PLACEMENT_POINT
			  && sym->label_placement != NULL)
			  rl2_destroy_point_placement ((rl2PrivPointPlacementPtr) (sym->label_placement));
		      if (sym->label_placement_type ==
			  RL2_LABEL_PLACEMENT_LINE
			  && sym->label_placement != NULL)
			  rl2_destroy_line_placement ((rl2PrivLinePlacementPtr)
						      (sym->label_placement));
		      sym->label_placement_type = RL2_LABEL_PLACEMENT_UNKNOWN;
		      sym->label_placement = NULL;
		      while (child)
			{
................................................................................
    rl2PrivTextSymbolizerPtr text;

    pR = style->first_rule;
    while (pR != NULL)
      {
	  /* counting max column names */
	  if (pR->column_name != NULL)

	      count++;
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	    {
		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		item = pV->first;
		while (item != NULL)
		  {
		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
			  && item->symbolizer != NULL)
			{
			    text =
				(rl2PrivTextSymbolizerPtr) (item->symbolizer);

			    if (text->label != NULL)
				count++;
			}
		      item = item->next;

		  }
	    }
	  pR = pR->next;
      }
    pR = style->else_rule;
    if (pR != NULL)
      {
	  if (pR->column_name != NULL)

	      count++;
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	    {
		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		item = pV->first;
		while (item != NULL)
		  {
		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
			  && item->symbolizer != NULL)
			{
			    text =
				(rl2PrivTextSymbolizerPtr) (item->symbolizer);

			    if (text->label != NULL)
				count++;
			}
		      item = item->next;

		  }
	    }
      }
    if (count == 0)
	return;

    strings = malloc (sizeof (char *) * count);
................................................................................
	  if (pR->column_name != NULL)
	    {
		len = strlen (pR->column_name);
		*(strings + i) = malloc (len + 1);
		strcpy (*(strings + i), pR->column_name);
		*(dupl + i) = 'N';
		i++;
	    }
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	    {
		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		item = pV->first;
		while (item != NULL)
		  {
		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
			  && item->symbolizer != NULL)
			{
			    text =
				(rl2PrivTextSymbolizerPtr) (item->symbolizer);

			    if (text->label != NULL)
			      {
				  len = strlen (text->label);
				  *(strings + i) = malloc (len + 1);
				  strcpy (*(strings + i), text->label);
				  *(dupl + i) = 'N';
				  i++;
			      }
			}
		      item = item->next;

		  }
	    }
	  pR = pR->next;
      }
    pR = style->else_rule;
    if (pR != NULL)
      {
................................................................................
	  if (pR->column_name != NULL)
	    {
		len = strlen (pR->column_name);
		*(strings + i) = malloc (len + 1);
		strcpy (*(strings + i), pR->column_name);
		*(dupl + i) = 'N';
		i++;
	    }
	  if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL)
	    {
		pV = (rl2PrivVectorSymbolizerPtr) (pR->style);
		item = pV->first;
		while (item != NULL)
		  {
		      if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER
			  && item->symbolizer != NULL)
			{
			    text =
				(rl2PrivTextSymbolizerPtr) (item->symbolizer);

			    if (text->label != NULL)
			      {
				  len = strlen (text->label);
				  *(strings + i) = malloc (len + 1);
				  strcpy (*(strings + i), text->label);
				  *(dupl + i) = 'N';
				  i++;
			      }
			}
		      item = item->next;

		  }
	    }
      }

    for (i = 0; i < count; i++)
      {
	  /* identifying all duplicates */
................................................................................
	  lyr->raster_stats = NULL;
      }
    return ptr;
}

static int
rl2_group_renderer_set_raster (rl2PrivGroupRendererPtr group, int index,
			       const char *layer_name,
			       rl2CoveragePtr coverage,
			       sqlite3_int64 style_id,
			       rl2RasterSymbolizerPtr symbolizer,
			       rl2RasterStatisticsPtr stats)
{
/* setting up one of the Layers within the Group */
    int len;
    rl2PrivGroupRendererLayerPtr lyr;

Changes to src/rl2tiff.c.

547
548
549
550
551
552
553

554
555
556
557
558
559
560
...
640
641
642
643
644
645
646













647
648
649
650
651
652
653
....
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429
....
2169
2170
2171
2172
2173
2174
2175


2176


2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
....
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
....
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
....
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
....
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
....
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
....
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
....
3673
3674
3675
3676
3677
3678
3679
3680

3681
3682
3683
3684
3685
3686
3687
3688
....
4172
4173
4174
4175
4176
4177
4178
4179

4180
4181
4182
4183
4184
4185
4186
....
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
....
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
....
5078
5079
5080
5081
5082
5083
5084
5085

5086
5087
5088
5089
5090
5091
5092
5093
5094
....
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
....
6163
6164
6165
6166
6167
6168
6169
6170

6171
6172
6173
6174
6175
6176
6177
6178
....
6539
6540
6541
6542
6543
6544
6545

6546
6547
6548
6549
6550
6551
6552
6553
....
6658
6659
6660
6661
6662
6663
6664

6665
6666
6667
6668
6669
6670
6671
6672
....
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
....
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
....
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
....
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
....
8082
8083
8084
8085
8086
8087
8088

8089
8090
8091
8092
8093
8094
8095
8096
8097
    uint32 height = 0;
    double cx;
    double cy;
    GTIFDefn definition;
    char *pString;
    int len;
    int basic = 0;

    TIFF *in = (TIFF *) 0;
    GTIF *gtif = (GTIF *) 0;

/* suppressing TIFF messages */
    TIFFSetErrorHandler (NULL);
    TIFFSetWarningHandler (NULL);

................................................................................
    origin->maxX = cx;

/* computing the pixel resolution */
    origin->hResolution = (origin->maxX - origin->minX) / (double) width;
    origin->vResolution = (origin->maxY - origin->minY) / (double) height;
    origin->isGeoReferenced = 1;
    origin->isGeoTiff = 1;














  error:
    if (basic && origin->isGeoTiff == 0)
	recover_incomplete_geotiff (origin, in, width, height, force_srid);
    if (in != (TIFF *) 0)
	XTIFFClose (in);
    if (gtif != (GTIF *) 0)
................................................................................
      {
	  /* attempting to recover badly formatted TIFFs */
	  origin->planarConfig = PLANARCONFIG_CONTIG;
      }
    else
	origin->planarConfig = value16;


    if (origin->bitsPerSample == 16 && origin->sampleFormat == SAMPLEFORMAT_UINT
	&& origin->planarConfig == PLANARCONFIG_SEPARATE)
	;
    else if (origin->bitsPerSample == 8
	     && origin->sampleFormat == SAMPLEFORMAT_UINT
	     && origin->planarConfig == PLANARCONFIG_SEPARATE)
	;
    else if (origin->planarConfig != PLANARCONFIG_CONTIG)
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */


	  if (hResolution != coverage->hResolution)


	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		return RL2_FALSE;
	    }
	  if (vResolution != coverage->vResolution)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		return RL2_FALSE;
	    }
      }
................................................................................
		if (tiff_max_x < startCol)
		    skip = 1;
		if (skip)
		  {
		      /* skipping any not required tile */
		      continue;
		  }
		if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0) <
		    0)
		    goto error;
		if (convert != RL2_CONVERT_NO)
		  {
		      /* applying some format conversion */
		      copy_convert_tile (origin, tiff_tile, pixels, startRow,
					 startCol, width, height, tile_y,
					 tile_x, convert);
................................................................................
			      {
			      case RL2_SAMPLE_INT8:
				  p_in_8 = (char *) tiff_tile;
				  p_in_8 += y * origin->tileWidth;
				  p_in_8 += x;
				  p_out_8 = (char *) pixels;
				  p_out_8 +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      case RL2_SAMPLE_UINT8:
				  p_in_u8 = (unsigned char *) tiff_tile;
				  p_in_u8 += y * origin->tileWidth * num_bands;
				  p_in_u8 += x * num_bands;
				  p_out_u8 = (unsigned char *) pixels;
				  p_out_u8 +=
................................................................................
				  break;
			      case RL2_SAMPLE_INT16:
				  p_in_16 = (short *) tiff_tile;
				  p_in_16 += y * origin->tileWidth;
				  p_in_16 += x;
				  p_out_16 = (short *) pixels;
				  p_out_16 +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      case RL2_SAMPLE_UINT16:
				  p_in_u16 = (unsigned short *) tiff_tile;
				  p_in_u16 += y * origin->tileWidth * num_bands;
				  p_in_u16 += x * num_bands;
				  p_out_u16 = (unsigned short *) pixels;
				  p_out_u16 +=
................................................................................
				  break;
			      case RL2_SAMPLE_INT32:
				  p_in_32 = (int *) tiff_tile;
				  p_in_32 += y * origin->tileWidth;
				  p_in_32 += x;
				  p_out_32 = (int *) pixels;
				  p_out_32 +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      case RL2_SAMPLE_UINT32:
				  p_in_u32 = (unsigned int *) tiff_tile;
				  p_in_u32 += y * origin->tileWidth;
				  p_in_u32 += x;
				  p_out_u32 = (unsigned int *) pixels;
				  p_out_u32 +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      case RL2_SAMPLE_FLOAT:
				  p_in_flt = (float *) tiff_tile;
				  p_in_flt += y * origin->tileWidth;
				  p_in_flt += x;
				  p_out_flt = (float *) pixels;
				  p_out_flt +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      case RL2_SAMPLE_DOUBLE:
				  p_in_dbl = (double *) tiff_tile;
				  p_in_dbl += y * origin->tileWidth;
				  p_in_dbl += x;
				  p_out_dbl = (double *) pixels;
				  p_out_dbl +=
				      ((dest_y - startRow) * width) + (dest_x -
								       startCol);
				  break;
			      };
			    for (bnd = 0; bnd < num_bands; bnd++)
			      {
				  switch (sample_type)
				    {
				    case RL2_SAMPLE_INT8:
................................................................................
      }

    for (y = 0; y < height; y++)
      {
	  /* scanning scanlines by row */
	  line_no = y + startRow;
	  if (line_no >= origin->height)
	    {
		switch (sample_type)
		  {
		  case RL2_SAMPLE_INT8:
		      p_out_8 = (char *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_8++ = 0;
		      break;
		  case RL2_SAMPLE_UINT8:
		      p_out_u8 = (unsigned char *) pixels;
		      for (x = 0; x < width * num_bands; x++)
			  *p_out_u8++ = 0;
		      break;
		  case RL2_SAMPLE_INT16:
		      p_out_16 = (short *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_16++ = 0;
		      break;
		  case RL2_SAMPLE_UINT16:
		      p_out_u16 = (unsigned short *) pixels;
		      for (x = 0; x < width * num_bands; x++)
			  *p_out_u16++ = 0;
		      break;
		  case RL2_SAMPLE_INT32:
		      p_out_32 = (int *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_32++ = 0;
		      break;
		  case RL2_SAMPLE_UINT32:
		      p_out_u32 = (unsigned int *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_u32++ = 0;
		      break;
		  case RL2_SAMPLE_FLOAT:
		      p_out_flt = (float *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_flt++ = 0;
		      break;
		  case RL2_SAMPLE_DOUBLE:
		      p_out_dbl = (double *) pixels;
		      for (x = 0; x < width; x++)
			  *p_out_dbl++ = 0;
		      break;
		  default:
		      goto error;
		  };
		continue;
	    }
	  if (TIFFReadScanline (in, tiff_scanline, line_no, 0) < 0)
	      goto error;
	  if (convert != RL2_CONVERT_NO)
	    {
		/* applying some format conversion */
		copy_convert_scanline (origin, tiff_scanline, pixels, y,
				       startCol, width, convert);
................................................................................
					p_in_u16 = (unsigned short *) tiff_tile;
					p_in_u16 += y * origin->tileWidth;
					p_in_u16 += x;
					p_out_u16 = (unsigned short *) pixels;
					p_out_u16 +=
					    ((dest_y -
					      startRow) * width * num_bands) +
					    ((dest_x - startCol) * num_bands) +
					    band;
					*p_out_u16 = *p_in_u16;
				    }
				  if (sample_type == RL2_SAMPLE_UINT8)
				    {
					p_in_u8 = (unsigned char *) tiff_tile;
					p_in_u8 += y * origin->tileWidth;
					p_in_u8 += x;
					p_out_u8 = (unsigned char *) pixels;
					p_out_u8 +=
					    ((dest_y -
					      startRow) * width * num_bands) +
					    ((dest_x - startCol) * num_bands) +
					    band;
					*p_out_u8 = *p_in_u8;
				    }
			      }
			}
		  }
	    }
      }
................................................................................
  error:
    if (tiff_tile != NULL)
	free (tiff_tile);
    return RL2_ERROR;
}

static int
read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin, unsigned short width,

			     unsigned short height, unsigned char sample_type,
			     unsigned char num_bands, unsigned int startRow,
			     unsigned int startCol, void *pixels)
{
/* reading TIFF raw strips - separate planes */
    uint32 line_no;
    uint32 x;
    uint32 y;
................................................................................
	      goto error;
      }
    else
      {
	  /* contiguous planar configuration */
	  if (origin->bitsPerSample <= 8
	      && origin->sampleFormat == SAMPLEFORMAT_UINT
	      && (origin->samplesPerPixel == 1 || origin->samplesPerPixel == 3)

	      && (pixel_type == RL2_PIXEL_MONOCHROME
		  || pixel_type == RL2_PIXEL_PALETTE
		  || pixel_type == RL2_PIXEL_GRAYSCALE
		  || pixel_type == RL2_PIXEL_RGB))
	    {
		/* using the TIFF RGBA methods */
		if (origin->isTiled)
................................................................................
		if (origin->isTiled)
		    ret =
			read_raw_tiles (origin, width, height, sample_type,
					num_bands, startRow, startCol,
					bufPixels);
		else
		    ret =
			read_raw_scanlines (origin, width, height, sample_type,
					    num_bands, startRow, startCol,
					    bufPixels);
		if (ret != RL2_OK)
		    goto error;
	    }
      }

    *pixels = bufPixels;
    *pixels_sz = bufPixelsSz;
................................................................................
		  }
	    }
      }

/* attempting to create the tile */
    if (read_from_tiff
	(origin, coverage->tileWidth, coverage->tileHeight,
	 coverage->sampleType, coverage->pixelType, coverage->nBands, startRow,
	 startCol, &pixels, &pixels_sz, palette) != RL2_OK)
	goto error;
    if (startCol + coverage->tileWidth > origin->width)
	unused_width = (startCol + coverage->tileWidth) - origin->width;
    if (startRow + coverage->tileHeight > origin->height)
	unused_height = (startRow + coverage->tileHeight) - origin->height;
    if (unused_width || unused_height)
      {
................................................................................
  error:
    return 0;
}

RL2_DECLARE rl2TiffDestinationPtr
rl2_create_tiff_destination (const char *path, unsigned int width,
			     unsigned int height, unsigned char sample_type,
			     unsigned char pixel_type, unsigned char num_bands,

			     rl2PalettePtr plt, unsigned char tiff_compression,
			     int tiled, unsigned int tile_size)
{
/* attempting to create a file-based TIFF destination (no georeferencing) */
    rl2PrivTiffDestinationPtr destination = NULL;
    if (!check_color_model
	(sample_type, pixel_type, num_bands, plt, tiff_compression))
      {
	  fprintf (stderr, "RL2-TIFF writer: unsupported pixel format\n");
................................................................................
      }
    if (TIFFWriteScanline (tiff->out, tiff->tiffBuffer, row, 0) < 0)
	return 0;
    return 1;
}

static int
tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster,
		       unsigned int row)
{
/* writing a TIFF Grayscale scanline */
    unsigned int x;
    unsigned char *p_in = raster->rasterBuffer;
    unsigned char *p_out = tiff->tiffBuffer;

    for (x = 0; x < raster->width; x++)
................................................................................
	      0)
	      return 0;
      }
    return 1;
}

static int
tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster,

			unsigned int row, unsigned int col)
{
/* writing a TIFF RGB tile - UINT8 */
    unsigned int y;
    unsigned int x;
    unsigned char *p_in = raster->rasterBuffer;
    unsigned char *p_out = tiff->tiffBuffer;

................................................................................
	     && rst->nBands == destination->samplesPerPixel
	     && destination->tileWidth == rst->width
	     && destination->tileHeight == rst->height)
	ret =
	    tiff_write_tile_multiband16 (destination, rst, startRow, startCol);
    else if (destination->sampleFormat == SAMPLEFORMAT_UINT
	     && destination->samplesPerPixel == 1

	     && destination->photometric < 2 && destination->bitsPerSample == 8
	     && rst->sampleType == RL2_SAMPLE_UINT8
	     && rst->pixelType == RL2_PIXEL_GRAYSCALE && rst->nBands == 1
	     && destination->tileWidth == rst->width
	     && destination->tileHeight == rst->height)
	ret = tiff_write_tile_gray (destination, rst, startRow, startCol);
    else if (destination->sampleFormat == SAMPLEFORMAT_UINT
	     && destination->samplesPerPixel == 1
................................................................................
	return RL2_ERROR;
    if (destination->tfw_path == NULL)
	return RL2_ERROR;

    tfw = fopen (destination->tfw_path, "w");
    if (tfw == NULL)
      {

	  fprintf (stderr, "RL2-TIFF writer: unable to open Worldfile \"%s\"\n",
		   destination->tfw_path);
	  return RL2_ERROR;
      }
    fprintf (tfw, "        %1.16f\n", destination->hResolution);
    fprintf (tfw, "        0.0\n");
    fprintf (tfw, "        0.0\n");
    fprintf (tfw, "        -%1.16f\n", destination->vResolution);
................................................................................
    TIFFClose (in);
    if (tiff_buffer != NULL)
	free (tiff_buffer);
    return RL2_ERROR;
}

static int
rgb_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width,
		 unsigned short height)
{
/* common implementation of RGB TIFF export */
    tsize_t buf_size;
    void *tiff_buffer = NULL;
    int y;
    int x;
    const unsigned char *p_in;
................................................................................
    return 0;
}

static int
output_palette_tiff (const unsigned char *buffer,
		     unsigned short width,
		     unsigned short height, unsigned char *red,
		     unsigned char *green, unsigned char *blue, int max_palette,
		     unsigned char **blob, int *blob_size)
{
/* generating a PALETTE TIFF - actual work */
    struct memfile clientdata;
    TIFF *out = (TIFF *) 0;

/* suppressing TIFF warnings */
    TIFFSetWarningHandler (NULL);
................................................................................
	       tiff_size))
	      return RL2_ERROR;
      }
    return RL2_OK;
}

static int
gray_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width,
		  unsigned short height)
{
/* common implementation of Grayscale TIFF export */
    tsize_t buf_size;
    void *tiff_buffer = NULL;
    int y;
    int x;
    const unsigned char *p_in;
................................................................................
	xml =
	    sqlite3_mprintf ("%s<Compression>%u</Compression>", prev,
			     org->compression);
    sqlite3_free (prev);
    prev = xml;
    if (org->sampleFormat == SAMPLEFORMAT_UINT)
	xml =
	    sqlite3_mprintf ("%s<SampleFormat>unsigned integer</SampleFormat>",
			     prev);
    else if (org->sampleFormat == SAMPLEFORMAT_INT)
	xml =
	    sqlite3_mprintf ("%s<SampleFormat>signed integer</SampleFormat>",
			     prev);
    else if (org->sampleFormat == SAMPLEFORMAT_IEEEFP)
	xml =
	    sqlite3_mprintf ("%s<SampleFormat>floating point</SampleFormat>",
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =

	      sqlite3_mprintf ("%s<HorizontalExtent>%1.10f</HorizontalExtent>",
			       prev, org->maxX - org->minX);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, org->maxY - org->minY);
	  sqlite3_free (prev);
	  prev = xml;







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
|







 







>
>
|
>
>






|







 







|
|







 







|
|







 







|
|







 







|
|







|
|







|
|







|
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<







 







|
|











|
|







 







|
>
|







 







|
>







 







|
|
|







 







|
|







 







|
>
|
|







 







|
|







 







|
>
|







 







>
|







 







>
|







 







|
|







 







|
|







 







|
|







 







|
|







 







>
|
|







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
...
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
....
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
....
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
....
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
....
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
....
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
....
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
....
3391
3392
3393
3394
3395
3396
3397














































3398

3399
3400
3401
3402
3403
3404
3405
....
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
....
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
....
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
....
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
....
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
....
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
....
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
....
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
....
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
....
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
....
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
....
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
....
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
....
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
....
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
    uint32 height = 0;
    double cx;
    double cy;
    GTIFDefn definition;
    char *pString;
    int len;
    int basic = 0;
    short pixel_mode = RasterPixelIsArea;
    TIFF *in = (TIFF *) 0;
    GTIF *gtif = (GTIF *) 0;

/* suppressing TIFF messages */
    TIFFSetErrorHandler (NULL);
    TIFFSetWarningHandler (NULL);

................................................................................
    origin->maxX = cx;

/* computing the pixel resolution */
    origin->hResolution = (origin->maxX - origin->minX) / (double) width;
    origin->vResolution = (origin->maxY - origin->minY) / (double) height;
    origin->isGeoReferenced = 1;
    origin->isGeoTiff = 1;

/* retrieving GTRasterTypeGeoKey */
    if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1))
	pixel_mode = RasterPixelIsArea;
    if (pixel_mode == RasterPixelIsPoint)
      {
	  /* adjusting the BBOX */
	  origin->minX -= origin->hResolution / 2.0;
	  origin->minY -= origin->vResolution / 2.0;
	  origin->maxX += origin->hResolution / 2.0;
	  origin->maxY += origin->vResolution / 2.0;

      }

  error:
    if (basic && origin->isGeoTiff == 0)
	recover_incomplete_geotiff (origin, in, width, height, force_srid);
    if (in != (TIFF *) 0)
	XTIFFClose (in);
    if (gtif != (GTIF *) 0)
................................................................................
      {
	  /* attempting to recover badly formatted TIFFs */
	  origin->planarConfig = PLANARCONFIG_CONTIG;
      }
    else
	origin->planarConfig = value16;

    if (origin->bitsPerSample == 16
	&& origin->sampleFormat == SAMPLEFORMAT_UINT
	&& origin->planarConfig == PLANARCONFIG_SEPARATE)
	;
    else if (origin->bitsPerSample == 8
	     && origin->sampleFormat == SAMPLEFORMAT_UINT
	     && origin->planarConfig == PLANARCONFIG_SEPARATE)
	;
    else if (origin->planarConfig != PLANARCONFIG_CONTIG)
................................................................................
    if (coverage->mixedResolutions)
      {
	  /* accepting any resolution */
      }
    else if (coverage->strictResolution)
      {
	  /* enforcing Strict Resolution check */
	  double x_diff = fabs (coverage->hResolution - hResolution);
	  double y_diff = fabs (coverage->vResolution - vResolution);
	  double x_lim = coverage->hResolution / 1000000.0;
	  double y_lim = coverage->vResolution / 1000000.0;
	  if (x_diff > x_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Horizontal Resolution (Strict) !!!\n");
		return RL2_FALSE;
	    }
	  if (y_diff > y_lim)
	    {
		if (verbose)
		    fprintf (stderr,
			     "Mismatching Vertical Resolution (Strict) !!!\n");
		return RL2_FALSE;
	    }
      }
................................................................................
		if (tiff_max_x < startCol)
		    skip = 1;
		if (skip)
		  {
		      /* skipping any not required tile */
		      continue;
		  }
		if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0)
		    < 0)
		    goto error;
		if (convert != RL2_CONVERT_NO)
		  {
		      /* applying some format conversion */
		      copy_convert_tile (origin, tiff_tile, pixels, startRow,
					 startCol, width, height, tile_y,
					 tile_x, convert);
................................................................................
			      {
			      case RL2_SAMPLE_INT8:
				  p_in_8 = (char *) tiff_tile;
				  p_in_8 += y * origin->tileWidth;
				  p_in_8 += x;
				  p_out_8 = (char *) pixels;
				  p_out_8 +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      case RL2_SAMPLE_UINT8:
				  p_in_u8 = (unsigned char *) tiff_tile;
				  p_in_u8 += y * origin->tileWidth * num_bands;
				  p_in_u8 += x * num_bands;
				  p_out_u8 = (unsigned char *) pixels;
				  p_out_u8 +=
................................................................................
				  break;
			      case RL2_SAMPLE_INT16:
				  p_in_16 = (short *) tiff_tile;
				  p_in_16 += y * origin->tileWidth;
				  p_in_16 += x;
				  p_out_16 = (short *) pixels;
				  p_out_16 +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      case RL2_SAMPLE_UINT16:
				  p_in_u16 = (unsigned short *) tiff_tile;
				  p_in_u16 += y * origin->tileWidth * num_bands;
				  p_in_u16 += x * num_bands;
				  p_out_u16 = (unsigned short *) pixels;
				  p_out_u16 +=
................................................................................
				  break;
			      case RL2_SAMPLE_INT32:
				  p_in_32 = (int *) tiff_tile;
				  p_in_32 += y * origin->tileWidth;
				  p_in_32 += x;
				  p_out_32 = (int *) pixels;
				  p_out_32 +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      case RL2_SAMPLE_UINT32:
				  p_in_u32 = (unsigned int *) tiff_tile;
				  p_in_u32 += y * origin->tileWidth;
				  p_in_u32 += x;
				  p_out_u32 = (unsigned int *) pixels;
				  p_out_u32 +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      case RL2_SAMPLE_FLOAT:
				  p_in_flt = (float *) tiff_tile;
				  p_in_flt += y * origin->tileWidth;
				  p_in_flt += x;
				  p_out_flt = (float *) pixels;
				  p_out_flt +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      case RL2_SAMPLE_DOUBLE:
				  p_in_dbl = (double *) tiff_tile;
				  p_in_dbl += y * origin->tileWidth;
				  p_in_dbl += x;
				  p_out_dbl = (double *) pixels;
				  p_out_dbl +=
				      ((dest_y - startRow) * width) +
				      (dest_x - startCol);
				  break;
			      };
			    for (bnd = 0; bnd < num_bands; bnd++)
			      {
				  switch (sample_type)
				    {
				    case RL2_SAMPLE_INT8:
................................................................................
      }

    for (y = 0; y < height; y++)
      {
	  /* scanning scanlines by row */
	  line_no = y + startRow;
	  if (line_no >= origin->height)














































	      continue;

	  if (TIFFReadScanline (in, tiff_scanline, line_no, 0) < 0)
	      goto error;
	  if (convert != RL2_CONVERT_NO)
	    {
		/* applying some format conversion */
		copy_convert_scanline (origin, tiff_scanline, pixels, y,
				       startCol, width, convert);
................................................................................
					p_in_u16 = (unsigned short *) tiff_tile;
					p_in_u16 += y * origin->tileWidth;
					p_in_u16 += x;
					p_out_u16 = (unsigned short *) pixels;
					p_out_u16 +=
					    ((dest_y -
					      startRow) * width * num_bands) +
					    ((dest_x -
					      startCol) * num_bands) + band;
					*p_out_u16 = *p_in_u16;
				    }
				  if (sample_type == RL2_SAMPLE_UINT8)
				    {
					p_in_u8 = (unsigned char *) tiff_tile;
					p_in_u8 += y * origin->tileWidth;
					p_in_u8 += x;
					p_out_u8 = (unsigned char *) pixels;
					p_out_u8 +=
					    ((dest_y -
					      startRow) * width * num_bands) +
					    ((dest_x -
					      startCol) * num_bands) + band;
					*p_out_u8 = *p_in_u8;
				    }
			      }
			}
		  }
	    }
      }
................................................................................
  error:
    if (tiff_tile != NULL)
	free (tiff_tile);
    return RL2_ERROR;
}

static int
read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin,
			     unsigned short width, unsigned short height,
			     unsigned char sample_type,
			     unsigned char num_bands, unsigned int startRow,
			     unsigned int startCol, void *pixels)
{
/* reading TIFF raw strips - separate planes */
    uint32 line_no;
    uint32 x;
    uint32 y;
................................................................................
	      goto error;
      }
    else
      {
	  /* contiguous planar configuration */
	  if (origin->bitsPerSample <= 8
	      && origin->sampleFormat == SAMPLEFORMAT_UINT
	      && (origin->samplesPerPixel == 1
		  || origin->samplesPerPixel == 3)
	      && (pixel_type == RL2_PIXEL_MONOCHROME
		  || pixel_type == RL2_PIXEL_PALETTE
		  || pixel_type == RL2_PIXEL_GRAYSCALE
		  || pixel_type == RL2_PIXEL_RGB))
	    {
		/* using the TIFF RGBA methods */
		if (origin->isTiled)
................................................................................
		if (origin->isTiled)
		    ret =
			read_raw_tiles (origin, width, height, sample_type,
					num_bands, startRow, startCol,
					bufPixels);
		else
		    ret =
			read_raw_scanlines (origin, width, height,
					    sample_type, num_bands, startRow,
					    startCol, bufPixels);
		if (ret != RL2_OK)
		    goto error;
	    }
      }

    *pixels = bufPixels;
    *pixels_sz = bufPixelsSz;
................................................................................
		  }
	    }
      }

/* attempting to create the tile */
    if (read_from_tiff
	(origin, coverage->tileWidth, coverage->tileHeight,
	 coverage->sampleType, coverage->pixelType, coverage->nBands,
	 startRow, startCol, &pixels, &pixels_sz, palette) != RL2_OK)
	goto error;
    if (startCol + coverage->tileWidth > origin->width)
	unused_width = (startCol + coverage->tileWidth) - origin->width;
    if (startRow + coverage->tileHeight > origin->height)
	unused_height = (startRow + coverage->tileHeight) - origin->height;
    if (unused_width || unused_height)
      {
................................................................................
  error:
    return 0;
}

RL2_DECLARE rl2TiffDestinationPtr
rl2_create_tiff_destination (const char *path, unsigned int width,
			     unsigned int height, unsigned char sample_type,
			     unsigned char pixel_type,
			     unsigned char num_bands, rl2PalettePtr plt,
			     unsigned char tiff_compression, int tiled,
			     unsigned int tile_size)
{
/* attempting to create a file-based TIFF destination (no georeferencing) */
    rl2PrivTiffDestinationPtr destination = NULL;
    if (!check_color_model
	(sample_type, pixel_type, num_bands, plt, tiff_compression))
      {
	  fprintf (stderr, "RL2-TIFF writer: unsupported pixel format\n");
................................................................................
      }
    if (TIFFWriteScanline (tiff->out, tiff->tiffBuffer, row, 0) < 0)
	return 0;
    return 1;
}

static int
tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff,
		       rl2PrivRasterPtr raster, unsigned int row)
{
/* writing a TIFF Grayscale scanline */
    unsigned int x;
    unsigned char *p_in = raster->rasterBuffer;
    unsigned char *p_out = tiff->tiffBuffer;

    for (x = 0; x < raster->width; x++)
................................................................................
	      0)
	      return 0;
      }
    return 1;
}

static int
tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff,
			rl2PrivRasterPtr raster, unsigned int row,
			unsigned int col)
{
/* writing a TIFF RGB tile - UINT8 */
    unsigned int y;
    unsigned int x;
    unsigned char *p_in = raster->rasterBuffer;
    unsigned char *p_out = tiff->tiffBuffer;

................................................................................
	     && rst->nBands == destination->samplesPerPixel
	     && destination->tileWidth == rst->width
	     && destination->tileHeight == rst->height)
	ret =
	    tiff_write_tile_multiband16 (destination, rst, startRow, startCol);
    else if (destination->sampleFormat == SAMPLEFORMAT_UINT
	     && destination->samplesPerPixel == 1
	     && destination->photometric < 2
	     && destination->bitsPerSample == 8
	     && rst->sampleType == RL2_SAMPLE_UINT8
	     && rst->pixelType == RL2_PIXEL_GRAYSCALE && rst->nBands == 1
	     && destination->tileWidth == rst->width
	     && destination->tileHeight == rst->height)
	ret = tiff_write_tile_gray (destination, rst, startRow, startCol);
    else if (destination->sampleFormat == SAMPLEFORMAT_UINT
	     && destination->samplesPerPixel == 1
................................................................................
	return RL2_ERROR;
    if (destination->tfw_path == NULL)
	return RL2_ERROR;

    tfw = fopen (destination->tfw_path, "w");
    if (tfw == NULL)
      {
	  fprintf (stderr,
		   "RL2-TIFF writer: unable to open Worldfile \"%s\"\n",
		   destination->tfw_path);
	  return RL2_ERROR;
      }
    fprintf (tfw, "        %1.16f\n", destination->hResolution);
    fprintf (tfw, "        0.0\n");
    fprintf (tfw, "        0.0\n");
    fprintf (tfw, "        -%1.16f\n", destination->vResolution);
................................................................................
    TIFFClose (in);
    if (tiff_buffer != NULL)
	free (tiff_buffer);
    return RL2_ERROR;
}

static int
rgb_tiff_common (TIFF * out, const unsigned char *buffer,
		 unsigned short width, unsigned short height)
{
/* common implementation of RGB TIFF export */
    tsize_t buf_size;
    void *tiff_buffer = NULL;
    int y;
    int x;
    const unsigned char *p_in;
................................................................................
    return 0;
}

static int
output_palette_tiff (const unsigned char *buffer,
		     unsigned short width,
		     unsigned short height, unsigned char *red,
		     unsigned char *green, unsigned char *blue,
		     int max_palette, unsigned char **blob, int *blob_size)
{
/* generating a PALETTE TIFF - actual work */
    struct memfile clientdata;
    TIFF *out = (TIFF *) 0;

/* suppressing TIFF warnings */
    TIFFSetWarningHandler (NULL);
................................................................................
	       tiff_size))
	      return RL2_ERROR;
      }
    return RL2_OK;
}

static int
gray_tiff_common (TIFF * out, const unsigned char *buffer,
		  unsigned short width, unsigned short height)
{
/* common implementation of Grayscale TIFF export */
    tsize_t buf_size;
    void *tiff_buffer = NULL;
    int y;
    int x;
    const unsigned char *p_in;
................................................................................
	xml =
	    sqlite3_mprintf ("%s<Compression>%u</Compression>", prev,
			     org->compression);
    sqlite3_free (prev);
    prev = xml;
    if (org->sampleFormat == SAMPLEFORMAT_UINT)
	xml =
	    sqlite3_mprintf
	    ("%s<SampleFormat>unsigned integer</SampleFormat>", prev);
    else if (org->sampleFormat == SAMPLEFORMAT_INT)
	xml =
	    sqlite3_mprintf ("%s<SampleFormat>signed integer</SampleFormat>",
			     prev);
    else if (org->sampleFormat == SAMPLEFORMAT_IEEEFP)
	xml =
	    sqlite3_mprintf ("%s<SampleFormat>floating point</SampleFormat>",
................................................................................
	  xml = sqlite3_mprintf ("%s</BoundingBox>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml = sqlite3_mprintf ("%s<Extent>", prev);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf
	      ("%s<HorizontalExtent>%1.10f</HorizontalExtent>", prev,
	       org->maxX - org->minX);
	  sqlite3_free (prev);
	  prev = xml;
	  xml =
	      sqlite3_mprintf ("%s<VerticalExtent>%1.10f</VerticalExtent>",
			       prev, org->maxY - org->minY);
	  sqlite3_free (prev);
	  prev = xml;

Changes to src/rl2webp.c.

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	  else
	      return RL2_ERROR;
      }
    return RL2_OK;
}

static void
copy_pixels (unsigned char *out, const unsigned char *in, int width, int height,
	     int num_bands)
{
/* copying pixels */
    int x;
    int y;
    int ib;
    const unsigned char *p_in = in;
    unsigned char *p_out = out;
................................................................................
	RL2_ERROR)
	return RL2_ERROR;
    if (quality > 100)
	quality = 100;
    if (quality < 0)
	quality = 75;
    size =
	WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4, quality,
			&output);
    free (rgba);
    if (size == 0)
	return RL2_ERROR;
    *webp = output;
    *webp_size = size;
    return RL2_OK;
}







|
|







 







|
|







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	  else
	      return RL2_ERROR;
      }
    return RL2_OK;
}

static void
copy_pixels (unsigned char *out, const unsigned char *in, int width,
	     int height, int num_bands)
{
/* copying pixels */
    int x;
    int y;
    int ib;
    const unsigned char *p_in = in;
    unsigned char *p_out = out;
................................................................................
	RL2_ERROR)
	return RL2_ERROR;
    if (quality > 100)
	quality = 100;
    if (quality < 0)
	quality = 75;
    size =
	WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4,
			quality, &output);
    free (rgba);
    if (size == 0)
	return RL2_ERROR;
    *webp = output;
    *webp_size = size;
    return RL2_OK;
}

Changes to src/rl2wms.c.

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
....
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
....
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
....
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
....
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
....
2752
2753
2754
2755
2756
2757
2758

2759
2760
2761
2762
2763
2764
2765
2766
2767
....
2805
2806
2807
2808
2809
2810
2811

2812
2813
2814
2815
2816
2817
2818
2819
2820
....
2934
2935
2936
2937
2938
2939
2940
2941

2942
2943
2944
2945
2946
2947
2948
2949
....
3245
3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259
3260
....
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
....
3349
3350
3351
3352
3353
3354
3355

3356
3357
3358
3359
3360
3361
3362
3363
3364
....
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
....
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
....
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
....
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
....
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
....
6945
6946
6947
6948
6949
6950
6951

6952
6953
6954
6955
6956
6957
6958
6959
....
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104

7105
7106
7107
7108
7109
7110
7111
....
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
....
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
....
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
    while (pI != NULL)
      {
	  /* populating the array */
	  *(cache->SortedByUrl + pos) = pI;
	  pos++;
	  pI = pI->Next;
      }
    qsort (cache->SortedByUrl, cache->NumCachedItems, sizeof (wmsCachedItemPtr),
	   compare_url);
}

static void
wmsCacheSqueeze (wmsCachePtr cache, int limit)
{
/* squeezing the WMS Cache */
    int i;
................................................................................
	cache->LastCapab->Next = ptr;
    cache->LastCapab = ptr;
    cache->TotalDownload += (double) size;
}


static void
wmsAddCachedItem (wmsCachePtr cache, const char *url, const unsigned char *item,
		  int size, const char *image_format)
{
/* adding a new WMS Cached Item */
    wmsCachedItemPtr ptr;
    if (cache == NULL)
	return;
    if (cache->CurrentSize + size > cache->MaxSize)
	wmsCacheSqueeze (cache, cache->MaxSize - size);
................................................................................
	ptr->first = arg;
    if (ptr->last != NULL)
	ptr->last->next = arg;
    ptr->last = arg;
}

static void
parse_pattern_bbox (const char *value, double *minx, double *miny, double *maxx,
		    double *maxy)
{
/* parsing a BBOX arg [minx,miny,maxx,maxy] */
    int step = 0;
    const char *p_start = value;
    const char *p_end = value;
    *minx = DBL_MAX;
    *miny = DBL_MAX;
................................................................................
		outbuf.WriteOffset -= 2;
		continue;
	    }
	  if (cdata)
	    {
		/* masking XML special characters */
		if (*(p_in + i) == '<')
		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&lt;",
					4);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&gt;",
					4);
		else if (*(p_in + i) == '&')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&amp;", 5);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&quot;", 6);
		else
................................................................................
		outbuf.WriteOffset -= 2;
		continue;
	    }
	  if (cdata)
	    {
		/* masking XML special characters */
		if (*(p_in + i) == '<')
		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&lt;",
					4);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf, (const unsigned char *) "&gt;",
					4);
		else if (*(p_in + i) == '&')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&amp;", 5);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&quot;", 6);
		else
................................................................................
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_organization =
				    (const char *) (child_node->content);
			}
		  }
		if (strcmp ((const char *) (cur_node->name), "ContactPerson") ==
		    0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_person =
				    (const char *) (child_node->content);
................................................................................
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*city = (const char *) (child_node->content);
			}
		  }

		if (strcmp ((const char *) (cur_node->name), "StateOrProvince")
		    == 0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*state_province =
				    (const char *) (child_node->content);
................................................................................
    xmlNodePtr cur_node = NULL;
    xmlNodePtr child_node = NULL;

    for (cur_node = node; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {

		if (strcmp ((const char *) (cur_node->name), "ContactPosition")
		    == 0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_position =
				    (const char *) (child_node->content);
................................................................................
		    ((const char *) (cur_node->name),
		     "ContactInformation") == 0)
		    parse_wms_contact_information (cur_node->children,
						   &contact_person,
						   &contact_organization,
						   &contact_position,
						   &postal_address, &city,
						   &state_province, &post_code,

						   &country, &voice_telephone,
						   &fax_telephone,
						   &email_address);
		if (strcmp ((const char *) (cur_node->name), "Fees") == 0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
................................................................................
						    cap->GetMapURLGet = NULL;
						}
					      p = (const char
						   *) (text->content);
					      len = strlen (p);
					      cap->GetTileServiceURLGet =
						  malloc (len + 1);

					      strcpy (cap->GetTileServiceURLGet,
						      p);
					  }
				    }
			      }
			    attr = attr->next;
			}
		  }
	    }
................................................................................
				  if (strcmp
				      ((const char *) (attr->name),
				       "href") == 0)
				    {
					xmlNodePtr text = attr->children;
					if (text->type == XML_TEXT_NODE)
					  {
					      if (cap->GetTileServiceURLPost !=
						  NULL)
						{
						    free (cap->
							  GetTileServiceURLPost);
						    cap->GetTileServiceURLPost =
							NULL;
						}
					      p = (const char
................................................................................
							NULL;
						}
					      p = (const char
						   *) (text->content);
					      len = strlen (p);
					      cap->GetFeatureInfoURLGet =
						  malloc (len + 1);

					      strcpy (cap->GetFeatureInfoURLGet,
						      p);
					  }
				    }
			      }
			    attr = attr->next;
			}
		  }
	    }
................................................................................
				  if (strcmp
				      ((const char *) (attr->name),
				       "href") == 0)
				    {
					xmlNodePtr text = attr->children;
					if (text->type == XML_TEXT_NODE)
					  {
					      if (cap->GetFeatureInfoURLPost !=
						  NULL)
						{
						    free (cap->GetFeatureInfoURLPost);
						    cap->GetFeatureInfoURLPost =
							NULL;
						}
					      p = (const char
						   *) (text->content);
................................................................................
					    ok = 1;
					if (strcmp
					    (format,
					     "application/vnd.ogc.gml") == 0)
					    ok = 1;
					if (strcmp
					    (format,
					     "application/vnd.ogc.gml/3.1.1") ==
					    0)
					    ok = 1;
					if (ok)
					  {
					      int len = strlen (format);
					      cap->GmlMimeType =
						  malloc (len + 1);
					      strcpy (cap->GmlMimeType, format);
................................................................................

    for (; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {
		if (strcmp ((const char *) (cur_node->name), "Service") == 0)
		    parse_tile_service_info (cur_node, cap);
		if (strcmp ((const char *) (cur_node->name), "TiledPatterns") ==
		    0)
		    parse_tiled_patterns (cur_node, cap);
	    }
      }
}

static void
parse_wms_get_tile_service (wmsCapabilitiesPtr capabilities, const char *buf)
................................................................................
    else
	return;

    for (; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {
		if (strcmp ((const char *) (cur_node->name), "featureMember") ==
		    0)
		    parse_wms_feature_member (cur_node->children, coll);
	    }
      }
}

static wmsFeatureCollectionPtr
parse_wms_feature_collection (const char *buf)
................................................................................
	    }
      }

    return coll;
}

static int
query_TileService (rl2WmsCachePtr cache_handle, wmsCapabilitiesPtr capabilities,
		   const char *proxy)
{
/* attempting to get and parse a WMS GetTileService request */
    CURL *curl = NULL;
    CURLcode res;
    wmsMemBuffer headerBuf;
    wmsMemBuffer bodyBuf;
    int http_status;
................................................................................
	  attr = attr->next;
      }
    return NULL;
}

RL2_DECLARE int
get_wms_feature_attribute_blob_geometry (rl2WmsFeatureMemberPtr handle,

					 int index, const unsigned char **blob,
					 int *blob_size)
{
/* attempting to get the Nth FeatureAttribute (Geometry) from some WMS-FeatureMember object */
    int count = 0;
    wmsFeatureAttributePtr attr;
    wmsFeatureMemberPtr ptr = (wmsFeatureMemberPtr) handle;
    if (ptr == NULL)
................................................................................
	  /* "?" marker not declared */
	  if (swap_xy)
	      request =
		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, miny, minx,
				   maxy, maxx, width, height, style, format,
				   (opaque == 0) ? "TRUE" : "FALSE");
	  else
	      request =
		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, minx, miny,
				   maxx, maxy, width, height, style, format,
				   (opaque == 0) ? "TRUE" : "FALSE");
      }
    else
      {
	  /* "?" marker already defined */
	  if (swap_xy)
	      request =
		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, miny, minx,
				   maxy, maxx, width, height, style, format,
				   (opaque == 0) ? "TRUE" : "FALSE");
	  else
	      request =
		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, minx, miny,
				   maxx, maxy, width, height, style, format,
				   (opaque == 0) ? "TRUE" : "FALSE");
      }


    if (cache != NULL)
      {
	  /* checks if it's already stored into the WMS Cache */
	  wmsCachedItemPtr cachedItem = getWmsCachedItem (cache, request);
	  if (cachedItem != NULL)
	    {
................................................................................
		    double maxx, double maxy, int width, int height,
		    const char *style, const char *format, int opaque,
		    int from_cache, char **err_msg)
{
/* attempting to execute a WMS GepMap request [method POST] */

/* not yet implemented: just a stupid placeholder always returning NULL */
    if (cache_handle == NULL || url == NULL || proxy == NULL || version == NULL
	|| layer == NULL || crs == NULL)
	return NULL;
    if (minx == miny || maxx == maxy || width == height || opaque == from_cache
	|| width == swap_xy)
	return NULL;
    if (style == NULL || format == NULL || err_msg == NULL)
	return NULL;
    return NULL;
}

RL2_DECLARE unsigned char *
................................................................................
      {
	  if (swap_xy)
	      request =
		  sqlite3_mprintf
		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
		   crs, miny, minx, maxy, maxx, width, height, mouse_x,
		   mouse_y, format);
	  else
	      request =
		  sqlite3_mprintf
		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
		   crs, minx, miny, maxx, maxy, width, height, mouse_x,
		   mouse_y, format);
      }
    else
      {
	  if (swap_xy)
	      request =
		  sqlite3_mprintf
		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
		   crs, miny, minx, maxy, maxx, width, height, mouse_x,
		   mouse_y, format);
	  else
	      request =
		  sqlite3_mprintf
		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix,
		   crs, minx, miny, maxx, maxy, width, height, mouse_x,
		   mouse_y, format);
      }

    curl = curl_easy_init ();
    if (curl)
      {
	  /* setting the URL */
	  curl_easy_setopt (curl, CURLOPT_URL, request);
................................................................................
    return (rl2WmsFeatureCollectionPtr) coll;
}

RL2_DECLARE rl2WmsFeatureCollectionPtr
do_wms_GetFeatureInfo_post (const char *url, const char *proxy,
			    const char *version, const char *format,
			    const char *layer, const char *crs, int swap_xy,
			    double minx, double miny, double maxx, double maxy,
			    int width, int height, int mouse_x, int mouse_y,
			    char **err_msg)
{
/* attempting to execute a WMS GepFeatureInfo request [method POST] */

/* not yet implemented: just a stupid placeholder always returning NULL */
    if (url == NULL || proxy == NULL || version == NULL || format == NULL
	|| layer == NULL || crs == NULL)
	return NULL;







|
|







 







|
|







 







|
|







 







|
|

|
|







 







|
|

|
|







 







|
|







 







>
|
<







 







>
|
<







 







|
>
|







 







>
|
|







 







|
|







 







>
|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







>
|







 







|
|
|






|
|
|










|
|
|






|
|
|

>







 







|
|

|
|







 







|
|
|






|
|
|









|
|
|






|
|
|







 







|
|
|







534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
....
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
....
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
....
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
....
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
....
2752
2753
2754
2755
2756
2757
2758
2759
2760

2761
2762
2763
2764
2765
2766
2767
....
2805
2806
2807
2808
2809
2810
2811
2812
2813

2814
2815
2816
2817
2818
2819
2820
....
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
....
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
....
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
....
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
....
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
....
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
....
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
....
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
....
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
....
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
....
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
....
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
....
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
....
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
    while (pI != NULL)
      {
	  /* populating the array */
	  *(cache->SortedByUrl + pos) = pI;
	  pos++;
	  pI = pI->Next;
      }
    qsort (cache->SortedByUrl, cache->NumCachedItems,
	   sizeof (wmsCachedItemPtr), compare_url);
}

static void
wmsCacheSqueeze (wmsCachePtr cache, int limit)
{
/* squeezing the WMS Cache */
    int i;
................................................................................
	cache->LastCapab->Next = ptr;
    cache->LastCapab = ptr;
    cache->TotalDownload += (double) size;
}


static void
wmsAddCachedItem (wmsCachePtr cache, const char *url,
		  const unsigned char *item, int size, const char *image_format)
{
/* adding a new WMS Cached Item */
    wmsCachedItemPtr ptr;
    if (cache == NULL)
	return;
    if (cache->CurrentSize + size > cache->MaxSize)
	wmsCacheSqueeze (cache, cache->MaxSize - size);
................................................................................
	ptr->first = arg;
    if (ptr->last != NULL)
	ptr->last->next = arg;
    ptr->last = arg;
}

static void
parse_pattern_bbox (const char *value, double *minx, double *miny,
		    double *maxx, double *maxy)
{
/* parsing a BBOX arg [minx,miny,maxx,maxy] */
    int step = 0;
    const char *p_start = value;
    const char *p_end = value;
    *minx = DBL_MAX;
    *miny = DBL_MAX;
................................................................................
		outbuf.WriteOffset -= 2;
		continue;
	    }
	  if (cdata)
	    {
		/* masking XML special characters */
		if (*(p_in + i) == '<')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&lt;", 4);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&gt;", 4);
		else if (*(p_in + i) == '&')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&amp;", 5);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&quot;", 6);
		else
................................................................................
		outbuf.WriteOffset -= 2;
		continue;
	    }
	  if (cdata)
	    {
		/* masking XML special characters */
		if (*(p_in + i) == '<')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&lt;", 4);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&gt;", 4);
		else if (*(p_in + i) == '&')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&amp;", 5);
		else if (*(p_in + i) == '>')
		    wmsMemBufferAppend (&outbuf,
					(const unsigned char *) "&quot;", 6);
		else
................................................................................
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_organization =
				    (const char *) (child_node->content);
			}
		  }
		if (strcmp ((const char *) (cur_node->name), "ContactPerson")
		    == 0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_person =
				    (const char *) (child_node->content);
................................................................................
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*city = (const char *) (child_node->content);
			}
		  }
		if (strcmp
		    ((const char *) (cur_node->name), "StateOrProvince") == 0)

		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*state_province =
				    (const char *) (child_node->content);
................................................................................
    xmlNodePtr cur_node = NULL;
    xmlNodePtr child_node = NULL;

    for (cur_node = node; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {
		if (strcmp
		    ((const char *) (cur_node->name), "ContactPosition") == 0)

		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
			    if (child_node->type == XML_TEXT_NODE)
				*contact_position =
				    (const char *) (child_node->content);
................................................................................
		    ((const char *) (cur_node->name),
		     "ContactInformation") == 0)
		    parse_wms_contact_information (cur_node->children,
						   &contact_person,
						   &contact_organization,
						   &contact_position,
						   &postal_address, &city,
						   &state_province,
						   &post_code, &country,
						   &voice_telephone,
						   &fax_telephone,
						   &email_address);
		if (strcmp ((const char *) (cur_node->name), "Fees") == 0)
		  {
		      child_node = cur_node->children;
		      if (child_node != NULL)
			{
................................................................................
						    cap->GetMapURLGet = NULL;
						}
					      p = (const char
						   *) (text->content);
					      len = strlen (p);
					      cap->GetTileServiceURLGet =
						  malloc (len + 1);
					      strcpy
						  (cap->GetTileServiceURLGet,
						   p);
					  }
				    }
			      }
			    attr = attr->next;
			}
		  }
	    }
................................................................................
				  if (strcmp
				      ((const char *) (attr->name),
				       "href") == 0)
				    {
					xmlNodePtr text = attr->children;
					if (text->type == XML_TEXT_NODE)
					  {
					      if (cap->GetTileServiceURLPost
						  != NULL)
						{
						    free (cap->
							  GetTileServiceURLPost);
						    cap->GetTileServiceURLPost =
							NULL;
						}
					      p = (const char
................................................................................
							NULL;
						}
					      p = (const char
						   *) (text->content);
					      len = strlen (p);
					      cap->GetFeatureInfoURLGet =
						  malloc (len + 1);
					      strcpy
						  (cap->GetFeatureInfoURLGet,
						   p);
					  }
				    }
			      }
			    attr = attr->next;
			}
		  }
	    }
................................................................................
				  if (strcmp
				      ((const char *) (attr->name),
				       "href") == 0)
				    {
					xmlNodePtr text = attr->children;
					if (text->type == XML_TEXT_NODE)
					  {
					      if (cap->GetFeatureInfoURLPost
						  != NULL)
						{
						    free (cap->GetFeatureInfoURLPost);
						    cap->GetFeatureInfoURLPost =
							NULL;
						}
					      p = (const char
						   *) (text->content);
................................................................................
					    ok = 1;
					if (strcmp
					    (format,
					     "application/vnd.ogc.gml") == 0)
					    ok = 1;
					if (strcmp
					    (format,
					     "application/vnd.ogc.gml/3.1.1")
					    == 0)
					    ok = 1;
					if (ok)
					  {
					      int len = strlen (format);
					      cap->GmlMimeType =
						  malloc (len + 1);
					      strcpy (cap->GmlMimeType, format);
................................................................................

    for (; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {
		if (strcmp ((const char *) (cur_node->name), "Service") == 0)
		    parse_tile_service_info (cur_node, cap);
		if (strcmp ((const char *) (cur_node->name), "TiledPatterns")
		    == 0)
		    parse_tiled_patterns (cur_node, cap);
	    }
      }
}

static void
parse_wms_get_tile_service (wmsCapabilitiesPtr capabilities, const char *buf)
................................................................................
    else
	return;

    for (; cur_node; cur_node = cur_node->next)
      {
	  if (cur_node->type == XML_ELEMENT_NODE)
	    {
		if (strcmp ((const char *) (cur_node->name), "featureMember")
		    == 0)
		    parse_wms_feature_member (cur_node->children, coll);
	    }
      }
}

static wmsFeatureCollectionPtr
parse_wms_feature_collection (const char *buf)
................................................................................
	    }
      }

    return coll;
}

static int
query_TileService (rl2WmsCachePtr cache_handle,
		   wmsCapabilitiesPtr capabilities, const char *proxy)
{
/* attempting to get and parse a WMS GetTileService request */
    CURL *curl = NULL;
    CURLcode res;
    wmsMemBuffer headerBuf;
    wmsMemBuffer bodyBuf;
    int http_status;
................................................................................
	  attr = attr->next;
      }
    return NULL;
}

RL2_DECLARE int
get_wms_feature_attribute_blob_geometry (rl2WmsFeatureMemberPtr handle,
					 int index,
					 const unsigned char **blob,
					 int *blob_size)
{
/* attempting to get the Nth FeatureAttribute (Geometry) from some WMS-FeatureMember object */
    int count = 0;
    wmsFeatureAttributePtr attr;
    wmsFeatureMemberPtr ptr = (wmsFeatureMemberPtr) handle;
    if (ptr == NULL)
................................................................................
	  /* "?" marker not declared */
	  if (swap_xy)
	      request =
		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, miny,
				   minx, maxy, maxx, width, height, style,
				   format, (opaque == 0) ? "TRUE" : "FALSE");
	  else
	      request =
		  sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, minx,
				   miny, maxx, maxy, width, height, style,
				   format, (opaque == 0) ? "TRUE" : "FALSE");
      }
    else
      {
	  /* "?" marker already defined */
	  if (swap_xy)
	      request =
		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, miny,
				   minx, maxy, maxx, width, height, style,
				   format, (opaque == 0) ? "TRUE" : "FALSE");
	  else
	      request =
		  sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s"
				   "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
				   "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s"
				   "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url,
				   version, layer, crs_prefix, crs, minx,
				   miny, maxx, maxy, width, height, style,
				   format, (opaque == 0) ? "TRUE" : "FALSE");
      }
    fprintf (stderr, "\n%s\n", request);

    if (cache != NULL)
      {
	  /* checks if it's already stored into the WMS Cache */
	  wmsCachedItemPtr cachedItem = getWmsCachedItem (cache, request);
	  if (cachedItem != NULL)
	    {
................................................................................
		    double maxx, double maxy, int width, int height,
		    const char *style, const char *format, int opaque,
		    int from_cache, char **err_msg)
{
/* attempting to execute a WMS GepMap request [method POST] */

/* not yet implemented: just a stupid placeholder always returning NULL */
    if (cache_handle == NULL || url == NULL || proxy == NULL
	|| version == NULL || layer == NULL || crs == NULL)
	return NULL;
    if (minx == miny || maxx == maxy || width == height
	|| opaque == from_cache || width == swap_xy)
	return NULL;
    if (style == NULL || format == NULL || err_msg == NULL)
	return NULL;
    return NULL;
}

RL2_DECLARE unsigned char *
................................................................................
      {
	  if (swap_xy)
	      request =
		  sqlite3_mprintf
		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer,
		   crs_prefix, crs, miny, minx, maxy, maxx, width, height,
		   mouse_x, mouse_y, format);
	  else
	      request =
		  sqlite3_mprintf
		  ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer,
		   crs_prefix, crs, minx, miny, maxx, maxy, width, height,
		   mouse_x, mouse_y, format);
      }
    else
      {
	  if (swap_xy)
	      request =
		  sqlite3_mprintf
		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer,
		   crs_prefix, crs, miny, minx, maxy, maxx, width, height,
		   mouse_x, mouse_y, format);
	  else
	      request =
		  sqlite3_mprintf
		  ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s"
		   "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f"
		   "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s"
		   "&FEATURE_COUNT=50", url, version, layer, layer,
		   crs_prefix, crs, minx, miny, maxx, maxy, width, height,
		   mouse_x, mouse_y, format);
      }

    curl = curl_easy_init ();
    if (curl)
      {
	  /* setting the URL */
	  curl_easy_setopt (curl, CURLOPT_URL, request);
................................................................................
    return (rl2WmsFeatureCollectionPtr) coll;
}

RL2_DECLARE rl2WmsFeatureCollectionPtr
do_wms_GetFeatureInfo_post (const char *url, const char *proxy,
			    const char *version, const char *format,
			    const char *layer, const char *crs, int swap_xy,
			    double minx, double miny, double maxx,
			    double maxy, int width, int height, int mouse_x,
			    int mouse_y, char **err_msg)
{
/* attempting to execute a WMS GepFeatureInfo request [method POST] */

/* not yet implemented: just a stupid placeholder always returning NULL */
    if (url == NULL || proxy == NULL || version == NULL || format == NULL
	|| layer == NULL || crs == NULL)
	return NULL;

Changes to test/Makefile.am.

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
	test_map_indiana test_load_wms \
	test_map_noref test_map_trento \
	test_map_trieste test_map_infrared \
	test_map_orbetello test_raster_symbolizer \
	test_svg test_raw test_openjpeg \
	test_line_symbolizer test_polygon_symbolizer \
	test_point_symbolizer test_text_symbolizer \
	test_vectors test_font test_copy_rastercov


AM_CPPFLAGS = -I@srcdir@/../headers @LIBXML2_CFLAGS@
AM_LDFLAGS = -L../src -lrasterlite2 @LIBCAIRO_LIBS@ @LIBPNG_LIBS@ \
	@LIBWEBP_LIBS@ @LIBLZMA_LIBS@ @LIBSPATIALITE_LIBS@ \
	@LIBCURL_LIBS@ @LIBXML2_LIBS@  @LIBFREETYPE2_LIBS@ \
	$(GCOV_FLAGS)








|
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
	test_map_indiana test_load_wms \
	test_map_noref test_map_trento \
	test_map_trieste test_map_infrared \
	test_map_orbetello test_raster_symbolizer \
	test_svg test_raw test_openjpeg \
	test_line_symbolizer test_polygon_symbolizer \
	test_point_symbolizer test_text_symbolizer \
	test_vectors test_font test_copy_rastercov \
	test_tile_callback

AM_CPPFLAGS = -I@srcdir@/../headers @LIBXML2_CFLAGS@
AM_LDFLAGS = -L../src -lrasterlite2 @LIBCAIRO_LIBS@ @LIBPNG_LIBS@ \
	@LIBWEBP_LIBS@ @LIBLZMA_LIBS@ @LIBSPATIALITE_LIBS@ \
	@LIBCURL_LIBS@ @LIBXML2_LIBS@  @LIBFREETYPE2_LIBS@ \
	$(GCOV_FLAGS)

Changes to test/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17










18
19
20
21
22
23
24
..
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
...
291
292
293
294
295
296
297



298
299
300
301
302
303
304
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
618
619
620
621
622
623
624


625
626
627
628
629
630
631
...
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
....
1144
1145
1146
1147
1148
1149
1150




1151
1152
1153
1154
1155
1156
1157
....
1229
1230
1231
1232
1233
1234
1235

1236
1237
1238
1239
1240
1241
1242
....
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
....
1943
1944
1945
1946
1947
1948
1949







1950
1951
1952
1953
1954
1955
1956
....
2141
2142
2143
2144
2145
2146
2147


2148
2149
2150
2151
2152
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
	test_map_noref$(EXEEXT) test_map_trento$(EXEEXT) \
	test_map_trieste$(EXEEXT) test_map_infrared$(EXEEXT) \
	test_map_orbetello$(EXEEXT) test_raster_symbolizer$(EXEEXT) \
	test_svg$(EXEEXT) test_raw$(EXEEXT) test_openjpeg$(EXEEXT) \
	test_line_symbolizer$(EXEEXT) test_polygon_symbolizer$(EXEEXT) \
	test_point_symbolizer$(EXEEXT) test_text_symbolizer$(EXEEXT) \
	test_vectors$(EXEEXT) test_font$(EXEEXT) \
	test_copy_rastercov$(EXEEXT)
subdir = test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
	$(top_srcdir)/depcomp $(top_srcdir)/test-driver
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)

mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
check_sql_stmt_SOURCES = check_sql_stmt.c
check_sql_stmt_OBJECTS = check_sql_stmt.$(OBJEXT)
check_sql_stmt_LDADD = $(LDADD)
................................................................................
test_svg_LDADD = $(LDADD)
test_text_symbolizer_SOURCES = test_text_symbolizer.c
test_text_symbolizer_OBJECTS = test_text_symbolizer.$(OBJEXT)
test_text_symbolizer_LDADD = $(LDADD)
test_tifin_SOURCES = test_tifin.c
test_tifin_OBJECTS = test_tifin.$(OBJEXT)
test_tifin_LDADD = $(LDADD)



test_vectors_SOURCES = test_vectors.c
test_vectors_OBJECTS = test_vectors.$(OBJEXT)
test_vectors_LDADD = $(LDADD)
test_webp_SOURCES = test_webp.c
test_webp_OBJECTS = test_webp.$(OBJEXT)
test_webp_LDADD = $(LDADD)
test_wms1_SOURCES = test_wms1.c
................................................................................
	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
	test_map_srtm.c test_map_trento.c test_map_trieste.c \
	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
	test_point_symbolizer.c test_polygon_symbolizer.c \
	test_raster.c test_raster_symbolizer.c test_raw.c \
	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
	test_vectors.c test_webp.c test_wms1.c test_wms2.c \
	test_wr_tiff.c
DIST_SOURCES = check_sql_stmt.c test1.c test10.c test11.c test12.c \
	test13.c test14.c test15.c test16.c test17.c test18.c test19.c \
	test2.c test20.c test3.c test4.c test5.c test6.c test7.c \
	test8.c test9.c test_copy_rastercov.c test_coverage.c \
	test_font.c test_gif.c test_line_symbolizer.c test_load_wms.c \
	test_map_ascii.c test_map_gray.c test_map_indiana.c \
	test_map_infrared.c test_map_mono.c test_map_nile_32.c \
................................................................................
	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
	test_map_srtm.c test_map_trento.c test_map_trieste.c \
	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
	test_point_symbolizer.c test_polygon_symbolizer.c \
	test_raster.c test_raster_symbolizer.c test_raw.c \
	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
	test_vectors.c test_webp.c test_wms1.c test_wms2.c \
	test_wr_tiff.c
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
	ctags-recursive dvi-recursive html-recursive info-recursive \
	install-data-recursive install-dvi-recursive \
	install-exec-recursive install-html-recursive \
	install-info-recursive install-pdf-recursive \
	install-ps-recursive install-recursive installcheck-recursive \
	installdirs-recursive pdf-recursive ps-recursive \
................................................................................
am__test_logs1 = $(TESTS:=.log)
am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
TEST_LOGS = $(am__test_logs2:.test.log=.log)
TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
	$(TEST_LOG_FLAGS)
DIST_SUBDIRS = $(SUBDIRS)


DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
am__relativize = \
  dir0=`pwd`; \
  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
  sed_rest='s,^[^/]*/*,,'; \
  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
  sed_butlast='s,/*[^/]*$$,,'; \
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
test_text_symbolizer$(EXEEXT): $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_DEPENDENCIES) $(EXTRA_test_text_symbolizer_DEPENDENCIES) 
	@rm -f test_text_symbolizer$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_LDADD) $(LIBS)

test_tifin$(EXEEXT): $(test_tifin_OBJECTS) $(test_tifin_DEPENDENCIES) $(EXTRA_test_tifin_DEPENDENCIES) 
	@rm -f test_tifin$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_tifin_OBJECTS) $(test_tifin_LDADD) $(LIBS)





test_vectors$(EXEEXT): $(test_vectors_OBJECTS) $(test_vectors_DEPENDENCIES) $(EXTRA_test_vectors_DEPENDENCIES) 
	@rm -f test_vectors$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_vectors_OBJECTS) $(test_vectors_LDADD) $(LIBS)

test_webp$(EXEEXT): $(test_webp_OBJECTS) $(test_webp_DEPENDENCIES) $(EXTRA_test_webp_DEPENDENCIES) 
	@rm -f test_webp$(EXEEXT)
................................................................................
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster_symbolizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raw.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_section.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_svg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_text_symbolizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tifin.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_vectors.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_webp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wr_tiff.Po@am__quote@

.c.o:
................................................................................
	  if $(am__make_dryrun); then :; else \
	    rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
	  fi; \
	fi; \
	if test -n "$$am__remaking_logs"; then \
	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
	       "recursion detected" >&2; \
	else \
	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
	fi; \
	if $(am__make_dryrun); then :; else \
	  st=0;  \
	  errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
	  for i in $$redo_bases; do \
	    test -f $$i.trs && test -r $$i.trs \
................................................................................
test_copy_rastercov.log: test_copy_rastercov$(EXEEXT)
	@p='test_copy_rastercov$(EXEEXT)'; \
	b='test_copy_rastercov'; \
	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
	--log-file $$b.log --trs-file $$b.trs \
	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
	"$$tst" $(AM_TESTS_FD_REDIRECT)







.test.log:
	@p='$<'; \
	$(am__set_b); \
	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
	--log-file $$b.log --trs-file $$b.trs \
	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
	"$$tst" $(AM_TESTS_FD_REDIRECT)
................................................................................
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	installdirs-am maintainer-clean maintainer-clean-generic \
	mostlyclean mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \
	uninstall uninstall-am




# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|












|
>
>
>
>
>
>
>
>
>
>







 







|

<
<







>







 







>
>
>







 







|
|







 







|
|







 







>
>







 







<







 







>
>
>
>







 







>







 







|







 







>
>
>
>
>
>
>







 







>
>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
108
109
110
111
112
113
114
115
116


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
...
899
900
901
902
903
904
905

906
907
908
909
910
911
912
....
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
....
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
....
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
....
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
....
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
	test_map_noref$(EXEEXT) test_map_trento$(EXEEXT) \
	test_map_trieste$(EXEEXT) test_map_infrared$(EXEEXT) \
	test_map_orbetello$(EXEEXT) test_raster_symbolizer$(EXEEXT) \
	test_svg$(EXEEXT) test_raw$(EXEEXT) test_openjpeg$(EXEEXT) \
	test_line_symbolizer$(EXEEXT) test_polygon_symbolizer$(EXEEXT) \
	test_point_symbolizer$(EXEEXT) test_text_symbolizer$(EXEEXT) \
	test_vectors$(EXEEXT) test_font$(EXEEXT) \
	test_copy_rastercov$(EXEEXT) test_tile_callback$(EXEEXT)
subdir = test


ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
check_sql_stmt_SOURCES = check_sql_stmt.c
check_sql_stmt_OBJECTS = check_sql_stmt.$(OBJEXT)
check_sql_stmt_LDADD = $(LDADD)
................................................................................
test_svg_LDADD = $(LDADD)
test_text_symbolizer_SOURCES = test_text_symbolizer.c
test_text_symbolizer_OBJECTS = test_text_symbolizer.$(OBJEXT)
test_text_symbolizer_LDADD = $(LDADD)
test_tifin_SOURCES = test_tifin.c
test_tifin_OBJECTS = test_tifin.$(OBJEXT)
test_tifin_LDADD = $(LDADD)
test_tile_callback_SOURCES = test_tile_callback.c
test_tile_callback_OBJECTS = test_tile_callback.$(OBJEXT)
test_tile_callback_LDADD = $(LDADD)
test_vectors_SOURCES = test_vectors.c
test_vectors_OBJECTS = test_vectors.$(OBJEXT)
test_vectors_LDADD = $(LDADD)
test_webp_SOURCES = test_webp.c
test_webp_OBJECTS = test_webp.$(OBJEXT)
test_webp_LDADD = $(LDADD)
test_wms1_SOURCES = test_wms1.c
................................................................................
	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
	test_map_srtm.c test_map_trento.c test_map_trieste.c \
	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
	test_point_symbolizer.c test_polygon_symbolizer.c \
	test_raster.c test_raster_symbolizer.c test_raw.c \
	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
	test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \
	test_wms2.c test_wr_tiff.c
DIST_SOURCES = check_sql_stmt.c test1.c test10.c test11.c test12.c \
	test13.c test14.c test15.c test16.c test17.c test18.c test19.c \
	test2.c test20.c test3.c test4.c test5.c test6.c test7.c \
	test8.c test9.c test_copy_rastercov.c test_coverage.c \
	test_font.c test_gif.c test_line_symbolizer.c test_load_wms.c \
	test_map_ascii.c test_map_gray.c test_map_indiana.c \
	test_map_infrared.c test_map_mono.c test_map_nile_32.c \
................................................................................
	test_map_nile_u16.c test_map_nile_u32.c test_map_nile_u8.c \
	test_map_noref.c test_map_orbetello.c test_map_rgb.c \
	test_map_srtm.c test_map_trento.c test_map_trieste.c \
	test_mask.c test_openjpeg.c test_paint.c test_palette.c \
	test_point_symbolizer.c test_polygon_symbolizer.c \
	test_raster.c test_raster_symbolizer.c test_raw.c \
	test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \
	test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \
	test_wms2.c test_wr_tiff.c
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
	ctags-recursive dvi-recursive html-recursive info-recursive \
	install-data-recursive install-dvi-recursive \
	install-exec-recursive install-html-recursive \
	install-info-recursive install-pdf-recursive \
	install-ps-recursive install-recursive installcheck-recursive \
	installdirs-recursive pdf-recursive ps-recursive \
................................................................................
am__test_logs1 = $(TESTS:=.log)
am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
TEST_LOGS = $(am__test_logs2:.test.log=.log)
TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
	$(TEST_LOG_FLAGS)
DIST_SUBDIRS = $(SUBDIRS)
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
	$(top_srcdir)/test-driver
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
am__relativize = \
  dir0=`pwd`; \
  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
  sed_rest='s,^[^/]*/*,,'; \
  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
  sed_butlast='s,/*[^/]*$$,,'; \
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
test_text_symbolizer$(EXEEXT): $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_DEPENDENCIES) $(EXTRA_test_text_symbolizer_DEPENDENCIES) 
	@rm -f test_text_symbolizer$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_LDADD) $(LIBS)

test_tifin$(EXEEXT): $(test_tifin_OBJECTS) $(test_tifin_DEPENDENCIES) $(EXTRA_test_tifin_DEPENDENCIES) 
	@rm -f test_tifin$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_tifin_OBJECTS) $(test_tifin_LDADD) $(LIBS)

test_tile_callback$(EXEEXT): $(test_tile_callback_OBJECTS) $(test_tile_callback_DEPENDENCIES) $(EXTRA_test_tile_callback_DEPENDENCIES) 
	@rm -f test_tile_callback$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_tile_callback_OBJECTS) $(test_tile_callback_LDADD) $(LIBS)

test_vectors$(EXEEXT): $(test_vectors_OBJECTS) $(test_vectors_DEPENDENCIES) $(EXTRA_test_vectors_DEPENDENCIES) 
	@rm -f test_vectors$(EXEEXT)
	$(AM_V_CCLD)$(LINK) $(test_vectors_OBJECTS) $(test_vectors_LDADD) $(LIBS)

test_webp$(EXEEXT): $(test_webp_OBJECTS) $(test_webp_DEPENDENCIES) $(EXTRA_test_webp_DEPENDENCIES) 
	@rm -f test_webp$(EXEEXT)
................................................................................
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raster_symbolizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raw.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_section.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_svg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_text_symbolizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tifin.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tile_callback.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_vectors.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_webp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wr_tiff.Po@am__quote@

.c.o:
................................................................................
	  if $(am__make_dryrun); then :; else \
	    rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
	  fi; \
	fi; \
	if test -n "$$am__remaking_logs"; then \
	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
	       "recursion detected" >&2; \
	elif test -n "$$redo_logs"; then \
	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
	fi; \
	if $(am__make_dryrun); then :; else \
	  st=0;  \
	  errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
	  for i in $$redo_bases; do \
	    test -f $$i.trs && test -r $$i.trs \
................................................................................
test_copy_rastercov.log: test_copy_rastercov$(EXEEXT)
	@p='test_copy_rastercov$(EXEEXT)'; \
	b='test_copy_rastercov'; \
	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
	--log-file $$b.log --trs-file $$b.trs \
	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
	"$$tst" $(AM_TESTS_FD_REDIRECT)
test_tile_callback.log: test_tile_callback$(EXEEXT)
	@p='test_tile_callback$(EXEEXT)'; \
	b='test_tile_callback'; \
	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
	--log-file $$b.log --trs-file $$b.trs \
	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
	"$$tst" $(AM_TESTS_FD_REDIRECT)
.test.log:
	@p='$<'; \
	$(am__set_b); \
	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
	--log-file $$b.log --trs-file $$b.trs \
	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
	"$$tst" $(AM_TESTS_FD_REDIRECT)
................................................................................
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	installdirs-am maintainer-clean maintainer-clean-generic \
	mostlyclean mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \
	uninstall uninstall-am

.PRECIOUS: Makefile


# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to test/sql_stmt_security_tests/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17










18
19
20
21
22
23
24
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
...
106
107
108
109
110
111
112

113
114
115
116
117
118
119
...
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
....
1070
1071
1072
1073
1074
1075
1076


1077
1078
1079
1080
1081
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = test/sql_stmt_security_tests
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)

mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
DIST_SOURCES =
am__can_run_installinfo = \
  case $$AM_UPDATE_INFO_DIR in \
    n|no|NO) false;; \
    *) (install-info --version) >/dev/null 2>&1;; \
  esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)

DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-dvi-am install-exec install-exec-am install-html \
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags-am uninstall uninstall-am




# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|












|
>
>
>
>
>
>
>
>
>
>







 







<







>







 







>







 







<







 







>
>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
907
908
909
910
911
912
913

914
915
916
917
918
919
920
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = test/sql_stmt_security_tests

ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
DIST_SOURCES =
am__can_run_installinfo = \
  case $$AM_UPDATE_INFO_DIR in \
    n|no|NO) false;; \
    *) (install-info --version) >/dev/null 2>&1;; \
  esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-dvi-am install-exec install-exec-am install-html \
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags-am uninstall uninstall-am

.PRECIOUS: Makefile


# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to test/sql_stmt_tests/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17










18
19
20
21
22
23
24
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
...
106
107
108
109
110
111
112

113
114
115
116
117
118
119
...
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
....
1042
1043
1044
1045
1046
1047
1048


1049
1050
1051
1052
1053
1054
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = test/sql_stmt_tests
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)

mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
DIST_SOURCES =
am__can_run_installinfo = \
  case $$AM_UPDATE_INFO_DIR in \
    n|no|NO) false;; \
    *) (install-info --version) >/dev/null 2>&1;; \
  esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)

DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-dvi-am install-exec install-exec-am install-html \
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags-am uninstall uninstall-am



	version.testcase 

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|












|
>
>
>
>
>
>
>
>
>
>







 







<







>







 







>







 







<







 







>
>






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
879
880
881
882
883
884
885

886
887
888
889
890
891
892
....
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = test/sql_stmt_tests

ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
................................................................................
DIST_SOURCES =
am__can_run_installinfo = \
  case $$AM_UPDATE_INFO_DIR in \
    n|no|NO) false;; \
    *) (install-info --version) >/dev/null 2>&1;; \
  esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-dvi-am install-exec install-exec-am install-html \
	install-html-am install-info install-info-am install-man \
	install-pdf install-pdf-am install-ps install-ps-am \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags-am uninstall uninstall-am

.PRECIOUS: Makefile

	version.testcase 

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to test/symbolizers.sqlite.

cannot compute difference between binary files

Changes to test/test_line_symbolizer.c.

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







|







 







|







 







|







 







|







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

Changes to test/test_point_symbolizer.c.

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







|







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

Changes to test/test_polygon_symbolizer.c.

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







|







 







|







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

Added test/test_tile_callback.c.



































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/*

 test_tile_callback.c -- RasterLite2 Test Case

 Author: Alessandro Furieri <a.furieri@lqt.it>

 ------------------------------------------------------------------------------
 
 Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/
 
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.

The Original Code is the RasterLite2 library

The Initial Developer of the Original Code is Alessandro Furieri
 
Portions created by the Initial Developer are Copyright (C) 2013
the Initial Developer. All Rights Reserved.

Contributor(s):

Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <memory.h>

#include "config.h"

#include "sqlite3.h"
#include "spatialite.h"

#include "rasterlite2/rasterlite2.h"

struct tile_info
{
/* a struct supporting the Tile Callback function */
    unsigned char sample;
    unsigned char pixel;
    unsigned char num_bands;
    int srid;
    const char *coverage;
    unsigned int tile_w;
    unsigned int tile_h;
};

static void
set_tile_pixel_gray8 (unsigned char *bufpix, unsigned int x, unsigned int y,
		      unsigned int tile_w, double map_x, double map_y)
{
/* pixel generator - GRAYSCALE UINT8 */
    unsigned char *p = bufpix + ((y * tile_w) + x);
    if (map_y >= -15.0 && map_y <= 15.0)
      {
	  if (map_x < 0.0)
	      *p = 248;
	  else
	      *p = 216;
      }
    else if (map_y >= -60.0 && map_y <= 60.0)
      {
	  if (map_x < 0.0)
	      *p = 208;
	  else
	      *p = 192;
      }
    else
      {
	  if (map_x < 0.0)
	      *p = 128;
	  else
	      *p = 96;
      }
}

static void
set_tile_pixel_rgb8 (unsigned char *bufpix, unsigned int x, unsigned int y,
		     unsigned int tile_w, double map_x, double map_y,
		     unsigned int num_bands)
{
/* pixel generator - RGB UINT8 */
    unsigned char *p = bufpix + (y * tile_w * num_bands) + (x * num_bands);
    if (map_y >= -15.0 && map_y <= 15.0)
      {
	  if (map_x < 0.0)
	    {
		*p++ = 248;
		*p++ = 255;
		*p++ = 0;
	    }
	  else
	    {
		*p++ = 216;
		*p++ = 248;
		*p++ = 0;
	    }
      }
    else if (map_y >= -60.0 && map_y <= 60.0)
      {
	  if (map_x < 0.0)
	    {
		*p++ = 0;
		*p++ = 208;
		*p++ = 248;
	    }
	  else
	    {
		*p++ = 0;
		*p++ = 192;
		*p++ = 248;
	    }
      }
    else
      {
	  if (map_x < 0.0)
	    {
		*p++ = 192;
		*p++ = 192;
		*p++ = 128;
	    }
	  else
	    {
		*p++ = 192;
		*p++ = 192;
		*p++ = 96;
	    }
      }
}

static void
set_tile_pixel_int16 (unsigned char *bufpix, unsigned int x, unsigned int y,
		      unsigned int tile_w, double map_x, double map_y)
{
/* pixel generator - DATAGRID INT16 */
    short *p = (short *) bufpix;
    p += ((y * tile_w) + x);
    if (map_y >= -15.0 && map_y <= 15.0)
      {
	  if (map_x < 0.0)
	      *p = -10;
	  else
	      *p = 50;
      }
    else if (map_y >= -60.0 && map_y <= 60.0)
      {
	  if (map_x < 0.0)
	      *p = 100;
	  else
	      *p = 200;
      }
    else
      {
	  if (map_x < 0.0)
	      *p = -100;
	  else
	      *p = -50;
      }
}

static void
set_tile_pixel_double (unsigned char *bufpix, unsigned int x, unsigned int y,
		       unsigned int tile_w, double map_x, double map_y)
{
/* pixel generator - DATAGRID DOUBLE */
    double *p = (double *) bufpix;
    p += ((y * tile_w) + x);
    if (map_y >= -15.0 && map_y <= 15.0)
      {
	  if (map_x < 0.0)
	      *p = -10.06;
	  else
	      *p = 50.02;
      }
    else if (map_y >= -60.0 && map_y <= 60.0)
      {
	  if (map_x < 0.0)
	      *p = 100.03;
	  else
	      *p = 200.81;
      }
    else
      {
	  if (map_x < 0.0)
	      *p = -100.23;
	  else
	      *p = -50.41;
      }
}

static void
set_tile_pixel_uint8 (unsigned char *bufpix, unsigned int x, unsigned int y,
		      unsigned int tile_w, double map_x, double map_y,
		      unsigned char pixel, unsigned char num_bands)
{
/* pixel generator - UINT8 */
    switch (pixel)
      {
      case RL2_PIXEL_GRAYSCALE:
	  set_tile_pixel_gray8 (bufpix, x, y, tile_w, map_x, map_y);
	  break;
      case RL2_PIXEL_RGB:
	  set_tile_pixel_rgb8 (bufpix, x, y, tile_w, map_x, map_y, num_bands);
	  break;
      };
}

static void
set_tile_pixel (unsigned char *bufpix, unsigned int x, unsigned int y,
		unsigned int tile_w, double map_x, double map_y,
		unsigned char sample, unsigned char pixel,
		unsigned int num_bands)
{
/* generalized pixel generator */
    switch (sample)
      {
      case RL2_SAMPLE_UINT8:
	  set_tile_pixel_uint8 (bufpix, x, y, tile_w, map_x, map_y, pixel,
				num_bands);
	  break;
      case RL2_SAMPLE_INT16:
	  set_tile_pixel_int16 (bufpix, x, y, tile_w, map_x, map_y);
	  break;
      case RL2_SAMPLE_DOUBLE:
	  set_tile_pixel_double (bufpix, x, y, tile_w, map_x, map_y);
	  break;
      };
}

static int
tile_callback (void *data, double tile_minx, double tile_miny, double tile_maxx,
	       double tile_maxy, unsigned char *bufpix, rl2PalettePtr * palette)
{
/* callback function initializing a Tile */
    struct tile_info *info = (struct tile_info *) data;
    unsigned int x;
    unsigned int y;
    double res_x = (tile_maxx - tile_minx) / (double) (info->tile_w);
    double res_y = (tile_maxy - tile_miny) / (double) (info->tile_h);

/* setting tile pixels */
    for (y = 0; y < info->tile_h; y++)
      {
	  double map_y = tile_maxy - ((double) y * res_y);
	  if (map_y < tile_miny)
	      continue;
	  for (x = 0; x < info->tile_w; x++)
	    {
		double map_x = tile_minx + ((double) x * res_x);
		if (map_x > tile_maxx)
		    continue;
		set_tile_pixel (bufpix, x, y, info->tile_w, map_x, map_y,
				info->sample, info->pixel, info->num_bands);
	    }
      }

    return 1;
}

static rl2PixelPtr
default_nodata (unsigned char sample, unsigned char pixel,
		unsigned char num_bands)
{
/* creating a default NO-DATA value */
    int nb;
    rl2PixelPtr pxl = rl2_create_pixel (sample, pixel, num_bands);
    if (pxl == NULL)
	return NULL;
    switch (pixel)
      {
      case RL2_PIXEL_MONOCHROME:
	  rl2_set_pixel_sample_1bit (pxl, 0);
	  break;
      case RL2_PIXEL_PALETTE:
	  switch (sample)
	    {
	    case RL2_SAMPLE_1_BIT:
		rl2_set_pixel_sample_1bit (pxl, 0);
		break;
	    case RL2_SAMPLE_2_BIT:
		rl2_set_pixel_sample_2bit (pxl, 0);
		break;
	    case RL2_SAMPLE_4_BIT:
		rl2_set_pixel_sample_4bit (pxl, 0);
		break;
	    case RL2_SAMPLE_UINT8:
		rl2_set_pixel_sample_uint8 (pxl, 0, 0);
		break;
	    };
	  break;
      case RL2_PIXEL_GRAYSCALE:
	  switch (sample)
	    {
	    case RL2_SAMPLE_1_BIT:
		rl2_set_pixel_sample_1bit (pxl, 1);
		break;
	    case RL2_SAMPLE_2_BIT:
		rl2_set_pixel_sample_2bit (pxl, 3);
		break;
	    case RL2_SAMPLE_4_BIT:
		rl2_set_pixel_sample_4bit (pxl, 15);
		break;
	    case RL2_SAMPLE_UINT8:
		rl2_set_pixel_sample_uint8 (pxl, 0, 255);
		break;
	    case RL2_SAMPLE_UINT16:
		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
		break;
	    };
	  break;
      case RL2_PIXEL_RGB:
	  switch (sample)
	    {
	    case RL2_SAMPLE_UINT8:
		rl2_set_pixel_sample_uint8 (pxl, 0, 255);
		rl2_set_pixel_sample_uint8 (pxl, 1, 255);
		rl2_set_pixel_sample_uint8 (pxl, 2, 255);
		break;
	    case RL2_SAMPLE_UINT16:
		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
		rl2_set_pixel_sample_uint16 (pxl, 1, 0);
		rl2_set_pixel_sample_uint16 (pxl, 2, 0);
		break;
	    };
	  break;
      case RL2_PIXEL_DATAGRID:
	  switch (sample)
	    {
	    case RL2_SAMPLE_INT8:
		rl2_set_pixel_sample_int8 (pxl, 0);
		break;
	    case RL2_SAMPLE_UINT8:
		rl2_set_pixel_sample_uint8 (pxl, 0, 0);
		break;
	    case RL2_SAMPLE_INT16:
		rl2_set_pixel_sample_int16 (pxl, 0);
		break;
	    case RL2_SAMPLE_UINT16:
		rl2_set_pixel_sample_uint16 (pxl, 0, 0);
		break;
	    case RL2_SAMPLE_INT32:
		rl2_set_pixel_sample_int32 (pxl, 0);
		break;
	    case RL2_SAMPLE_UINT32:
		rl2_set_pixel_sample_uint32 (pxl, 0);
		break;
	    case RL2_SAMPLE_FLOAT:
		rl2_set_pixel_sample_float (pxl, 0.0);
		break;
	    case RL2_SAMPLE_DOUBLE:
		rl2_set_pixel_sample_double (pxl, 0.0);
		break;
	    };
	  break;
      case RL2_PIXEL_MULTIBAND:
	  switch (sample)
	    {
	    case RL2_SAMPLE_UINT8:
		for (nb = 0; nb < num_bands; nb++)
		    rl2_set_pixel_sample_uint8 (pxl, nb, 255);
		break;
	    case RL2_SAMPLE_UINT16:
		for (nb = 0; nb < num_bands; nb++)
		    rl2_set_pixel_sample_uint16 (pxl, nb, 0);
		break;
	    };
	  break;
      };
    return pxl;
}

static int
test_uint8_gray (sqlite3 * handle)
{
/* testing UINT8 GRAYSCALE */
    struct tile_info info;
    rl2CoveragePtr cvg;

    info.sample = RL2_SAMPLE_UINT8;
    info.pixel = RL2_PIXEL_GRAYSCALE;
    info.num_bands = 1;
    info.srid = 4326;
    info.coverage = "UINT8_GRAYSCALE";
    info.tile_w = 512;
    info.tile_h = 512;

    rl2PixelPtr no_data =
	default_nodata (info.sample, info.pixel, info.num_bands);
    if (rl2_create_dbms_coverage
	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
	 RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1,
	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
      {
	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
	  return 0;
      }

    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
    if (cvg == NULL)
      {
	  rl2_destroy_coverage (cvg);
	  return 0;
      }

    if (rl2_load_raw_tiles_into_dbms
	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
	 tile_callback, &info, 1) != RL2_OK)
      {
	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
		   info.coverage);
	  return 0;
      }

    rl2_destroy_coverage (cvg);
    rl2_destroy_pixel (no_data);
    return 1;
}

static int
test_uint8_rgb (sqlite3 * handle)
{
/* testing UINT8 RGB */
    struct tile_info info;
    rl2CoveragePtr cvg;

    info.sample = RL2_SAMPLE_UINT8;
    info.pixel = RL2_PIXEL_RGB;
    info.num_bands = 3;
    info.srid = 4326;
    info.coverage = "UINT8_RGB";
    info.tile_w = 512;
    info.tile_h = 512;

    rl2PixelPtr no_data =
	default_nodata (info.sample, info.pixel, info.num_bands);
    if (rl2_create_dbms_coverage
	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
	 RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1,
	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
      {
	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
	  return 0;
      }

    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
    if (cvg == NULL)
      {
	  rl2_destroy_coverage (cvg);
	  return 0;
      }

    if (rl2_load_raw_tiles_into_dbms
	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
	 tile_callback, &info, 1) != RL2_OK)
      {
	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
		   info.coverage);
	  return 0;
      }

    rl2_destroy_coverage (cvg);
    rl2_destroy_pixel (no_data);
    return 1;
}

static int
test_int16_grid (sqlite3 * handle)
{
/* testing INT8 DATAGRID */
    struct tile_info info;
    rl2CoveragePtr cvg;

    info.sample = RL2_SAMPLE_INT16;
    info.pixel = RL2_PIXEL_DATAGRID;
    info.num_bands = 1;
    info.srid = 4326;
    info.coverage = "INT16_GRID";
    info.tile_w = 512;
    info.tile_h = 512;

    rl2PixelPtr no_data =
	default_nodata (info.sample, info.pixel, info.num_bands);
    if (rl2_create_dbms_coverage
	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
	 RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1,
	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
      {
	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
	  return 0;
      }

    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
    if (cvg == NULL)
      {
	  rl2_destroy_coverage (cvg);
	  return 0;
      }

    if (rl2_load_raw_tiles_into_dbms
	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
	 tile_callback, &info, 1) != RL2_OK)
      {
	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
		   info.coverage);
	  return 0;
      }

    rl2_destroy_coverage (cvg);
    rl2_destroy_pixel (no_data);
    return 1;
}

static int
test_double_grid (sqlite3 * handle)
{
/* testing DOUBLE DATAGRID */
    struct tile_info info;
    rl2CoveragePtr cvg;

    info.sample = RL2_SAMPLE_DOUBLE;
    info.pixel = RL2_PIXEL_DATAGRID;
    info.num_bands = 1;
    info.srid = 4326;
    info.coverage = "DOUBLE_GRID";
    info.tile_w = 512;
    info.tile_h = 512;

    rl2PixelPtr no_data =
	default_nodata (info.sample, info.pixel, info.num_bands);
    if (rl2_create_dbms_coverage
	(handle, info.coverage, info.sample, info.pixel, info.num_bands,
	 RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1,
	 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK)
      {
	  fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage);
	  return 0;
      }

    cvg = rl2_create_coverage_from_dbms (handle, info.coverage);
    if (cvg == NULL)
      {
	  rl2_destroy_coverage (cvg);
	  return 0;
      }

    if (rl2_load_raw_tiles_into_dbms
	(handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90,
	 tile_callback, &info, 1) != RL2_OK)
      {
	  fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n",
		   info.coverage);
	  return 0;
      }

    rl2_destroy_coverage (cvg);
    rl2_destroy_pixel (no_data);
    return 1;
}

int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle = NULL;
    char *err_msg = NULL;
    void *cache = spatialite_alloc_connection ();
    void *priv_data = rl2_alloc_private ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */
    ret =
	sqlite3_open_v2 ("callback.sqlite", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  return -1;
      }
    spatialite_init_ex (handle, cache, 0);
    rl2_init (handle, priv_data, 0);

/* the complete test is handled as an unique SQL Transaction */
    ret = sqlite3_exec (handle, "BEGIN", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "BEGIN TRANSACTION error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -2;
      }

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata()", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -3;
      }
    ret =
	sqlite3_exec (handle, "SELECT CreateRasterCoveragesTable()", NULL,
		      NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CreateRasterCoveragesTable() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -4;
      }

    if (!test_uint8_gray (handle))
	return -5;

    if (!test_uint8_rgb (handle))
	return -6;

    if (!test_int16_grid (handle))
	return -7;

    if (!test_double_grid (handle))
	return -8;

/* committing the SQL Transaction */
    ret = sqlite3_exec (handle, "COMMIT", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "COMMIT TRANSACTION error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -9;
      }

    sqlite3_close (handle);
    spatialite_cleanup_ex (cache);
    rl2_cleanup_private (priv_data);
    spatialite_shutdown ();
    fprintf (stderr, "******** endok\n");
    return 0;
}

Changes to tools/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18










19
20
21
22
23
24
25
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
...
165
166
167
168
169
170
171

172
173
174
175
176
177
178
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
674
675
676
677
678
679
680


681
682
683
684
685
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2013 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'










am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = rl2sniff$(EXEEXT) rl2tool$(EXEEXT) wmslite$(EXEEXT)
subdir = tools
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
	$(top_srcdir)/depcomp
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)

mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_rl2sniff_OBJECTS = rl2sniff.$(OBJEXT)
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags

DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu tools/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-exec install-exec-am install-html install-html-am \
	install-info install-info-am install-man install-pdf \
	install-pdf-am install-ps install-ps-am install-strip \
	installcheck installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags tags-am uninstall uninstall-am uninstall-binPROGRAMS




# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
|


|













|
>
>
>
>
>
>
>
>
>
>







 







<
<







>







 







>







 







<







 







>
>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
363
364
365
366
367
368
369

370
371
372
373
374
375
376
...
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2014 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
................................................................................
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = rl2sniff$(EXEEXT) rl2tool$(EXEEXT) wmslite$(EXEEXT)
subdir = tools


ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
	$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_rl2sniff_OBJECTS = rl2sniff.$(OBJEXT)
................................................................................
am__define_uniq_tagged_files = \
  list='$(am__tagged_files)'; \
  unique=`for i in $$list; do \
    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
  done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
................................................................................
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu tools/Makefile

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
................................................................................
	install-exec install-exec-am install-html install-html-am \
	install-info install-info-am install-man install-pdf \
	install-pdf-am install-ps install-ps-am install-strip \
	installcheck installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags tags-am uninstall uninstall-am uninstall-binPROGRAMS

.PRECIOUS: Makefile


# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Changes to tools/rl2sniff.c.

730
731
732
733
734
735
736

737
738
739
740
741
742
743
...
897
898
899
900
901
902
903













904
905
906
907
908
909
910
    double cy;
    double minX;
    double minY;
    double maxX;
    double maxY;
    double x_res;
    double y_res;

    GTIFDefn definition;
    char *md5 = NULL;
    TIFF *in = (TIFF *) 0;
    GTIF *gtif = (GTIF *) 0;

/* suppressing TIFF messages */
    TIFFSetErrorHandler (NULL);
................................................................................
    GTIFImageToPCS (gtif, &cx, &cy);
    maxX = cx;

/* computing the pixel resolution */
    x_res = (maxX - minX) / (double) width;
    y_res = (maxY - minY) / (double) height;
    is_geotiff = 1;













    goto print;

  recover:
    is_geotiff =
	recover_incomplete_geotiff (in, width, height, &minX, &minY, &maxX,
				    &maxY, &x_res, &y_res);








>







 







>
>
>
>
>
>
>
>
>
>
>
>
>







730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
...
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
    double cy;
    double minX;
    double minY;
    double maxX;
    double maxY;
    double x_res;
    double y_res;
    short pixel_mode = RasterPixelIsArea;
    GTIFDefn definition;
    char *md5 = NULL;
    TIFF *in = (TIFF *) 0;
    GTIF *gtif = (GTIF *) 0;

/* suppressing TIFF messages */
    TIFFSetErrorHandler (NULL);
................................................................................
    GTIFImageToPCS (gtif, &cx, &cy);
    maxX = cx;

/* computing the pixel resolution */
    x_res = (maxX - minX) / (double) width;
    y_res = (maxY - minY) / (double) height;
    is_geotiff = 1;

/* retrieving GTRasterTypeGeoKey */
    if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1))
	pixel_mode = RasterPixelIsArea;
    if (pixel_mode == RasterPixelIsPoint)
      {
	  /* adjusting the BBOX */
	  minX -= x_res / 2.0;
	  minY -= y_res / 2.0;
	  maxX += x_res / 2.0;
	  maxY += y_res / 2.0;

      }
    goto print;

  recover:
    is_geotiff =
	recover_incomplete_geotiff (in, width, height, &minX, &minY, &maxX,
				    &maxY, &x_res, &y_res);

Changes to tools/rl2tool.c.

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
....
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744

    sql =
	"SELECT coverage_name, title, abstract, sample_type, pixel_type, "
	"num_bands, compression, quality, tile_width, tile_height, "
	"horz_resolution, vert_resolution, srid, auth_name, auth_srid, "
	"ref_sys_name, extent_minx, extent_miny, extent_maxx, extent_maxy, "
	"nodata_pixel, palette, statistics, red_band_index, green_band_index, "
	"blue_band_index, nir_band_index, eneble_auto_ndvi "
	"FROM raster_coverages_ref_sys ORDER BY coverage_name";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	goto stop;

    while (1)
      {
................................................................................
			    printf
				("       NIR band index: *** undefined ***\n");
			}
		  }
		if (palette != NULL)
		  {
		      /* printing an eventual Palette */
		      unsigned char i;
		      unsigned short num_entries;
		      unsigned char *red = NULL;
		      unsigned char *green = NULL;
		      unsigned char *blue = NULL;
		      rl2_get_palette_colors (palette, &num_entries, &red,
					      &green, &blue);
		      for (i = 0; i < num_entries; i++)







|







 







|







1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
....
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744

    sql =
	"SELECT coverage_name, title, abstract, sample_type, pixel_type, "
	"num_bands, compression, quality, tile_width, tile_height, "
	"horz_resolution, vert_resolution, srid, auth_name, auth_srid, "
	"ref_sys_name, extent_minx, extent_miny, extent_maxx, extent_maxy, "
	"nodata_pixel, palette, statistics, red_band_index, green_band_index, "
	"blue_band_index, nir_band_index, enable_auto_ndvi "
	"FROM raster_coverages_ref_sys ORDER BY coverage_name";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	goto stop;

    while (1)
      {
................................................................................
			    printf
				("       NIR band index: *** undefined ***\n");
			}
		  }
		if (palette != NULL)
		  {
		      /* printing an eventual Palette */
		      unsigned short i;
		      unsigned short num_entries;
		      unsigned char *red = NULL;
		      unsigned char *green = NULL;
		      unsigned char *blue = NULL;
		      rl2_get_palette_colors (palette, &num_entries, &red,
					      &green, &blue);
		      for (i = 0; i < num_entries; i++)

Changes to tools/wmslite.c.

47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
...
305
306
307
308
309
310
311

312
313
314
315
316
317
318
....
2566
2567
2568
2569
2570
2571
2572
2573

2574
2575
2576
2577
2578
2579
2580
....
2593
2594
2595
2596
2597
2598
2599

2600
2601
2602
2603





2604
2605
2606
2607
2608
2609
2610
....
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
....
2643
2644
2645
2646
2647
2648
2649

2650
2651




2652
2653
2654
2655
2656
2657
2658
2659
2660
....
2682
2683
2684
2685
2686
2687
2688

2689
2690
2691





2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704

2705
2706




2707
2708
2709
2710
2711
2712
2713
2714
2715
....
3193
3194
3195
3196
3197
3198
3199

3200


3201
3202
3203
3204
3205
3206
3207
....
3399
3400
3401
3402
3403
3404
3405
3406

3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
....
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
....
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572

3573
3574
3575
3576
3577
3578
3579
3580
....
3607
3608
3609
3610
3611
3612
3613

3614
3615
3616
3617
3618
3619
3620
....
3692
3693
3694
3695
3696
3697
3698

3699
3700
3701
3702
3703
3704
3705
....
3761
3762
3763
3764
3765
3766
3767
3768

3769
3770
3771
3772
3773
3774
3775
....
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
....
3810
3811
3812
3813
3814
3815
3816
3817

3818
3819
3820
3821
3822
3823
3824
....
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
....
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
....
4746
4747
4748
4749
4750
4751
4752


4753
4754
4755
4756
4757
4758
4759
....
4768
4769
4770
4771
4772
4773
4774

4775
4776
4777
4778
4779
4780
4781
....
4805
4806
4807
4808
4809
4810
4811



4812
4813
4814
4815
4816
4817
4818
....
4830
4831
4832
4833
4834
4835
4836






4837
4838
4839
4840
4841
4842
4843
....
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
....
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
....
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
#endif

#include <rasterlite2/rasterlite2.h>
#include <spatialite.h>

#define ARG_NONE		0
#define ARG_DB_PATH		1

#define ARG_IP_PORT		2
#define ARG_MAX_THREADS		3
#define ARG_CACHE_SIZE		4

#define WMS_ILLEGAL_REQUEST	0
#define WMS_GET_CAPABILITIES	1
#define WMS_GET_MAP		2

#define WMS_UNKNOWN		-1
#define WMS_TRANSPARENT		10
................................................................................
    unsigned char blue;
};

struct http_request
{
/* a struct wrapping an HTTP request */
    unsigned int id;		/* request ID */

    int port_no;
#ifdef _WIN32
    SOCKET socket;		/* Socket on which to receive data */
#else
    int socket;			/* Socket on which to receive data */
#endif
    struct wms_list *list;
................................................................................
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
    gaiaAppendToOutBuffer (xml_response, xml_text.Buffer);
    gaiaOutBufferReset (&xml_text);
}

static void
build_http_error (int http_status, gaiaOutBufferPtr xml_response, int port_no)

{
/* preparing an HTTP error */
    char *dummy;
    gaiaOutBuffer http_text;
    gaiaOutBufferInitialize (&http_text);
    gaiaAppendToOutBuffer (&http_text,
			   "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n");
................................................................................
				 "HTTP/1.1 500 Internal Server Error\r\n");
	  gaiaAppendToOutBuffer (&http_text,
				 "<title>500 Internal Server Error</title>\r\n");
	  gaiaAppendToOutBuffer (&http_text, "</head><body>\r\n");
	  gaiaAppendToOutBuffer (&http_text,
				 "<h1>Internal Server Error</h1>\n");
      }

    dummy =
	sqlite3_mprintf
	("<address>WmsLite/%s [%s] at localhost (127.0.0.1) Port %d</address>\r\n",
	 rl2_version (), rl2_target_cpu (), port_no);





    gaiaAppendToOutBuffer (&http_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&http_text, "</body></html>\r\n");
    gaiaAppendToOutBuffer (&http_text, "");
    dummy = get_current_timestamp ();
    gaiaAppendToOutBuffer (xml_response, dummy);
    sqlite3_free (dummy);
................................................................................
    gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
    gaiaAppendToOutBuffer (xml_response, http_text.Buffer);
    gaiaOutBufferReset (&http_text);
}

static void
build_get_capabilities (struct wms_list *list, char **cached, int *cached_len,
			int port_no)
{
/* preparing the WMS GetCapabilities XML document */
    struct wms_layer *lyr;
    struct wms_group *grp;
    struct wms_style *style;
    struct wms_alt_srid *alt_srid;
    struct wms_keyword *keyword;
................................................................................
			   "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd\">\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Service>\r\n<Name>WMS</Name>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Title>WmsLite test server</Title>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Abstract>A simple light-weight WMS server for testing RasterLite2 Coverages.</Abstract>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<KeywordList>\r\n<Keyword>maps</Keyword>\r\n</KeywordList>\r\n");

    dummy =
	sqlite3_mprintf




	("<OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",
	 port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<ContactInformation>\r\n<ContactPersonPrimary>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
................................................................................
    gaiaAppendToOutBuffer (&xml_text, "<MaxWidth>5000</MaxWidth>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<MaxHeight>5000</MaxHeight>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "</Service>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Capability>\r\n<Request>\r\n<GetCapabilities>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Format>text/xml</Format>\r\n<DCPType>\r\n<HTTP>\r\n");

    dummy =
	sqlite3_mprintf
	("<Get><OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",





	 port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "</HTTP>\r\n</DCPType>\r\n</GetCapabilities>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<GetMap>\r\n<Format>image/png</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>image/jpeg</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>application/x-pdf</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>image/tiff</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<DCPType>\r\n<HTTP>\r\n<Get>");

    dummy =
	sqlite3_mprintf




	("<OnlineResource xlink:href=\"http://127.0.0.1:%d/wmslite?\" ",
	 port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "</HTTP>\r\n</DCPType>\r\n</GetMap>\r\n</Request>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
................................................................................
	sqlite3_bind_text (stmt, 9, "image/png", strlen ("image/png"),
			   SQLITE_TRANSIENT);
    if (args->has_bgcolor)
	sprintf (bgcolor, "#%02x%02x%02x", args->red, args->green, args->blue);
    else
	strcpy (bgcolor, "#ffffff");
    sqlite3_bind_text (stmt, 10, bgcolor, strlen (bgcolor), SQLITE_TRANSIENT);

    sqlite3_bind_int (stmt, 11, args->transparent);


    if (args->format == RL2_OUTPUT_FORMAT_JPEG)
	sqlite3_bind_int (stmt, 12, 80);
    else
	sqlite3_bind_int (stmt, 12, 100);
    while (1)
      {
	  ret = sqlite3_step (stmt);
................................................................................
	  wms_get_capabilities (req->socket, req->cached_capabilities,
				req->cached_capabilities_len, req->log);
      }
    if (args->request_type == WMS_GET_MAP)
      {
	  /* preparing the WMS GetMap payload */
	  args->db_handle = req->conn->handle;
	  args->stmt_get_map = req->conn->stmt_get_map;

	  log_get_map_1 (req->log, timestamp, http_status, method, url, args);
	  wms_get_map (args, req->socket, req->log);
      }
    goto end_request;

/* preparing an HTTP error code */
  http_error:
    gaiaOutBufferInitialize (&xml_response);
    build_http_error (http_status, &xml_response, req->port_no);
    curr = 0;
    while (1)
      {
	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
	  if (rd == 0)
	      break;
	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
	  wms_get_map (args, req->socket, req->log);
      }
    goto end_request;

/* preparing an HTTP error code */
  http_error:
    gaiaOutBufferInitialize (&xml_response);
    build_http_error (http_status, &xml_response, req->port_no);
    curr = 0;
    while (1)
      {
	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
	  if (rd == 0)
	      break;
	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
    req->conn->status = CONNECTION_AVAILABLE;
    free (req);
    pthread_exit (NULL);
}
#endif

static void
do_accept_loop (struct neutral_socket *skt, struct wms_list *list, int port_no,
		sqlite3 * db_handle, sqlite3_stmt * stmt_log,
		struct connections_pool *pool, struct server_log *log,

		char *cached_capab, int cached_capab_len)
{
/* implementing the ACCEPT loop */
    unsigned int id = 0;
    struct read_connection *conn;
    int ic;
    time_t diff;
    time_t now;
................................................................................
		      WSACleanup ();
		      fprintf (stderr, "error from accept()\n");
		      return;
		  }
	    }
	  req = malloc (sizeof (struct http_request));
	  req->id = id++;

	  req->port_no = port_no;
	  req->socket = client;
	  req->list = list;
	  req->cached_capabilities = cached_capab;
	  req->cached_capabilities_len = cached_capab_len;
	  while (1)
	    {
................................................................................
	    {
		close (socket);
		fprintf (stderr, "error from accept()\n");
		return;
	    }
	  req = malloc (sizeof (struct http_request));
	  req->id = id++;

	  req->port_no = port_no;
	  req->socket = client;
	  req->list = list;
	  req->cached_capabilities = cached_capab;
	  req->cached_capabilities_len = cached_capab_len;
	  while (1)
	    {
................................................................................
	  pthread_create (&thread_id, NULL, berkeley_http_request,
			  (void *) req);
      }
#endif
}

static int
do_start_http (int port_no, struct neutral_socket *srv_skt, int max_threads)

{
/* starting the HTTP server */
#ifdef _WIN32
/* Winsockets */
    WSADATA wd;
    SOCKET skt = INVALID_SOCKET;
    SOCKADDR_IN addr;
................................................................................
    if (skt == INVALID_SOCKET)
      {
	  fprintf (stderr, "unable to create a socket\n");
	  return 0;
      }
    addr.sin_family = AF_INET;
    addr.sin_port = htons (port_no);
    addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
    if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
      {
	  fprintf (stderr, "unable to bind the socket\n");
	  closesocket (skt);
	  return 0;
      }
    if (listen (skt, SOMAXCONN) == SOCKET_ERROR)
................................................................................
    if (skt == -1)
      {
	  fprintf (stderr, "unable to create a socket\n");
	  return 0;
      }
    addr.sin_family = AF_INET;
    addr.sin_port = htons (port_no);
    addr.sin_addr.s_addr = htonl (INADDR_ANY);

    if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == -1)
      {
	  fprintf (stderr, "unable to bind the socket\n");
	  close (skt);
	  return 0;
      }
    if (listen (skt, SOMAXCONN) == -1)
................................................................................
static void
get_raster_styles (sqlite3 * handle, struct wms_list *list)
{
/* retrieving all declared Raster Styles */
    int ret;
    sqlite3_stmt *stmt;
    const char *sql = "SELECT coverage_name, name, title, abstract "
	"FROM SE_raster_styled_layers_view ORDER BY coverage_name, style_id";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return;
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
................................................................................
static void
get_vector_styles (sqlite3 * handle, struct wms_list *list)
{
/* retrieving all declared Vector Styles */
    int ret;
    sqlite3_stmt *stmt;
    const char *sql = "SELECT coverage_name, name, title, abstract "
	"FROM SE_vector_styled_layers_view ORDER BY coverage_name, style_id";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return;
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
................................................................................
{
/* printing the argument list */
    fprintf (stderr, "\n\nusage: wmslite ARGLIST ]\n");
    fprintf (stderr,
	     "==============================================================\n");
    fprintf (stderr, "-db or --db-path      pathname  RasterLite2 DB path\n");
    fprintf (stderr,


	     "-p or --ip-port       number    IP port number [default: 8080]\n\n");
    fprintf (stderr,
	     "-mt or --max-threads   num      max number of concurrent threads\n");
    fprintf (stderr,
	     "-cs or --cache-size    num      DB cache size (how many pages)\n");
    fprintf (stderr,
	     "-dbg or --debug                 verbose debugginh mode\n");
................................................................................
    sqlite3_stmt *stmt_log = NULL;
    const char *sql;
    int ret;
    int i;
    int error = 0;
    int next_arg = ARG_NONE;
    const char *db_path = NULL;

    int port_no = 8080;
    int cache_size = 0;
    void *cache;
    void *priv_data;
    struct wms_list *list = NULL;
    struct connections_pool *pool;
    struct server_log *log;
................................................................................
	  if (next_arg != ARG_NONE)
	    {
		switch (next_arg)
		  {
		  case ARG_DB_PATH:
		      db_path = argv[i];
		      break;



		  case ARG_IP_PORT:
		      port_no = atoi (argv[i]);
		      break;
		  case ARG_CACHE_SIZE:
		      cache_size = atoi (argv[i]);
		      break;
		  case ARG_MAX_THREADS:
................................................................................
		return -1;
	    }
	  if (strcmp (argv[i], "-db") == 0
	      || strcasecmp (argv[i], "--db-path") == 0)
	    {
		next_arg = ARG_DB_PATH;
		continue;






	    }
	  if (strcmp (argv[i], "-p") == 0
	      || strcasecmp (argv[i], "--ip-port") == 0)
	    {
		next_arg = ARG_IP_PORT;
		continue;
	    }
................................................................................
    get_raster_alt_srids (handle, list);
    get_vector_alt_srids (handle, list);
    get_raster_keywords (handle, list);
    get_vector_keywords (handle, list);
    glob.list = list;
    complete_layer_config (handle, list);
    build_get_capabilities (list, &cached_capabilities,
			    &cached_capabilities_len, port_no);
    glob.cached_capabilities = cached_capabilities;

/* creating the read connections pool */
    pool = alloc_connections_pool (db_path, max_threads);
    if (pool == NULL)
      {
	  fprintf (stderr, "ERROR: unable to initialize a connections pool\n");
................................................................................
      {
	  fprintf (stderr, "ERROR: unable to initialize the server log\n");
	  goto stop;
      }
    glob.log = log;

/* starting the HTTP server */
    if (!do_start_http (port_no, &skt_ptr, max_threads))
	goto stop;

/* starting the logging facility */
    sql = "CREATE TABLE IF NOT EXISTS wms_server_log (\n"
	"\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n"
	"\ttimestamp TEXT NOT NULL,\n"
	"\tclient_ip_addr TEXT NOT NULL,\n"
................................................................................
      {
	  printf ("INSERT INTO LOG error: %s\n", sqlite3_errmsg (handle));
	  goto stop;
      }
    glob.stmt_log = stmt_log;

/* looping on requests */
    do_accept_loop (&skt_ptr, list, port_no, handle, stmt_log, pool, log,
		    cached_capabilities, cached_capabilities_len);

  stop:
    destroy_wms_list (list);
    list = NULL;
    glob.list = NULL;
    clean_shutdown ();
    return 0;
}







>
|
|
|







 







>







 







|
>







 







>
|
|
|
|
>
>
>
>
>







 







|







 







>
|
|
>
>
>
>
|
|







 







>
|
|
|
>
>
>
>
>
|












>
|
|
>
>
>
>
|
|







 







>
|
>
>







 







|
>








|







 







|







 







|
|
|
>
|







 







>







 







>







 







|
>







 







|







 







|
>







 







|







 







|







 







>
>







 







>







 







>
>
>







 







>
>
>
>
>
>







 







|







 







|







 







|
|








47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
....
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
....
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
....
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
....
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
....
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
....
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
....
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
....
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
....
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
....
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
....
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
....
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
....
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
....
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
....
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
....
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
....
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
....
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
....
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
....
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
....
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
....
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
....
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
#endif

#include <rasterlite2/rasterlite2.h>
#include <spatialite.h>

#define ARG_NONE		0
#define ARG_DB_PATH		1
#define ARG_IP_ADDR		2
#define ARG_IP_PORT		3
#define ARG_MAX_THREADS		4
#define ARG_CACHE_SIZE		5

#define WMS_ILLEGAL_REQUEST	0
#define WMS_GET_CAPABILITIES	1
#define WMS_GET_MAP		2

#define WMS_UNKNOWN		-1
#define WMS_TRANSPARENT		10
................................................................................
    unsigned char blue;
};

struct http_request
{
/* a struct wrapping an HTTP request */
    unsigned int id;		/* request ID */
    const char *ip_addr;
    int port_no;
#ifdef _WIN32
    SOCKET socket;		/* Socket on which to receive data */
#else
    int socket;			/* Socket on which to receive data */
#endif
    struct wms_list *list;
................................................................................
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
    gaiaAppendToOutBuffer (xml_response, xml_text.Buffer);
    gaiaOutBufferReset (&xml_text);
}

static void
build_http_error (int http_status, gaiaOutBufferPtr xml_response,
		  const char *ip_addr, int port_no)
{
/* preparing an HTTP error */
    char *dummy;
    gaiaOutBuffer http_text;
    gaiaOutBufferInitialize (&http_text);
    gaiaAppendToOutBuffer (&http_text,
			   "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n");
................................................................................
				 "HTTP/1.1 500 Internal Server Error\r\n");
	  gaiaAppendToOutBuffer (&http_text,
				 "<title>500 Internal Server Error</title>\r\n");
	  gaiaAppendToOutBuffer (&http_text, "</head><body>\r\n");
	  gaiaAppendToOutBuffer (&http_text,
				 "<h1>Internal Server Error</h1>\n");
      }
    if (strcmp (ip_addr, "127.0.0.1") == 0)
	dummy =
	    sqlite3_mprintf
	    ("<address>WmsLite/%s [%s] at localhost (127.0.0.1) Port %d</address>\r\n",
	     rl2_version (), rl2_target_cpu (), port_no);
    else
	dummy =
	    sqlite3_mprintf
	    ("<address>WmsLite/%s [%s] at IP-addr %s Port %d</address>\r\n",
	     rl2_version (), rl2_target_cpu (), ip_addr, port_no);
    gaiaAppendToOutBuffer (&http_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&http_text, "</body></html>\r\n");
    gaiaAppendToOutBuffer (&http_text, "");
    dummy = get_current_timestamp ();
    gaiaAppendToOutBuffer (xml_response, dummy);
    sqlite3_free (dummy);
................................................................................
    gaiaAppendToOutBuffer (xml_response, "Connection: close\r\n\r\n");
    gaiaAppendToOutBuffer (xml_response, http_text.Buffer);
    gaiaOutBufferReset (&http_text);
}

static void
build_get_capabilities (struct wms_list *list, char **cached, int *cached_len,
			const char *ip_addr, int port_no)
{
/* preparing the WMS GetCapabilities XML document */
    struct wms_layer *lyr;
    struct wms_group *grp;
    struct wms_style *style;
    struct wms_alt_srid *alt_srid;
    struct wms_keyword *keyword;
................................................................................
			   "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd\">\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Service>\r\n<Name>WMS</Name>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Title>WmsLite test server</Title>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Abstract>A simple light-weight WMS server for testing RasterLite2 Coverages.</Abstract>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<KeywordList>\r\n<Keyword>maps</Keyword>\r\n</KeywordList>\r\n");
    if (port_no == 80)
	dummy =
	    sqlite3_mprintf
	    ("<OnlineResource xlink:href=\"http://%s/wmslite?\" ", ip_addr);
    else
	dummy =
	    sqlite3_mprintf
	    ("<OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
	     ip_addr, port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<ContactInformation>\r\n<ContactPersonPrimary>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
................................................................................
    gaiaAppendToOutBuffer (&xml_text, "<MaxWidth>5000</MaxWidth>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<MaxHeight>5000</MaxHeight>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "</Service>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Capability>\r\n<Request>\r\n<GetCapabilities>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<Format>text/xml</Format>\r\n<DCPType>\r\n<HTTP>\r\n");
    if (port_no == 80)
	dummy =
	    sqlite3_mprintf
	    ("<Get><OnlineResource xlink:href=\"http://%s/wmslite?\" ",
	     ip_addr);
    else
	dummy =
	    sqlite3_mprintf
	    ("<Get><OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
	     ip_addr, port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "</HTTP>\r\n</DCPType>\r\n</GetCapabilities>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "<GetMap>\r\n<Format>image/png</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>image/jpeg</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>application/x-pdf</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<Format>image/tiff</Format>\r\n");
    gaiaAppendToOutBuffer (&xml_text, "<DCPType>\r\n<HTTP>\r\n<Get>");
    if (port_no == 80)
	dummy =
	    sqlite3_mprintf
	    ("<OnlineResource xlink:href=\"http://%s/wmslite?\" ", ip_addr);
    else
	dummy =
	    sqlite3_mprintf
	    ("<OnlineResource xlink:href=\"http://%s:%d/wmslite?\" ",
	     ip_addr, port_no);
    gaiaAppendToOutBuffer (&xml_text, dummy);
    sqlite3_free (dummy);
    gaiaAppendToOutBuffer (&xml_text,
			   "xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Get>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
			   "</HTTP>\r\n</DCPType>\r\n</GetMap>\r\n</Request>\r\n");
    gaiaAppendToOutBuffer (&xml_text,
................................................................................
	sqlite3_bind_text (stmt, 9, "image/png", strlen ("image/png"),
			   SQLITE_TRANSIENT);
    if (args->has_bgcolor)
	sprintf (bgcolor, "#%02x%02x%02x", args->red, args->green, args->blue);
    else
	strcpy (bgcolor, "#ffffff");
    sqlite3_bind_text (stmt, 10, bgcolor, strlen (bgcolor), SQLITE_TRANSIENT);
    if (args->transparent == WMS_OPAQUE)
	sqlite3_bind_int (stmt, 11, 0);
    else
	sqlite3_bind_int (stmt, 11, 1);
    if (args->format == RL2_OUTPUT_FORMAT_JPEG)
	sqlite3_bind_int (stmt, 12, 80);
    else
	sqlite3_bind_int (stmt, 12, 100);
    while (1)
      {
	  ret = sqlite3_step (stmt);
................................................................................
	  wms_get_capabilities (req->socket, req->cached_capabilities,
				req->cached_capabilities_len, req->log);
      }
    if (args->request_type == WMS_GET_MAP)
      {
	  /* preparing the WMS GetMap payload */
	  args->db_handle = req->conn->handle;
	  args->stmt_get_map_raster = req->conn->stmt_get_map_raster;
	  args->stmt_get_map_vector = req->conn->stmt_get_map_vector;
	  log_get_map_1 (req->log, timestamp, http_status, method, url, args);
	  wms_get_map (args, req->socket, req->log);
      }
    goto end_request;

/* preparing an HTTP error code */
  http_error:
    gaiaOutBufferInitialize (&xml_response);
    build_http_error (http_status, &xml_response, req->ip_addr, req->port_no);
    curr = 0;
    while (1)
      {
	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
	  if (rd == 0)
	      break;
	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
	  wms_get_map (args, req->socket, req->log);
      }
    goto end_request;

/* preparing an HTTP error code */
  http_error:
    gaiaOutBufferInitialize (&xml_response);
    build_http_error (http_status, &xml_response, req->ip_addr, req->port_no);
    curr = 0;
    while (1)
      {
	  rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ);
	  if (rd == 0)
	      break;
	  send (req->socket, xml_response.Buffer + curr, rd, 0);
................................................................................
    req->conn->status = CONNECTION_AVAILABLE;
    free (req);
    pthread_exit (NULL);
}
#endif

static void
do_accept_loop (struct neutral_socket *skt, struct wms_list *list,
		const char *xip_addr, int port_no, sqlite3 * db_handle,
		sqlite3_stmt * stmt_log, struct connections_pool *pool,
		struct server_log *log, char *cached_capab,
		int cached_capab_len)
{
/* implementing the ACCEPT loop */
    unsigned int id = 0;
    struct read_connection *conn;
    int ic;
    time_t diff;
    time_t now;
................................................................................
		      WSACleanup ();
		      fprintf (stderr, "error from accept()\n");
		      return;
		  }
	    }
	  req = malloc (sizeof (struct http_request));
	  req->id = id++;
	  req->ip_addr = xip_addr;
	  req->port_no = port_no;
	  req->socket = client;
	  req->list = list;
	  req->cached_capabilities = cached_capab;
	  req->cached_capabilities_len = cached_capab_len;
	  while (1)
	    {
................................................................................
	    {
		close (socket);
		fprintf (stderr, "error from accept()\n");
		return;
	    }
	  req = malloc (sizeof (struct http_request));
	  req->id = id++;
	  req->ip_addr = xip_addr;
	  req->port_no = port_no;
	  req->socket = client;
	  req->list = list;
	  req->cached_capabilities = cached_capab;
	  req->cached_capabilities_len = cached_capab_len;
	  while (1)
	    {
................................................................................
	  pthread_create (&thread_id, NULL, berkeley_http_request,
			  (void *) req);
      }
#endif
}

static int
do_start_http (const char *ip_addr, int port_no, struct neutral_socket *srv_skt,
	       int max_threads)
{
/* starting the HTTP server */
#ifdef _WIN32
/* Winsockets */
    WSADATA wd;
    SOCKET skt = INVALID_SOCKET;
    SOCKADDR_IN addr;
................................................................................
    if (skt == INVALID_SOCKET)
      {
	  fprintf (stderr, "unable to create a socket\n");
	  return 0;
      }
    addr.sin_family = AF_INET;
    addr.sin_port = htons (port_no);
    addr.sin_addr.s_addr = inet_addr (ip_addr);
    if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
      {
	  fprintf (stderr, "unable to bind the socket\n");
	  closesocket (skt);
	  return 0;
      }
    if (listen (skt, SOMAXCONN) == SOCKET_ERROR)
................................................................................
    if (skt == -1)
      {
	  fprintf (stderr, "unable to create a socket\n");
	  return 0;
      }
    addr.sin_family = AF_INET;
    addr.sin_port = htons (port_no);
    //addr.sin_addr.s_addr = htonl (INADDR_ANY);
    addr.sin_addr.s_addr = inet_addr (ip_addr);
    if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == -1)
      {
	  fprintf (stderr, "unable to bind the socket\n");
	  close (skt);
	  return 0;
      }
    if (listen (skt, SOMAXCONN) == -1)
................................................................................
static void
get_raster_styles (sqlite3 * handle, struct wms_list *list)
{
/* retrieving all declared Raster Styles */
    int ret;
    sqlite3_stmt *stmt;
    const char *sql = "SELECT coverage_name, name, title, abstract "
	"FROM SE_raster_styled_layers_view ORDER BY coverage_name, name";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return;
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
................................................................................
static void
get_vector_styles (sqlite3 * handle, struct wms_list *list)
{
/* retrieving all declared Vector Styles */
    int ret;
    sqlite3_stmt *stmt;
    const char *sql = "SELECT coverage_name, name, title, abstract "
	"FROM SE_vector_styled_layers_view ORDER BY coverage_name, name";
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
	return;
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
................................................................................
{
/* printing the argument list */
    fprintf (stderr, "\n\nusage: wmslite ARGLIST ]\n");
    fprintf (stderr,
	     "==============================================================\n");
    fprintf (stderr, "-db or --db-path      pathname  RasterLite2 DB path\n");
    fprintf (stderr,
	     "-ip or --ip-addr    ip-address  IP address [default: 127.0.0.1]\n\n");
    fprintf (stderr,
	     "-p or --ip-port       number    IP port number [default: 8080]\n\n");
    fprintf (stderr,
	     "-mt or --max-threads   num      max number of concurrent threads\n");
    fprintf (stderr,
	     "-cs or --cache-size    num      DB cache size (how many pages)\n");
    fprintf (stderr,
	     "-dbg or --debug                 verbose debugginh mode\n");
................................................................................
    sqlite3_stmt *stmt_log = NULL;
    const char *sql;
    int ret;
    int i;
    int error = 0;
    int next_arg = ARG_NONE;
    const char *db_path = NULL;
    const char *ip_addr = "127.0.0.1";
    int port_no = 8080;
    int cache_size = 0;
    void *cache;
    void *priv_data;
    struct wms_list *list = NULL;
    struct connections_pool *pool;
    struct server_log *log;
................................................................................
	  if (next_arg != ARG_NONE)
	    {
		switch (next_arg)
		  {
		  case ARG_DB_PATH:
		      db_path = argv[i];
		      break;
		  case ARG_IP_ADDR:
		      ip_addr = argv[i];
		      break;
		  case ARG_IP_PORT:
		      port_no = atoi (argv[i]);
		      break;
		  case ARG_CACHE_SIZE:
		      cache_size = atoi (argv[i]);
		      break;
		  case ARG_MAX_THREADS:
................................................................................
		return -1;
	    }
	  if (strcmp (argv[i], "-db") == 0
	      || strcasecmp (argv[i], "--db-path") == 0)
	    {
		next_arg = ARG_DB_PATH;
		continue;
	    }
	  if (strcmp (argv[i], "-ip") == 0
	      || strcasecmp (argv[i], "--ip-addr") == 0)
	    {
		next_arg = ARG_IP_ADDR;
		continue;
	    }
	  if (strcmp (argv[i], "-p") == 0
	      || strcasecmp (argv[i], "--ip-port") == 0)
	    {
		next_arg = ARG_IP_PORT;
		continue;
	    }
................................................................................
    get_raster_alt_srids (handle, list);
    get_vector_alt_srids (handle, list);
    get_raster_keywords (handle, list);
    get_vector_keywords (handle, list);
    glob.list = list;
    complete_layer_config (handle, list);
    build_get_capabilities (list, &cached_capabilities,
			    &cached_capabilities_len, ip_addr, port_no);
    glob.cached_capabilities = cached_capabilities;

/* creating the read connections pool */
    pool = alloc_connections_pool (db_path, max_threads);
    if (pool == NULL)
      {
	  fprintf (stderr, "ERROR: unable to initialize a connections pool\n");
................................................................................
      {
	  fprintf (stderr, "ERROR: unable to initialize the server log\n");
	  goto stop;
      }
    glob.log = log;

/* starting the HTTP server */
    if (!do_start_http (ip_addr, port_no, &skt_ptr, max_threads))
	goto stop;

/* starting the logging facility */
    sql = "CREATE TABLE IF NOT EXISTS wms_server_log (\n"
	"\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n"
	"\ttimestamp TEXT NOT NULL,\n"
	"\tclient_ip_addr TEXT NOT NULL,\n"
................................................................................
      {
	  printf ("INSERT INTO LOG error: %s\n", sqlite3_errmsg (handle));
	  goto stop;
      }
    glob.stmt_log = stmt_log;

/* looping on requests */
    do_accept_loop (&skt_ptr, list, ip_addr, port_no, handle, stmt_log, pool,
		    log, cached_capabilities, cached_capabilities_len);

  stop:
    destroy_wms_list (list);
    list = NULL;
    glob.list = NULL;
    clean_shutdown ();
    return 0;
}