Skip to content

Commit

Permalink
TileSource now loads images from http tile servers without SSL certif…
Browse files Browse the repository at this point in the history
…icate
  • Loading branch information
Matthew Reid committed Apr 6, 2024
1 parent fcafc6d commit 61dd843
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Skybolt/SkyboltVis/OsgImageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ osg::Image* readImageWithCorrectOrientation(const std::string& filename)
return image;
}

osg::ref_ptr<osg::Image> readImageWithoutWarnings(const std::string& filename)
osg::ref_ptr<osg::Image> readImageWithoutWarnings(const std::string& filename, const osgDB::Options* options)
{
osgDB::ReaderWriter::ReadResult rr = osgDB::Registry::instance()->readImage(filename, osgDB::Registry::instance()->getOptions());
osgDB::ReaderWriter::ReadResult rr = osgDB::Registry::instance()->readImage(filename, options ? options : osgDB::Registry::instance()->getOptions());
if (rr.validImage()) return osg::ref_ptr<osg::Image>(rr.getImage());
return nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Skybolt/SkyboltVis/OsgImageHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <osg/Image>
#include <osgDB/Registry>
#include <SkyboltCommon/Exception.h>
#include <string>

Expand Down Expand Up @@ -58,7 +59,7 @@ GLuint toSrgbInternalFormat(GLuint format);

osg::Image* readImageWithCorrectOrientation(const std::string& filename);

osg::ref_ptr<osg::Image> readImageWithoutWarnings(const std::string& filename);
osg::ref_ptr<osg::Image> readImageWithoutWarnings(const std::string& filename, const osgDB::Options* options = osgDB::Registry::instance()->getOptions());

//! Reads an image from stream including the image's user data stored in osg::UserDataContainer
osg::ref_ptr<osg::Image> readImageWithUserData(std::istream& s, const std::string& extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ XyzTileSource::XyzTileSource(const XyzTileSourceConfig& config) :
mYOrigin(config.yOrigin),
mApiKey(config.apiKey),
mCacheSha(skybolt::calcSha1(config.urlTemplate)),
mElevationRerange(config.elevationRerange)
mElevationRerange(config.elevationRerange),
mImageReadOptions(new osgDB::Options())
{
// Disable SSL verification CURL requests, so that we can read images from http:// tile servers.
// FIXME: Ideally we would allow the user keep verification on and provide a certificate.
mImageReadOptions->setOptionString("OSG_CURL_SSL_VERIFYPEER=0");
}

bool XyzTileSource::validate() const
{
// Validate the loader by loading level 0 image
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(toUrl(QuadTreeTileKey()));
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(toUrl(QuadTreeTileKey()), mImageReadOptions);
if (!image)
{
BOOST_LOG_TRIVIAL(error) << "Could not load image from XyzTileSource with URL template '" << mUrlTemplate << ".";
Expand Down Expand Up @@ -65,7 +69,7 @@ static int flipY(int y, int level)

osg::ref_ptr<osg::Image> XyzTileSource::createImage(const QuadTreeTileKey& key, std::function<bool()> cancelSupplier) const
{
osg::ref_ptr<osg::Image> image = readImageWithoutWarnings(toUrl(key));
osg::ref_ptr<osg::Image> image = readImageWithoutWarnings(toUrl(key), mImageReadOptions);
if (image)
{
if (mElevationRerange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once
#include "TileSourceWithMinMaxLevel.h"
#include "SkyboltVis/Renderable/Planet/Tile/HeightMapElevationRerange.h"
#include <osgDB/Options>

namespace skybolt {
namespace vis {
Expand Down Expand Up @@ -59,6 +60,8 @@ class XyzTileSource : public TileSourceWithMinMaxLevel
const std::string mApiKey;
const std::string mCacheSha;
std::optional<HeightMapElevationRerange> mElevationRerange;

osg::ref_ptr<osgDB::Options> mImageReadOptions;
};

} // namespace vis
Expand Down

0 comments on commit 61dd843

Please sign in to comment.