comparison ViewerPlugin/Plugin.cpp @ 259:3e511f10896c iiif

avoid non-integer scale factors in IIIF
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 Jul 2023 08:06:10 +0200
parents 07be799fa383
children 35c241231af2
comparison
equal deleted inserted replaced
258:07be799fa383 259:3e511f10896c
415 "IIIF doesn't support levels with varying tile sizes"); 415 "IIIF doesn't support levels with varying tile sizes");
416 } 416 }
417 } 417 }
418 418
419 Json::Value sizes = Json::arrayValue; 419 Json::Value sizes = Json::arrayValue;
420 Json::Value scaleFactors = Json::arrayValue;
421
420 for (unsigned int i = locker.GetPyramid().GetLevelCount(); i > 0; i--) 422 for (unsigned int i = locker.GetPyramid().GetLevelCount(); i > 0; i--)
421 { 423 {
422 Json::Value level; 424 /**
423 level["width"] = locker.GetPyramid().GetLevelWidth(i - 1); 425 * Openseadragon seems to have difficulties in rendering
424 level["height"] = locker.GetPyramid().GetLevelHeight(i - 1); 426 * non-integer scale factors. Consequently, we only keep the
425 sizes.append(level); 427 * levels with an integer scale factor.
426 } 428 **/
427 429 if (locker.GetPyramid().GetLevelWidth(0) % locker.GetPyramid().GetLevelWidth(i - 1) == 0 &&
428 Json::Value scaleFactors = Json::arrayValue; 430 locker.GetPyramid().GetLevelHeight(0) % locker.GetPyramid().GetLevelHeight(i - 1) == 0)
429 for (unsigned int i = locker.GetPyramid().GetLevelCount(); i > 0; i--) 431 {
430 { 432 Json::Value level;
431 scaleFactors.append(static_cast<float>(locker.GetPyramid().GetLevelWidth(0)) / 433 level["width"] = locker.GetPyramid().GetLevelWidth(i - 1);
432 static_cast<float>(locker.GetPyramid().GetLevelWidth(i - 1))); 434 level["height"] = locker.GetPyramid().GetLevelHeight(i - 1);
435 sizes.append(level);
436
437 scaleFactors.append(static_cast<float>(locker.GetPyramid().GetLevelWidth(0)) /
438 static_cast<float>(locker.GetPyramid().GetLevelWidth(i - 1)));
439 }
433 } 440 }
434 441
435 Json::Value tiles; 442 Json::Value tiles;
436 tiles["width"] = locker.GetPyramid().GetTileWidth(0); 443 tiles["width"] = locker.GetPyramid().GetTileWidth(0);
437 tiles["height"] = locker.GetPyramid().GetTileHeight(0); 444 tiles["height"] = locker.GetPyramid().GetTileHeight(0);
607 const unsigned int physicalTileHeight = GetPhysicalTileHeight(pyramid, level); 614 const unsigned int physicalTileHeight = GetPhysicalTileHeight(pyramid, level);
608 615
609 if (regionX % physicalTileWidth == 0 && 616 if (regionX % physicalTileWidth == 0 &&
610 regionY % physicalTileHeight == 0 && 617 regionY % physicalTileHeight == 0 &&
611 regionWidth <= physicalTileWidth && 618 regionWidth <= physicalTileWidth &&
612 regionHeight <= physicalTileHeight) 619 regionHeight <= physicalTileHeight &&
620 regionX + regionWidth <= pyramid.GetLevelWidth(0) &&
621 regionY + regionHeight <= pyramid.GetLevelHeight(0))
613 { 622 {
614 break; 623 break;
615 } 624 }
616 } 625 }
617 626
618 if (cropWidth > pyramid.GetTileWidth(level)) 627 if (level == pyramid.GetLevelCount())
628 {
629 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "IIIF - Cannot locate the level of interest");
630 }
631 else if (cropWidth > pyramid.GetTileWidth(level))
619 { 632 {
620 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "IIIF - Request for a cropping that is too large for the tile size"); 633 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "IIIF - Request for a cropping that is too large for the tile size");
621 }
622
623 if (level == pyramid.GetLevelCount())
624 {
625 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "IIIF - Cannot locate the level of interest");
626 } 634 }
627 else 635 else
628 { 636 {
629 rawTile.reset(new RawTile(locker.GetPyramid(), level, 637 rawTile.reset(new RawTile(locker.GetPyramid(), level,
630 regionX / GetPhysicalTileWidth(pyramid, level), 638 regionX / GetPhysicalTileWidth(pyramid, level),