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

Function ParseScreenshotQueryParams

Modules/RESTAPI/src/mitkRenderingController.cpp:855–904  ·  view source on GitHub ↗

* \brief Parse `format` / `width` / `height` query parameters. * * \throws InvalidScreenshotRequest if any parameter is malformed. */

Source from the content-addressed store, hash-verified

853 * \throws InvalidScreenshotRequest if any parameter is malformed.
854 */
855 ScreenshotQueryParams ParseScreenshotQueryParams(const httplib::Request& req)
856 {
857 ScreenshotQueryParams p;
858
859 if (req.has_param("format"))
860 {
861 const auto formatStr = req.get_param_value("format");
862 if (formatStr == "png")
863 p.format = mitk::ScreenshotFormat::Png;
864 else if (formatStr == "jpeg")
865 p.format = mitk::ScreenshotFormat::Jpeg;
866 else
867 throw InvalidScreenshotRequest{
868 "Invalid format '" + formatStr + "'. Must be 'png' or 'jpeg'."};
869 }
870
871 const bool hasWidth = req.has_param("width");
872 const bool hasHeight = req.has_param("height");
873 if (hasWidth != hasHeight)
874 throw InvalidScreenshotRequest{
875 "Both 'width' and 'height' must be provided together."};
876
877 if (hasWidth)
878 {
879 int width = 0;
880 int height = 0;
881 try
882 {
883 width = std::stoi(req.get_param_value("width"));
884 height = std::stoi(req.get_param_value("height"));
885 }
886 catch (const std::exception&)
887 {
888 throw InvalidScreenshotRequest{"'width' and 'height' must be integers."};
889 }
890
891 if (width <= 0 || height <= 0)
892 throw InvalidScreenshotRequest{
893 "'width' and 'height' must be positive integers."};
894
895 static constexpr int maxDimension = 8192;
896 if (width > maxDimension || height > maxDimension)
897 throw InvalidScreenshotRequest{
898 "'width' and 'height' must not exceed " + std::to_string(maxDimension) + "."};
899
900 p.size = {width, height};
901 }
902
903 return p;
904 }
905
906 // SerializeSelectedPositionInfoToJson and ParsePositionFromBody live in the
907 // earlier anonymous namespace (top of this file) so they are visible to the

Calls

no outgoing calls

Tested by

no test coverage detected