Mercurial > hg > orthanc-webviewer
comparison Orthanc/Core/Images/ImageProcessing.cpp @ 129:2c73a785c08e
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 14 May 2016 16:39:55 +0200 |
parents | 3809121c3290 |
children | 2fffa4d0f313 |
comparison
equal
deleted
inserted
replaced
128:e8cfda4c8a2f | 129:2c73a785c08e |
---|---|
73 } | 73 } |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 template <typename SourceType> | |
79 static void ConvertGrayscaleToFloat(ImageAccessor& target, | |
80 const ImageAccessor& source) | |
81 { | |
82 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
83 { | |
84 float* t = reinterpret_cast<float*>(target.GetRow(y)); | |
85 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); | |
86 | |
87 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) | |
88 { | |
89 *t = static_cast<float>(*s); | |
90 } | |
91 } | |
92 } | |
93 | |
94 | |
78 template <typename TargetType> | 95 template <typename TargetType> |
79 static void ConvertColorToGrayscale(ImageAccessor& target, | 96 static void ConvertColorToGrayscale(ImageAccessor& target, |
80 const ImageAccessor& source) | 97 const ImageAccessor& source) |
81 { | 98 { |
82 assert(source.GetFormat() == PixelFormat_RGB24); | 99 assert(source.GetFormat() == PixelFormat_RGB24); |
83 | 100 |
84 const TargetType minValue = std::numeric_limits<TargetType>::min(); | 101 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
85 const TargetType maxValue = std::numeric_limits<TargetType>::max(); | 102 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
376 { | 393 { |
377 ConvertColorToGrayscale<int16_t>(target, source); | 394 ConvertColorToGrayscale<int16_t>(target, source); |
378 return; | 395 return; |
379 } | 396 } |
380 | 397 |
398 if (target.GetFormat() == PixelFormat_Float32 && | |
399 source.GetFormat() == PixelFormat_Grayscale8) | |
400 { | |
401 ConvertGrayscaleToFloat<uint8_t>(target, source); | |
402 return; | |
403 } | |
404 | |
405 if (target.GetFormat() == PixelFormat_Float32 && | |
406 source.GetFormat() == PixelFormat_Grayscale16) | |
407 { | |
408 ConvertGrayscaleToFloat<uint16_t>(target, source); | |
409 return; | |
410 } | |
411 | |
412 if (target.GetFormat() == PixelFormat_Float32 && | |
413 source.GetFormat() == PixelFormat_SignedGrayscale16) | |
414 { | |
415 ConvertGrayscaleToFloat<int16_t>(target, source); | |
416 return; | |
417 } | |
418 | |
381 if (target.GetFormat() == PixelFormat_Grayscale8 && | 419 if (target.GetFormat() == PixelFormat_Grayscale8 && |
382 source.GetFormat() == PixelFormat_RGBA32) | 420 source.GetFormat() == PixelFormat_RGBA32) |
383 { | 421 { |
384 for (unsigned int y = 0; y < source.GetHeight(); y++) | 422 for (unsigned int y = 0; y < source.GetHeight(); y++) |
385 { | 423 { |
436 } | 474 } |
437 | 475 |
438 return; | 476 return; |
439 } | 477 } |
440 | 478 |
479 if (target.GetFormat() == PixelFormat_RGB24 && | |
480 source.GetFormat() == PixelFormat_Grayscale8) | |
481 { | |
482 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
483 { | |
484 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); | |
485 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
486 for (unsigned int x = 0; x < source.GetWidth(); x++) | |
487 { | |
488 q[0] = *p; | |
489 q[1] = *p; | |
490 q[2] = *p; | |
491 p += 1; | |
492 q += 3; | |
493 } | |
494 } | |
495 | |
496 return; | |
497 } | |
498 | |
499 if (target.GetFormat() == PixelFormat_RGBA32 && | |
500 source.GetFormat() == PixelFormat_Grayscale8) | |
501 { | |
502 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
503 { | |
504 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); | |
505 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
506 for (unsigned int x = 0; x < source.GetWidth(); x++) | |
507 { | |
508 q[0] = *p; | |
509 q[1] = *p; | |
510 q[2] = *p; | |
511 q[3] = 255; | |
512 p += 1; | |
513 q += 4; | |
514 } | |
515 } | |
516 | |
517 return; | |
518 } | |
519 | |
441 throw OrthancException(ErrorCode_NotImplemented); | 520 throw OrthancException(ErrorCode_NotImplemented); |
442 } | 521 } |
443 | 522 |
444 | 523 |
445 | 524 |