Mercurial > hg > orthanc
comparison OrthancServer/FromDcmtkBridge.cpp @ 853:839be3022203 jpeg
DicomImageInformation
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Jun 2014 11:45:16 +0200 |
parents | 715ab7674993 |
children | 610a9a1ed855 |
comparison
equal
deleted
inserted
replaced
852:5944b8b80842 | 853:839be3022203 |
---|---|
429 | 429 |
430 | 430 |
431 static void ExtractPngImageColorPreview(std::string& result, | 431 static void ExtractPngImageColorPreview(std::string& result, |
432 DicomIntegerPixelAccessor& accessor) | 432 DicomIntegerPixelAccessor& accessor) |
433 { | 433 { |
434 assert(accessor.GetChannelCount() == 3); | 434 assert(accessor.GetInformation().GetChannelCount() == 3); |
435 PngWriter w; | 435 PngWriter w; |
436 | 436 |
437 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight() * 3, 0); | 437 std::vector<uint8_t> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight() * 3, 0); |
438 uint8_t* pixel = &image[0]; | 438 uint8_t* pixel = &image[0]; |
439 | 439 |
440 for (unsigned int y = 0; y < accessor.GetHeight(); y++) | 440 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++) |
441 { | 441 { |
442 for (unsigned int x = 0; x < accessor.GetWidth(); x++) | 442 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++) |
443 { | 443 { |
444 for (unsigned int c = 0; c < 3; c++, pixel++) | 444 for (unsigned int c = 0; c < 3; c++, pixel++) |
445 { | 445 { |
446 int32_t v = accessor.GetValue(x, y, c); | 446 int32_t v = accessor.GetValue(x, y, c); |
447 if (v < 0) | 447 if (v < 0) |
452 *pixel = v; | 452 *pixel = v; |
453 } | 453 } |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), | 457 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(), |
458 accessor.GetWidth() * 3, PixelFormat_RGB24, &image[0]); | 458 accessor.GetInformation().GetWidth() * 3, PixelFormat_RGB24, &image[0]); |
459 } | 459 } |
460 | 460 |
461 | 461 |
462 static void ExtractPngImageGrayscalePreview(std::string& result, | 462 static void ExtractPngImageGrayscalePreview(std::string& result, |
463 DicomIntegerPixelAccessor& accessor) | 463 DicomIntegerPixelAccessor& accessor) |
464 { | 464 { |
465 assert(accessor.GetChannelCount() == 1); | 465 assert(accessor.GetInformation().GetChannelCount() == 1); |
466 PngWriter w; | 466 PngWriter w; |
467 | 467 |
468 int32_t min, max; | 468 int32_t min, max; |
469 accessor.GetExtremeValues(min, max); | 469 accessor.GetExtremeValues(min, max); |
470 | 470 |
471 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight(), 0); | 471 std::vector<uint8_t> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight(), 0); |
472 if (min != max) | 472 if (min != max) |
473 { | 473 { |
474 uint8_t* pixel = &image[0]; | 474 uint8_t* pixel = &image[0]; |
475 for (unsigned int y = 0; y < accessor.GetHeight(); y++) | 475 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++) |
476 { | 476 { |
477 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) | 477 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++, pixel++) |
478 { | 478 { |
479 int32_t v = accessor.GetValue(x, y); | 479 int32_t v = accessor.GetValue(x, y); |
480 *pixel = static_cast<uint8_t>( | 480 *pixel = static_cast<uint8_t>( |
481 boost::math::lround(static_cast<float>(v - min) / | 481 boost::math::lround(static_cast<float>(v - min) / |
482 static_cast<float>(max - min) * 255.0f)); | 482 static_cast<float>(max - min) * 255.0f)); |
483 } | 483 } |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), | 487 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(), |
488 accessor.GetWidth(), PixelFormat_Grayscale8, &image[0]); | 488 accessor.GetInformation().GetWidth(), PixelFormat_Grayscale8, &image[0]); |
489 } | 489 } |
490 | 490 |
491 | 491 |
492 template <typename T> | 492 template <typename T> |
493 static void ExtractPngImageTruncate(std::string& result, | 493 static void ExtractPngImageTruncate(std::string& result, |
494 DicomIntegerPixelAccessor& accessor, | 494 DicomIntegerPixelAccessor& accessor, |
495 PixelFormat format) | 495 PixelFormat format) |
496 { | 496 { |
497 assert(accessor.GetChannelCount() == 1); | 497 assert(accessor.GetInformation().GetChannelCount() == 1); |
498 | 498 |
499 PngWriter w; | 499 PngWriter w; |
500 | 500 |
501 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); | 501 std::vector<T> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight(), 0); |
502 T* pixel = &image[0]; | 502 T* pixel = &image[0]; |
503 for (unsigned int y = 0; y < accessor.GetHeight(); y++) | 503 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++) |
504 { | 504 { |
505 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) | 505 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++, pixel++) |
506 { | 506 { |
507 int32_t v = accessor.GetValue(x, y); | 507 int32_t v = accessor.GetValue(x, y); |
508 if (v < static_cast<int32_t>(std::numeric_limits<T>::min())) | 508 if (v < static_cast<int32_t>(std::numeric_limits<T>::min())) |
509 *pixel = std::numeric_limits<T>::min(); | 509 *pixel = std::numeric_limits<T>::min(); |
510 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max())) | 510 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max())) |
512 else | 512 else |
513 *pixel = static_cast<T>(v); | 513 *pixel = static_cast<T>(v); |
514 } | 514 } |
515 } | 515 } |
516 | 516 |
517 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), | 517 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(), |
518 accessor.GetWidth() * sizeof(T), format, &image[0]); | 518 accessor.GetInformation().GetWidth() * sizeof(T), format, &image[0]); |
519 } | 519 } |
520 | 520 |
521 | 521 |
522 | 522 |
523 | 523 |
562 } | 562 } |
563 | 563 |
564 PixelFormat format; | 564 PixelFormat format; |
565 bool supported = false; | 565 bool supported = false; |
566 | 566 |
567 if (accessor->GetChannelCount() == 1) | 567 if (accessor->GetInformation().GetChannelCount() == 1) |
568 { | 568 { |
569 switch (mode) | 569 switch (mode) |
570 { | 570 { |
571 case ImageExtractionMode_Preview: | 571 case ImageExtractionMode_Preview: |
572 supported = true; | 572 supported = true; |
591 default: | 591 default: |
592 supported = false; | 592 supported = false; |
593 break; | 593 break; |
594 } | 594 } |
595 } | 595 } |
596 else if (accessor->GetChannelCount() == 3) | 596 else if (accessor->GetInformation().GetChannelCount() == 3) |
597 { | 597 { |
598 switch (mode) | 598 switch (mode) |
599 { | 599 { |
600 case ImageExtractionMode_Preview: | 600 case ImageExtractionMode_Preview: |
601 supported = true; | 601 supported = true; |
612 { | 612 { |
613 throw OrthancException(ErrorCode_NotImplemented); | 613 throw OrthancException(ErrorCode_NotImplemented); |
614 } | 614 } |
615 | 615 |
616 if (accessor.get() == NULL || | 616 if (accessor.get() == NULL || |
617 accessor->GetWidth() == 0 || | 617 accessor->GetInformation().GetWidth() == 0 || |
618 accessor->GetHeight() == 0) | 618 accessor->GetInformation().GetHeight() == 0) |
619 { | 619 { |
620 PngWriter w; | 620 PngWriter w; |
621 w.WriteToMemory(result, 0, 0, 0, format, NULL); | 621 w.WriteToMemory(result, 0, 0, 0, format, NULL); |
622 } | 622 } |
623 else | 623 else |