PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_raster_colormap ( )
static

Definition at line 874 of file cu_mapalgebra.c.

References ovdump::band, rt_colormap_entry_t::color, cu_add_band(), cu_free_raster(), rt_colormap_t::entry, ES_NONE, rt_colormap_entry_t::isnodata, rt_colormap_t::method, rt_colormap_t::ncolor, rt_colormap_t::nentry, PT_8BUI, rtrowdump::raster, rt_band_get_pixel(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_colormap(), rt_raster_get_band(), rt_raster_get_num_bands(), rt_raster_new(), rtalloc(), rtdealloc(), genraster::value, rt_colormap_entry_t::value, pixval::x, and pixval::y.

Referenced by mapalgebra_suite_setup().

874  {
876  rt_raster rtn;
877  rt_band band;
878  int x;
879  int y;
880  rt_colormap colormap = NULL;
881  double value;
882  int nodata;
883 
884  raster = rt_raster_new(9, 9);
885  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
886  band = cu_add_band(raster, PT_8BUI, 0, 0);
887  CU_ASSERT(band != NULL);
888  rt_band_set_nodata(band, 0, NULL);
889 
890  for (y = 0; y < 9; y++) {
891  for (x = 0; x < 9; x++) {
892  rt_band_set_pixel(band, x, y, x, NULL);
893  }
894  }
895 
896  colormap = (rt_colormap) rtalloc(sizeof(struct rt_colormap_t));
897  CU_ASSERT(colormap != NULL);
898  colormap->nentry = 3;
899  colormap->entry = (rt_colormap_entry) rtalloc(sizeof(struct rt_colormap_entry_t) * colormap->nentry);
900  CU_ASSERT(colormap->entry != NULL);
901 
902  colormap->entry[0].isnodata = 0;
903  colormap->entry[0].value = 8;
904  colormap->entry[0].color[0] = 255;
905  colormap->entry[0].color[1] = 255;
906  colormap->entry[0].color[2] = 255;
907  colormap->entry[0].color[3] = 255;
908 
909  colormap->entry[1].isnodata = 0;
910  colormap->entry[1].value = 3;
911  colormap->entry[1].color[0] = 127;
912  colormap->entry[1].color[1] = 127;
913  colormap->entry[1].color[2] = 127;
914  colormap->entry[1].color[3] = 255;
915 
916  colormap->entry[2].isnodata = 0;
917  colormap->entry[2].value = 0;
918  colormap->entry[2].color[0] = 0;
919  colormap->entry[2].color[1] = 0;
920  colormap->entry[2].color[2] = 0;
921  colormap->entry[2].color[3] = 255;
922 
923  /* 2 colors, 3 entries, INTERPOLATE */
924  colormap->ncolor = 2;
925  colormap->method = CM_INTERPOLATE;
926 
927  rtn = rt_raster_colormap(
928  raster, 0,
929  colormap
930  );
931  CU_ASSERT(rtn != NULL);
932  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
933 
934  band = rt_raster_get_band(rtn, 0);
935  CU_ASSERT(band != NULL);
936  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, &nodata), ES_NONE);
937  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
938  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 3, 0, &value, &nodata), ES_NONE);
939  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
940  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 8, 0, &value, &nodata), ES_NONE);
941  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
942 
943  cu_free_raster(rtn);
944 
945  /* 4 colors, 3 entries, INTERPOLATE */
946  colormap->ncolor = 4;
947 
948  rtn = rt_raster_colormap(
949  raster, 0,
950  colormap
951  );
952  CU_ASSERT(rtn != NULL);
953  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
954  cu_free_raster(rtn);
955 
956  /* 4 colors, 3 entries, EXACT */
957  colormap->method = CM_EXACT;
958 
959  rtn = rt_raster_colormap(
960  raster, 0,
961  colormap
962  );
963  CU_ASSERT(rtn != NULL);
964  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
965 
966  band = rt_raster_get_band(rtn, 0);
967  CU_ASSERT(band != NULL);
968  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, &nodata), ES_NONE);
969  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
970  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 3, 0, &value, &nodata), ES_NONE);
971  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
972  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 8, 0, &value, &nodata), ES_NONE);
973  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
974  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 1, 0, &value, &nodata), ES_NONE);
975  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
976  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 7, 0, &value, &nodata), ES_NONE);
977  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
978 
979  cu_free_raster(rtn);
980 
981  /* 4 colors, 3 entries, NEAREST */
982  colormap->method = CM_NEAREST;
983 
984  rtn = rt_raster_colormap(
985  raster, 0,
986  colormap
987  );
988  CU_ASSERT(rtn != NULL);
989  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
990 
991  band = rt_raster_get_band(rtn, 0);
992  CU_ASSERT(band != NULL);
993  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, &nodata), ES_NONE);
994  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
995  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 3, 0, &value, &nodata), ES_NONE);
996  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
997  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 8, 0, &value, &nodata), ES_NONE);
998  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
999  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 1, 0, &value, &nodata), ES_NONE);
1000  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
1001  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 2, 0, &value, &nodata), ES_NONE);
1002  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1003  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 4, 0, &value, &nodata), ES_NONE);
1004  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1005  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 7, 0, &value, &nodata), ES_NONE);
1006  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
1007 
1008  cu_free_raster(rtn);
1009 
1010  /* 4 colors, 2 entries, NEAREST */
1011  colormap->nentry = 2;
1012  colormap->method = CM_NEAREST;
1013 
1014  rtn = rt_raster_colormap(
1015  raster, 0,
1016  colormap
1017  );
1018  CU_ASSERT(rtn != NULL);
1019  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
1020 
1021  band = rt_raster_get_band(rtn, 0);
1022  CU_ASSERT(band != NULL);
1023  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, &nodata), ES_NONE);
1024  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1025  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 3, 0, &value, &nodata), ES_NONE);
1026  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1027  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 8, 0, &value, &nodata), ES_NONE);
1028  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
1029  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 1, 0, &value, &nodata), ES_NONE);
1030  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1031  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 2, 0, &value, &nodata), ES_NONE);
1032  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1033  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 4, 0, &value, &nodata), ES_NONE);
1034  CU_ASSERT_DOUBLE_EQUAL(value, 127, DBL_EPSILON);
1035  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 7, 0, &value, &nodata), ES_NONE);
1036  CU_ASSERT_DOUBLE_EQUAL(value, 255, DBL_EPSILON);
1037 
1038  cu_free_raster(rtn);
1039 
1040  rtdealloc(colormap->entry);
1041  rtdealloc(colormap);
1042 
1043  cu_free_raster(raster);
1044 
1045  /* new set of tests */
1046  raster = rt_raster_new(10, 10);
1047  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
1048  band = cu_add_band(raster, PT_8BUI, 0, 0);
1049  CU_ASSERT(band != NULL);
1050  rt_band_set_nodata(band, 0, NULL);
1051 
1052  for (y = 0; y < 10; y++) {
1053  for (x = 0; x < 10; x++) {
1054  rt_band_set_pixel(band, x, y, (x * y) + x, NULL);
1055  }
1056  }
1057 
1058  colormap = (rt_colormap) rtalloc(sizeof(struct rt_colormap_t));
1059  CU_ASSERT(colormap != NULL);
1060  colormap->nentry = 10;
1061  colormap->entry = (rt_colormap_entry) rtalloc(sizeof(struct rt_colormap_entry_t) * colormap->nentry);
1062  CU_ASSERT(colormap->entry != NULL);
1063 
1064  colormap->entry[0].isnodata = 0;
1065  colormap->entry[0].value = 90;
1066  colormap->entry[0].color[0] = 255;
1067  colormap->entry[0].color[1] = 255;
1068  colormap->entry[0].color[2] = 255;
1069  colormap->entry[0].color[3] = 255;
1070 
1071  colormap->entry[1].isnodata = 0;
1072  colormap->entry[1].value = 80;
1073  colormap->entry[1].color[0] = 255;
1074  colormap->entry[1].color[1] = 227;
1075  colormap->entry[1].color[2] = 227;
1076  colormap->entry[1].color[3] = 255;
1077 
1078  colormap->entry[2].isnodata = 0;
1079  colormap->entry[2].value = 70;
1080  colormap->entry[2].color[0] = 255;
1081  colormap->entry[2].color[1] = 198;
1082  colormap->entry[2].color[2] = 198;
1083  colormap->entry[2].color[3] = 255;
1084 
1085  colormap->entry[3].isnodata = 0;
1086  colormap->entry[3].value = 60;
1087  colormap->entry[3].color[0] = 255;
1088  colormap->entry[3].color[1] = 170;
1089  colormap->entry[3].color[2] = 170;
1090  colormap->entry[3].color[3] = 255;
1091 
1092  colormap->entry[4].isnodata = 0;
1093  colormap->entry[4].value = 50;
1094  colormap->entry[4].color[0] = 255;
1095  colormap->entry[4].color[1] = 142;
1096  colormap->entry[4].color[2] = 142;
1097  colormap->entry[4].color[3] = 255;
1098 
1099  colormap->entry[5].isnodata = 0;
1100  colormap->entry[5].value = 40;
1101  colormap->entry[5].color[0] = 255;
1102  colormap->entry[5].color[1] = 113;
1103  colormap->entry[5].color[2] = 113;
1104  colormap->entry[5].color[3] = 255;
1105 
1106  colormap->entry[6].isnodata = 0;
1107  colormap->entry[6].value = 30;
1108  colormap->entry[6].color[0] = 255;
1109  colormap->entry[6].color[1] = 85;
1110  colormap->entry[6].color[2] = 85;
1111  colormap->entry[6].color[3] = 255;
1112 
1113  colormap->entry[7].isnodata = 0;
1114  colormap->entry[7].value = 20;
1115  colormap->entry[7].color[0] = 255;
1116  colormap->entry[7].color[1] = 57;
1117  colormap->entry[7].color[2] = 57;
1118  colormap->entry[7].color[3] = 255;
1119 
1120  colormap->entry[8].isnodata = 0;
1121  colormap->entry[8].value = 10;
1122  colormap->entry[8].color[0] = 255;
1123  colormap->entry[8].color[1] = 28;
1124  colormap->entry[8].color[2] = 28;
1125  colormap->entry[8].color[3] = 255;
1126 
1127  colormap->entry[9].isnodata = 0;
1128  colormap->entry[9].value = 0;
1129  colormap->entry[9].color[0] = 255;
1130  colormap->entry[9].color[1] = 0;
1131  colormap->entry[9].color[2] = 0;
1132  colormap->entry[9].color[3] = 255;
1133 
1134  /* 2 colors, 3 entries, INTERPOLATE */
1135  colormap->ncolor = 4;
1136  colormap->method = CM_INTERPOLATE;
1137 
1138  rtn = rt_raster_colormap(
1139  raster, 0,
1140  colormap
1141  );
1142  CU_ASSERT(rtn != NULL);
1143  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rtn), colormap->ncolor);
1144 
1145  band = rt_raster_get_band(rtn, 2);
1146  CU_ASSERT(band != NULL);
1147  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, &nodata), ES_NONE);
1148  CU_ASSERT_DOUBLE_EQUAL(value, 0, DBL_EPSILON);
1149  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 5, 0, &value, &nodata), ES_NONE);
1150  CU_ASSERT_DOUBLE_EQUAL(value, 14, DBL_EPSILON);
1151  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 6, 0, &value, &nodata), ES_NONE);
1152  CU_ASSERT_DOUBLE_EQUAL(value, 17, DBL_EPSILON);
1153  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 9, 0, &value, &nodata), ES_NONE);
1154  CU_ASSERT_DOUBLE_EQUAL(value, 25, DBL_EPSILON);
1155 
1156  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 2, 4, &value, &nodata), ES_NONE);
1157  CU_ASSERT_DOUBLE_EQUAL(value, 28, DBL_EPSILON);
1158  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 3, 4, &value, &nodata), ES_NONE);
1159  CU_ASSERT_DOUBLE_EQUAL(value, 43, DBL_EPSILON);
1160  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 4, 4, &value, &nodata), ES_NONE);
1161  CU_ASSERT_DOUBLE_EQUAL(value, 57, DBL_EPSILON);
1162 
1163  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 6, 9, &value, &nodata), ES_NONE);
1164  CU_ASSERT_DOUBLE_EQUAL(value, 170, DBL_EPSILON);
1165  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 7, 9, &value, &nodata), ES_NONE);
1166  CU_ASSERT_DOUBLE_EQUAL(value, 198, DBL_EPSILON);
1167  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 8, 9, &value, &nodata), ES_NONE);
1168  CU_ASSERT_DOUBLE_EQUAL(value, 227, DBL_EPSILON);
1169 
1170  cu_free_raster(rtn);
1171 
1172  rtdealloc(colormap->entry);
1173  rtdealloc(colormap);
1174 
1175  cu_free_raster(raster);
1176 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
rt_raster rt_raster_colormap(rt_raster raster, int nband, rt_colormap colormap)
Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified...
Definition: rt_api.c:14937
void rtdealloc(void *mem)
Definition: rt_api.c:882
uint16_t nentry
Definition: rt_api.h:2410
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_api.c:2061
uint8_t color[4]
Definition: rt_api.h:2399
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
void cu_free_raster(rt_raster raster)
struct rt_colormap_t * rt_colormap
Definition: rt_api.h:148
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
enum rt_colormap_t::@15 method
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
rt_colormap_entry entry
Definition: rt_api.h:2411
tuple x
Definition: pixval.py:53
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
Definition: rt_api.h:2396
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
int isnodata
Definition: rt_api.h:2397
struct rt_colormap_entry_t * rt_colormap_entry
Definition: rt_api.h:147
double value
Definition: rt_api.h:2398
tuple y
Definition: pixval.py:54
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function:

Here is the caller graph for this function: