comparison Framework/Toolbox/ImageGeometry.cpp @ 190:465b294a55f0 wasm

typo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Mar 2018 14:35:26 +0100
parents 2cbfb08f3a95
children 46cb2eedc2e0
comparison
equal deleted inserted replaced
189:964118e7e6de 190:465b294a55f0
45 extent.AddPoint(p[0] / p[2], p[1] / p[2]); 45 extent.AddPoint(p[0] / p[2], p[1] / p[2]);
46 } 46 }
47 } 47 }
48 48
49 49
50 bool GetPerpectiveTransformExtent(unsigned int& x1, 50 bool GetProjectiveTransformExtent(unsigned int& x1,
51 unsigned int& y1, 51 unsigned int& y1,
52 unsigned int& x2, 52 unsigned int& x2,
53 unsigned int& y2, 53 unsigned int& y2,
54 const Matrix& a, 54 const Matrix& a,
55 unsigned int sourceWidth, 55 unsigned int sourceWidth,
199 199
200 Reader reader(source); 200 Reader reader(source);
201 201
202 unsigned int x1, y1, x2, y2; 202 unsigned int x1, y1, x2, y2;
203 203
204 if (GetPerpectiveTransformExtent(x1, y1, x2, y2, a, 204 if (GetProjectiveTransformExtent(x1, y1, x2, y2, a,
205 source.GetWidth(), source.GetHeight(), 205 source.GetWidth(), source.GetHeight(),
206 target.GetWidth(), target.GetHeight())) 206 target.GetWidth(), target.GetHeight()))
207 { 207 {
208 const size_t targetPitch = target.GetPitch(); 208 const size_t targetPitch = target.GetPitch();
209 uint8_t *targetRow = reinterpret_cast<uint8_t*>(reinterpret_cast<PixelType*>(target.GetRow(y1)) + x1); 209 uint8_t *targetRow = reinterpret_cast<uint8_t*>(reinterpret_cast<PixelType*>(target.GetRow(y1)) + x1);
358 } 358 }
359 359
360 360
361 template <Orthanc::PixelFormat Format, 361 template <Orthanc::PixelFormat Format,
362 ImageInterpolation Interpolation> 362 ImageInterpolation Interpolation>
363 static void ApplyPerspectiveInternal(Orthanc::ImageAccessor& target, 363 static void ApplyProjectiveInternal(Orthanc::ImageAccessor& target,
364 const Orthanc::ImageAccessor& source, 364 const Orthanc::ImageAccessor& source,
365 const Matrix& a, 365 const Matrix& a,
366 const Matrix& inva) 366 const Matrix& inva)
367 { 367 {
368 assert(target.GetFormat() == Format && 368 assert(target.GetFormat() == Format &&
369 source.GetFormat() == Format); 369 source.GetFormat() == Format);
370 370
371 typedef SubpixelReader<Format, Interpolation> Reader; 371 typedef SubpixelReader<Format, Interpolation> Reader;
375 unsigned int x1, y1, x2, y2; 375 unsigned int x1, y1, x2, y2;
376 376
377 const float floatWidth = source.GetWidth(); 377 const float floatWidth = source.GetWidth();
378 const float floatHeight = source.GetHeight(); 378 const float floatHeight = source.GetHeight();
379 379
380 if (GetPerpectiveTransformExtent(x1, y1, x2, y2, a, 380 if (GetProjectiveTransformExtent(x1, y1, x2, y2, a,
381 source.GetWidth(), source.GetHeight(), 381 source.GetWidth(), source.GetHeight(),
382 target.GetWidth(), target.GetHeight())) 382 target.GetWidth(), target.GetHeight()))
383 { 383 {
384 const size_t targetPitch = target.GetPitch(); 384 const size_t targetPitch = target.GetPitch();
385 uint8_t *targetRow = reinterpret_cast<uint8_t*>(reinterpret_cast<PixelType*>(target.GetRow(y1)) + x1); 385 uint8_t *targetRow = reinterpret_cast<uint8_t*>(reinterpret_cast<PixelType*>(target.GetRow(y1)) + x1);
401 const float sourceX = static_cast<float>(vv[0] * w); 401 const float sourceX = static_cast<float>(vv[0] * w);
402 const float sourceY = static_cast<float>(vv[1] * w); 402 const float sourceY = static_cast<float>(vv[1] * w);
403 403
404 // Make sure no integer overflow will occur after truncation 404 // Make sure no integer overflow will occur after truncation
405 // (the static_cast<unsigned int> could otherwise throw an 405 // (the static_cast<unsigned int> could otherwise throw an
406 // exception in WebAssembly if strong perspective effects) 406 // exception in WebAssembly if strong projective effects)
407 if (sourceX < floatWidth && 407 if (sourceX < floatWidth &&
408 sourceY < floatHeight) 408 sourceY < floatHeight)
409 { 409 {
410 reader.GetValue(*p, sourceX, sourceY); 410 reader.GetValue(*p, sourceX, sourceY);
411 } 411 }
421 } 421 }
422 } 422 }
423 } 423 }
424 424
425 425
426 void ApplyPerspectiveTransform(Orthanc::ImageAccessor& target, 426 void ApplyProjectiveTransform(Orthanc::ImageAccessor& target,
427 const Orthanc::ImageAccessor& source, 427 const Orthanc::ImageAccessor& source,
428 const Matrix& a, 428 const Matrix& a,
429 ImageInterpolation interpolation) 429 ImageInterpolation interpolation)
430 { 430 {
431 if (source.GetFormat() != target.GetFormat()) 431 if (source.GetFormat() != target.GetFormat())
432 { 432 {
433 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); 433 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
434 } 434 }
450 LinearAlgebra::IsCloseToZero(a(2, 1))) 450 LinearAlgebra::IsCloseToZero(a(2, 1)))
451 { 451 {
452 double w = a(2, 2); 452 double w = a(2, 2);
453 if (LinearAlgebra::IsCloseToZero(w)) 453 if (LinearAlgebra::IsCloseToZero(w))
454 { 454 {
455 LOG(ERROR) << "Singular perspective matrix"; 455 LOG(ERROR) << "Singular projective matrix";
456 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 456 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
457 } 457 }
458 else 458 else
459 { 459 {
460 ApplyAffineTransform(target, source, 460 ApplyAffineTransform(target, source,
484 { 484 {
485 case Orthanc::PixelFormat_Grayscale8: 485 case Orthanc::PixelFormat_Grayscale8:
486 switch (interpolation) 486 switch (interpolation)
487 { 487 {
488 case ImageInterpolation_Nearest: 488 case ImageInterpolation_Nearest:
489 ApplyPerspectiveInternal<Orthanc::PixelFormat_Grayscale8, 489 ApplyProjectiveInternal<Orthanc::PixelFormat_Grayscale8,
490 ImageInterpolation_Nearest>(target, source, a, inva); 490 ImageInterpolation_Nearest>(target, source, a, inva);
491 break; 491 break;
492 492
493 case ImageInterpolation_Bilinear: 493 case ImageInterpolation_Bilinear:
494 ApplyPerspectiveInternal<Orthanc::PixelFormat_Grayscale8, 494 ApplyProjectiveInternal<Orthanc::PixelFormat_Grayscale8,
495 ImageInterpolation_Bilinear>(target, source, a, inva); 495 ImageInterpolation_Bilinear>(target, source, a, inva);
496 break; 496 break;
497 497
498 default: 498 default:
499 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 499 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
500 } 500 }
502 502
503 case Orthanc::PixelFormat_Grayscale16: 503 case Orthanc::PixelFormat_Grayscale16:
504 switch (interpolation) 504 switch (interpolation)
505 { 505 {
506 case ImageInterpolation_Nearest: 506 case ImageInterpolation_Nearest:
507 ApplyPerspectiveInternal<Orthanc::PixelFormat_Grayscale16, 507 ApplyProjectiveInternal<Orthanc::PixelFormat_Grayscale16,
508 ImageInterpolation_Nearest>(target, source, a, inva); 508 ImageInterpolation_Nearest>(target, source, a, inva);
509 break; 509 break;
510 510
511 case ImageInterpolation_Bilinear: 511 case ImageInterpolation_Bilinear:
512 ApplyPerspectiveInternal<Orthanc::PixelFormat_Grayscale16, 512 ApplyProjectiveInternal<Orthanc::PixelFormat_Grayscale16,
513 ImageInterpolation_Bilinear>(target, source, a, inva); 513 ImageInterpolation_Bilinear>(target, source, a, inva);
514 break; 514 break;
515 515
516 default: 516 default:
517 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 517 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
518 } 518 }
520 520
521 case Orthanc::PixelFormat_SignedGrayscale16: 521 case Orthanc::PixelFormat_SignedGrayscale16:
522 switch (interpolation) 522 switch (interpolation)
523 { 523 {
524 case ImageInterpolation_Nearest: 524 case ImageInterpolation_Nearest:
525 ApplyPerspectiveInternal<Orthanc::PixelFormat_SignedGrayscale16, 525 ApplyProjectiveInternal<Orthanc::PixelFormat_SignedGrayscale16,
526 ImageInterpolation_Nearest>(target, source, a, inva); 526 ImageInterpolation_Nearest>(target, source, a, inva);
527 break; 527 break;
528 528
529 case ImageInterpolation_Bilinear: 529 case ImageInterpolation_Bilinear:
530 ApplyPerspectiveInternal<Orthanc::PixelFormat_SignedGrayscale16, 530 ApplyProjectiveInternal<Orthanc::PixelFormat_SignedGrayscale16,
531 ImageInterpolation_Bilinear>(target, source, a, inva); 531 ImageInterpolation_Bilinear>(target, source, a, inva);
532 break; 532 break;
533 533
534 default: 534 default:
535 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 535 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
536 } 536 }
538 538
539 case Orthanc::PixelFormat_RGB24: 539 case Orthanc::PixelFormat_RGB24:
540 switch (interpolation) 540 switch (interpolation)
541 { 541 {
542 case ImageInterpolation_Nearest: 542 case ImageInterpolation_Nearest:
543 ApplyPerspectiveInternal<Orthanc::PixelFormat_RGB24, 543 ApplyProjectiveInternal<Orthanc::PixelFormat_RGB24,
544 ImageInterpolation_Nearest>(target, source, a, inva); 544 ImageInterpolation_Nearest>(target, source, a, inva);
545 break; 545 break;
546 546
547 default: 547 default:
548 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 548 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
549 } 549 }