# HG changeset patch # User Sebastien Jodogne # Date 1689144059 -7200 # Node ID c766c25fe4929d56e98d73025c76453442e1162f # Parent 45e3b5adf4ae7a8d01729f126506749a7b081cce upgrade from IIIF Image API 2.1.1 to 3.0.0 diff -r 45e3b5adf4ae -r c766c25fe492 ViewerPlugin/IIIF.cpp --- a/ViewerPlugin/IIIF.cpp Wed Jul 12 07:38:59 2023 +0200 +++ b/ViewerPlugin/IIIF.cpp Wed Jul 12 08:40:59 2023 +0200 @@ -118,15 +118,15 @@ tiles["scaleFactors"] = scaleFactors; Json::Value result; - result["@context"] = "http://iiif.io/api/image/2/context.json"; - result["@id"] = iiifPublicUrl_ + "tiles/" + seriesId; - result["profile"] = "http://iiif.io/api/image/2/level0.json"; + result["@context"] = "http://iiif.io/api/image/3/context.json"; + result["profile"] = "level0"; result["protocol"] = "http://iiif.io/api/image"; + result["type"] = "ImageService3"; + + result["id"] = iiifPublicUrl_ + "tiles/" + seriesId; result["width"] = pyramid.GetLevelWidth(0); result["height"] = pyramid.GetLevelHeight(0); result["sizes"] = sizes; - - result["tiles"] = Json::arrayValue; result["tiles"].append(tiles); std::string s = result.toStyledString(); @@ -249,18 +249,20 @@ if (!ok) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "IIIF - Not a (x,y,width,height) region: " + region); + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "IIIF - Not a (x,y,width,height) region, found: " + region); } - int cropWidth; - boost::regex sizePattern("([0-9]+),"); + ok = false; + int cropWidth, cropHeight; + boost::regex sizePattern("([0-9]+),([0-9]+)"); boost::cmatch sizeWhat; if (regex_match(size.c_str(), sizeWhat, sizePattern)) { try { cropWidth = boost::lexical_cast(sizeWhat[1]); - ok = (cropWidth > 0); + cropHeight = boost::lexical_cast(sizeWhat[2]); + ok = (cropWidth > 0 && cropHeight > 0); } catch (boost::bad_lexical_cast&) { @@ -269,7 +271,7 @@ if (!ok) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "IIIF - Not a (width,) size: " + size); + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "IIIF - Not a (width,height) crop, found: " + size); } std::unique_ptr rawTile; @@ -311,7 +313,8 @@ regionX / GetPhysicalTileWidth(pyramid, level), regionY / GetPhysicalTileHeight(pyramid, level))); - if (static_cast(cropWidth) < pyramid.GetTileWidth(level)) + if (static_cast(cropWidth) < pyramid.GetTileWidth(level) || + static_cast(cropHeight) < pyramid.GetTileHeight(level)) { toCrop.reset(rawTile->Decode()); rawTile.reset(NULL); @@ -329,10 +332,15 @@ else if (toCrop.get() != NULL) { assert(rawTile.get() == NULL); - assert(static_cast(cropWidth) < toCrop->GetWidth()); + + if (static_cast(cropWidth) > toCrop->GetWidth() || + static_cast(cropHeight) > toCrop->GetHeight()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "IIIF - Asking to crop outside of the tile size"); + } Orthanc::ImageAccessor cropped; - toCrop->GetRegion(cropped, 0, 0, cropWidth, toCrop->GetHeight()); + toCrop->GetRegion(cropped, 0, 0, cropWidth, cropHeight); std::string encoded; OrthancWSI::RawTile::Encode(encoded, cropped, Orthanc::MimeType_Jpeg); @@ -559,10 +567,12 @@ tile["scaleFactors"].append(1); Json::Value result; - result["@context"] = "http://iiif.io/api/image/2/context.json"; - result["@id"] = iiifPublicUrl_ + "frames/" + instanceId + "/" + frame; - result["profile"] = "http://iiif.io/api/image/2/level0.json"; + result["@context"] = "http://iiif.io/api/image/3/context.json"; + result["profile"] = "http://iiif.io/api/image/3/level0.json"; result["protocol"] = "http://iiif.io/api/image"; + result["type"] = "ImageService3"; + + result["id"] = iiifPublicUrl_ + "frames/" + instanceId + "/" + frame; result["width"] = width; result["height"] = height; result["tiles"].append(tile);