MCPcopy Create free account
hub / github.com/MITK/MITK / HandleGET_mxnWindowScreenshot

Method HandleGET_mxnWindowScreenshot

Modules/RESTAPI/src/mitkRenderingController.cpp:2237–2282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2235}
2236
2237void RenderingController::HandleGET_mxnWindowScreenshot(const httplib::Request& req, httplib::Response& res) const
2238{
2239 const auto id = ReadRequiredPathParam(req, "id");
2240
2241 if (!IsValidMxNWindowId(id))
2242 {
2243 const auto error = ErrorResponse::InvalidRequest(
2244 "Malformed MxN window id '" + id + "'. Expected pattern: <prefix>__<bare> with URL-segment-safe characters.",
2245 req.path);
2246 this->SendErrorResponse(res, 400, error);
2247 return;
2248 }
2249
2250 if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasMxNWindowScreenshotProvider())
2251 {
2252 const auto error = ErrorResponse::RenderWindowNotAvailable(req.path);
2253 this->SendErrorResponse(res, 503, error);
2254 return;
2255 }
2256
2257 ScreenshotQueryParams params;
2258 try
2259 {
2260 params = ParseScreenshotQueryParams(req);
2261 }
2262 catch (const InvalidScreenshotRequest& e)
2263 {
2264 this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(e.detail, req.path));
2265 return;
2266 }
2267
2268 try
2269 {
2270 const auto imageData = m_RenderWindowBridge->TakeMxNWindowScreenshot(id, params.size, params.format);
2271 res.status = 200;
2272 res.set_content(
2273 reinterpret_cast<const char*>(imageData.data()),
2274 imageData.size(),
2275 ContentTypeFor(params.format));
2276 }
2277 catch (const std::exception& e)
2278 {
2279 const auto [status, payload] = MapBridgeException(e, req.path);
2280 this->SendErrorResponse(res, status, payload);
2281 }
2282}
2283
2284void RenderingController::Dispatch(std::function<void()> task) const
2285{

Calls 8

SendErrorResponseMethod · 0.95
IsValidMxNWindowIdFunction · 0.85
ContentTypeForFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45