bool Bitmap::loadEXR(const char* filename) { try { Imf::RgbaInputFile exr(filename); Imf::Array2D<Imf::Rgba> pixels; Imath::Box2i dw = exr.dataWindow(); width = dw.max.x - dw.min.x + 1; height = dw.max.y - dw.min.y + 1; pixels.resizeErase(height, width); exr.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width); exr.readPixels(dw.min.y, dw.max.y); data = new Color[width * height]; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { Color& pixel = data[y * width + x]; pixel.r = pixels[y + dw.min.y][x + dw.min.x].r; pixel.g = pixels[y + dw.min.y][x + dw.min.x].g; pixel.b = pixels[y + dw.min.y][x + dw.min.x].b; } return true; } catch (Iex::BaseExc ex) { width = height = 0; data = NULL; return false; } }
int main(int argc, char* argv[]) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, {0, 0, 0, 0} }; std::string output_format("SQLite"); while (true) { int c = getopt_long(argc, argv, "hf:", long_options, 0); if (c == -1) { break; } switch (c) { case 'h': print_help(); exit(0); case 'f': output_format = optarg; break; default: exit(1); } } std::string input_filename; std::string output_filename("ogr_out"); int remaining_args = argc - optind; if (remaining_args > 2) { std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl; exit(1); } else if (remaining_args == 2) { input_filename = argv[optind]; output_filename = argv[optind+1]; } else if (remaining_args == 1) { input_filename = argv[optind]; } else { input_filename = "-"; } index_type index_pos; location_handler_type location_handler(index_pos); osmium::experimental::FlexReader<location_handler_type> exr(input_filename, location_handler, osmium::osm_entity_bits::object); MyOGRHandler ogr_handler(output_format, output_filename); while (auto buffer = exr.read()) { osmium::apply(buffer, ogr_handler); } exr.close(); std::vector<const osmium::Relation*> incomplete_relations = exr.collector().get_incomplete_relations(); if (!incomplete_relations.empty()) { std::cerr << "Warning! Some member ways missing for these multipolygon relations:"; for (const auto* relation : incomplete_relations) { std::cerr << " " << relation->id(); } std::cerr << "\n"; } google::protobuf::ShutdownProtobufLibrary(); }