PostGIS  2.4.9dev-r@@SVN_REVISION@@
raster/test/cunit/cu_misc.c
Go to the documentation of this file.
1 /*
2  * PostGIS Raster - Raster Types for PostGIS
3  * http://trac.osgeo.org/postgis/wiki/WKTRaster
4  *
5  * Copyright (C) 2013 Regents of the University of California
6  * <bkpark@ucdavis.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "CUnit/Basic.h"
25 #include "cu_tester.h"
26 
27 static void test_rgb_to_hsv() {
28  double rgb[3] = {0, 0, 0};
29  double hsv[3] = {0, 0, 0};
30 
31  rt_util_rgb_to_hsv(rgb, hsv);
32  CU_ASSERT_DOUBLE_EQUAL(hsv[0], 0, DBL_EPSILON);
33  CU_ASSERT_DOUBLE_EQUAL(hsv[1], 0, DBL_EPSILON);
34  CU_ASSERT_DOUBLE_EQUAL(hsv[2], 0, DBL_EPSILON);
35 
36  rgb[0] = 0;
37  rgb[1] = 0;
38  rgb[2] = 1;
39  rt_util_rgb_to_hsv(rgb, hsv);
40  CU_ASSERT_DOUBLE_EQUAL(hsv[0], 2/3., DBL_EPSILON);
41  CU_ASSERT_DOUBLE_EQUAL(hsv[1], 1, DBL_EPSILON);
42  CU_ASSERT_DOUBLE_EQUAL(hsv[2], 1, DBL_EPSILON);
43 
44  rgb[0] = 0;
45  rgb[1] = 0.25;
46  rgb[2] = 0.5;
47  rt_util_rgb_to_hsv(rgb, hsv);
48  CU_ASSERT_DOUBLE_EQUAL(hsv[0], 7/12., DBL_EPSILON);
49  CU_ASSERT_DOUBLE_EQUAL(hsv[1], 1, DBL_EPSILON);
50  CU_ASSERT_DOUBLE_EQUAL(hsv[2], 0.5, DBL_EPSILON);
51 
52  rgb[0] = 0.5;
53  rgb[1] = 1;
54  rgb[2] = 0.5;
55  rt_util_rgb_to_hsv(rgb, hsv);
56  CU_ASSERT_DOUBLE_EQUAL(hsv[0], 1/3., DBL_EPSILON);
57  CU_ASSERT_DOUBLE_EQUAL(hsv[1], 0.5, DBL_EPSILON);
58  CU_ASSERT_DOUBLE_EQUAL(hsv[2], 1, DBL_EPSILON);
59 
60  rgb[0] = 0.2;
61  rgb[1] = 0.4;
62  rgb[2] = 0.4;
63  rt_util_rgb_to_hsv(rgb, hsv);
64  CU_ASSERT_DOUBLE_EQUAL(hsv[0], 0.5, DBL_EPSILON);
65  CU_ASSERT_DOUBLE_EQUAL(hsv[1], 0.5, DBL_EPSILON);
66  CU_ASSERT_DOUBLE_EQUAL(hsv[2], 0.4, DBL_EPSILON);
67 }
68 
69 static void test_hsv_to_rgb() {
70  double hsv[3] = {0, 0, 0};
71  double rgb[3] = {0, 0, 0};
72 
73  rt_util_hsv_to_rgb(hsv, rgb);
74  CU_ASSERT_DOUBLE_EQUAL(rgb[0], 0, DBL_EPSILON);
75  CU_ASSERT_DOUBLE_EQUAL(rgb[1], 0, DBL_EPSILON);
76  CU_ASSERT_DOUBLE_EQUAL(rgb[2], 0, DBL_EPSILON);
77 
78  hsv[0] = 2/3.;
79  hsv[1] = 1;
80  hsv[2] = 1;
81  rt_util_hsv_to_rgb(hsv, rgb);
82  CU_ASSERT_DOUBLE_EQUAL(rgb[0], 0., DBL_EPSILON);
83  CU_ASSERT_DOUBLE_EQUAL(rgb[1], 0, DBL_EPSILON);
84  CU_ASSERT_DOUBLE_EQUAL(rgb[2], 1, DBL_EPSILON);
85 
86  hsv[0] = 7/12.;
87  hsv[1] = 1;
88  hsv[2] = 0.5;
89  rt_util_hsv_to_rgb(hsv, rgb);
90  CU_ASSERT_DOUBLE_EQUAL(rgb[0], 0, DBL_EPSILON);
91  CU_ASSERT_DOUBLE_EQUAL(rgb[1], 0.25, DBL_EPSILON);
92  CU_ASSERT_DOUBLE_EQUAL(rgb[2], 0.5, DBL_EPSILON);
93 
94  hsv[0] = 1/3.;
95  hsv[1] = 0.5;
96  hsv[2] = 1;
97  rt_util_hsv_to_rgb(hsv, rgb);
98  CU_ASSERT_DOUBLE_EQUAL(rgb[0], 0.5, DBL_EPSILON);
99  CU_ASSERT_DOUBLE_EQUAL(rgb[1], 1, DBL_EPSILON);
100  CU_ASSERT_DOUBLE_EQUAL(rgb[2], 0.5, DBL_EPSILON);
101 
102  hsv[0] = 0.5;
103  hsv[1] = 0.5;
104  hsv[2] = 0.4;
105  rt_util_hsv_to_rgb(hsv, rgb);
106  CU_ASSERT_DOUBLE_EQUAL(rgb[0], 0.2, DBL_EPSILON);
107  CU_ASSERT_DOUBLE_EQUAL(rgb[1], 0.4, DBL_EPSILON);
108  CU_ASSERT_DOUBLE_EQUAL(rgb[2], 0.4, DBL_EPSILON);
109 }
110 
111 static void test_util_gdal_open() {
112  extern char *gdal_enabled_drivers;
113 
114  GDALDatasetH ds;
115 
116  char *disable_all = GDAL_DISABLE_ALL;
117  char *enabled = "GTiff JPEG PNG";
118  // char *enabled_vsi = "GTiff JPEG PNG VSICURL";
119 
121 
122  /* all drivers disabled */
123  gdal_enabled_drivers = disable_all;
124  ds = rt_util_gdal_open("/tmp/foo", GA_ReadOnly, 0);
125  CU_ASSERT(ds == NULL);
126 
127  /* can't test VSICURL if HTTP driver not found */
128  if (!rt_util_gdal_driver_registered("HTTP"))
129  return;
130 
131  /* enabled drivers, no VSICURL */
132  gdal_enabled_drivers = enabled;
133  ds = rt_util_gdal_open("/vsicurl/http://download.osgeo.org/gdal/data/gtiff/small_world.tif", GA_ReadOnly, 0);
134  CU_ASSERT(ds == NULL);
135 
136  /* enabled drivers with VSICURL */
137  /* disabled as we don't want network access as a requirement
138  gdal_enabled_drivers = enabled_vsi;
139  ds = rt_util_gdal_open("/vsicurl/http://download.osgeo.org/gdal/data/gtiff/small_world.tif", GA_ReadOnly, 0);
140  CU_ASSERT(ds != NULL);
141  GDALClose(ds);
142  */
143 }
144 
145 /* register tests */
146 void misc_suite_setup(void);
148 {
149  CU_pSuite suite = CU_add_suite("misc", NULL, NULL);
153 }
154 
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:334
static void test_rgb_to_hsv()
#define GDAL_DISABLE_ALL
Definition: librtcore.h:2000
ds
Definition: pixval.py:66
int rt_util_gdal_driver_registered(const char *drv)
Definition: rt_util.c:353
static void test_hsv_to_rgb()
rt_errorstate rt_util_rgb_to_hsv(double rgb[3], double hsv[3])
Definition: rt_util.c:503
#define PG_ADD_TEST(suite, testfunc)
char * gdal_enabled_drivers
Definition: rt_util.c:373
static void test_util_gdal_open()
void misc_suite_setup(void)
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_util.c:379
rt_errorstate rt_util_hsv_to_rgb(double hsv[3], double rgb[3])
Definition: rt_util.c:557