#include #include using namespace std; using namespace xmltio; namespace icl { void extractImage (XCF::CTUPtr ctu, xmltio::Location l, ImgBase*& poImg) { const string& sURI = extract(l["uri"]); xmltio::Location p(l, "PROPERTIES"); int iWidth = extract(p["width"]); int iHeight = extract(p["height"]); depth eDepth = depth8u; // extract(p[XPath("@depth")]); int iChannels = extract(p["channels"]); icl::format fmt = translateFormat(extract(p["format"])); Location r (l, "ROI"); icl::Rect roi ((int) extract(r["offsetX"]), (int) extract(r["offsetY"]), (int) extract(r["width"]), (int) extract(r["height"])); ensureCompatible (&poImg, eDepth, Size(iWidth, iHeight), iChannels, fmt, roi); Time::value_type t = extract(l[XPath("TIMESTAMPS/CREATED")]); poImg->setTime (Time::microSeconds (t)); XCF::Binary::TransportUnitPtr btu = ctu->getBinary (sURI); XCF::Binary::TransportVecByte *pTypedBTU = dynamic_cast(btu.get()); const std::vector &vecImage = pTypedBTU->value; int imgSize = iWidth * iHeight * getSizeOf(eDepth); for (int i=0; i < iChannels; i++) { memcpy(poImg->getDataPtr(i), &vecImage[i*imgSize], imgSize); } } XCFGrabber::XCFGrabber (const std::string& sServer, XCF::RecoverLevel l) : m_locRequest ("" "" "", "/IMAGEREQUEST/GRAB"), m_remoteServer(0) { // create remote server instance m_remoteServer = XCF::RemoteServer::create(sServer, XCF::NONE); // and on success, set default recover level m_remoteServer->setRecoverLevel (l); } XCFGrabber::~XCFGrabber () { m_remoteServer->destroy (); } const ImgBase* XCFGrabber::grab (ImgBase **ppoDst) { receive (m_result); Location loc (m_result->getXML(), "/IMAGESET/IMAGE"); ImgBase *poOutput = prepareOutput (ppoDst); extractImage (m_result, loc, m_poSource); m_oConverter.apply (m_poSource, poOutput); return poOutput; } void XCFGrabber::grab (std::vector& vGrabbedImages) { receive (m_result); vGrabbedImages.resize (m_result->getBinaryMap().size()); xmltio::Location locResult (m_result->getXML(), "/IMAGESET"); XPathIterator locIt = XPath("IMAGE[uri]").evaluate(locResult); vector::iterator imgIt = vGrabbedImages.begin(); for (; locIt; ++locIt, ++imgIt) { ImgBase *poOutput = prepareOutput (&(*imgIt)); extractImage (m_result, *locIt, m_poSource); m_oConverter.apply (m_poSource, poOutput); } } void XCFGrabber::receive (XCF::CTUPtr& result) { m_locRequest["timestamp"] = ""; // most-recent image m_remoteServer->callMethod ("retrieveImage", m_locRequest.getDocumentText(), result); } }