| 157 | } |
| 158 | |
| 159 | tiledb::Filter FilterFactory::filter(const tiledb::Context& ctx, |
| 160 | const NL::json& options) |
| 161 | { |
| 162 | if (options.empty()) |
| 163 | return tiledb::Filter(ctx, TILEDB_FILTER_NONE); |
| 164 | std::string filter_type_str = options["compression"]; |
| 165 | auto filter_type = FilterFactory::filterTypeFromString(filter_type_str); |
| 166 | |
| 167 | tiledb::Filter filter{ctx, filter_type}; |
| 168 | |
| 169 | for (auto& opt : options.items()) |
| 170 | { |
| 171 | const auto& key = opt.key(); |
| 172 | if (key == "compression") |
| 173 | continue; |
| 174 | else if (key == "compression_level" || key == "COMPRESSION_LEVEL") |
| 175 | filter.set_option(TILEDB_COMPRESSION_LEVEL, |
| 176 | options[key].get<int32_t>()); |
| 177 | else if (key == "bit_width_max_window" || key == "BIT_WIDTH_MAX_WINDOW") |
| 178 | filter.set_option(TILEDB_BIT_WIDTH_MAX_WINDOW, |
| 179 | options[key].get<uint32_t>()); |
| 180 | else if (key == "positive_delta_max_window" || |
| 181 | key == "POSITIVE_DELTA_MAX_WINDOW") |
| 182 | filter.set_option(TILEDB_POSITIVE_DELTA_MAX_WINDOW, |
| 183 | options[key].get<uint32_t>()); |
| 184 | else if (key == "scale_float_bytewidth" || |
| 185 | key == "SCALE_FLOAT_BYTEWIDTH") |
| 186 | filter.set_option(TILEDB_SCALE_FLOAT_BYTEWIDTH, |
| 187 | options[key].get<uint64_t>()); |
| 188 | else if (key == "scale_float_factor" || key == "SCALE_FLOAT_FACTOR") |
| 189 | filter.set_option(TILEDB_SCALE_FLOAT_FACTOR, |
| 190 | options[key].get<double>()); |
| 191 | else if (key == "scale_float_offset" || key == "SCALE_FLOAT_OFFSET") |
| 192 | filter.set_option(TILEDB_SCALE_FLOAT_OFFSET, |
| 193 | options[key].get<double>()); |
| 194 | else if (key == "webp_quality" || key == "WEBP_QUALITY") |
| 195 | filter.set_option(TILEDB_WEBP_QUALITY, options[key].get<float>()); |
| 196 | else if (key == "webp_input_format" || key == "WEBP_INPUT_FORMAT") |
| 197 | { |
| 198 | auto input_format_str = options[key].get<std::string>(); |
| 199 | uint8_t input_format = 0; |
| 200 | if (input_format_str == "none") |
| 201 | input_format = 0; |
| 202 | else if (input_format_str == "rgb") |
| 203 | input_format = 1; |
| 204 | else if (input_format_str == "bgr") |
| 205 | input_format = 2; |
| 206 | else if (input_format_str == "rgba") |
| 207 | input_format = 3; |
| 208 | else if (input_format_str == "bgra") |
| 209 | input_format = 4; |
| 210 | else |
| 211 | throw tiledb::TileDBError("Unrecognized webp input format '" + |
| 212 | input_format_str + "'."); |
| 213 | filter.set_option<uint8_t>(TILEDB_WEBP_INPUT_FORMAT, input_format); |
| 214 | } |
| 215 | else if (key == "webp_lossless" || key == "WEBP_LOSSLESS") |
| 216 | { |