Posts Tagged ‘stream’

libjpeg and libpng go C++

Wednesday, September 16th, 2009

I’ve just come across an interesting project(s). It is jpegxx and pngxx: two (or three if imagexx adaptors counted) thin libraries wrapping libjpeg and libpng with interface of C++ streams, iterators and ranges.

It slowly is getting crowded around raster libraries in C++. Another alternative is GIL developed by Adobe and included in Boost C++ Libraries with collection of IO and more extensions.

Just what tigers like best. Isn’t it?

OSGIS UK 2009 Live

Sunday, June 21st, 2009

Tomorrow early morning I’m leaving to Nottingham to attend the OSGIS UK 2009 conference. It’s been long time since FOSS4G 2007 and I didn’t make it to Cape Town last year, so I’m looking forward to meet FOSS4G and OSGeo folks in UK.

A few minutes ago, Suchith Anand announced there will be live streaming transmission available from OSGIS sessions. This is cool!

By the way, does anyone remember a kind of pioneer transmission from FOSS4G 2006 in Lausanne? The videos are still linked but seem to be unavailable. Pity. It would be cool to archive them somewhere on foss4g.org.

WKB hex decoder in C++

Thursday, August 21st, 2008

In PostGIS world, I often need to construct geometry from Well-Known-Binary (WKB) or PostGIS EWKB stream encoded as hex stream. It’s easy to do if I have access to PostgreSQL/PostGIS client which accepts SQL queries:

SELECT
   ST_AsText(
      ST_GeomFromWKB(
         decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'),
         4326))

I often need to do the same directly in C++ code – parse hex encoded binary stream to raw stream of bytes. Here is simple hex decoder I use:

#include <sstream>
#include <string>
#include <vector>
typedef std::vector<unsigned char> ewkb_t;

// bytes [out] - buffer for binary output
void hex_to_bytes(std::string const& hexstr, ewkb_t& bytes)
{
    bytes.clear();
    for(std::string::size_type i = 0; i < hexstr.size() / 2; ++i)
    {
        std::istringstream iss(hexstr.substr(i * 2, 2));
        unsigned int n;
        iss >> std::hex >> n;
        bytes.push_back(static_cast<unsigned char>(n));
    }
}

For example, I use it to build FDO geometry objects using another utility CreateGeometryFromExtendedWkb defined in FDO provider for PostGIS:

// POINT (1.234 5.678)
std::string ewkbhex("01010000005839B4C876BEF33F83C0CAA145B61640");
ewkb_t ewkb;
hex_to_bytes(ewkbhex, ewkb);
if (!ewkb.empty())
{
   FdoPtr<fdoigeometry> g = CreateGeometryFromExtendedWkb(ewkb);
   // ... use geometry
}