comparison Orthanc/Core/Images/ImageProcessing.cpp @ 131:f6c88aa6efe0

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 31 May 2016 12:11:58 +0200
parents 3809121c3290
children 2fffa4d0f313
comparison
equal deleted inserted replaced
128:e8cfda4c8a2f 131:f6c88aa6efe0
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 assert(sizeof(float) == 4);
83
84 for (unsigned int y = 0; y < source.GetHeight(); y++)
85 {
86 float* t = reinterpret_cast<float*>(target.GetRow(y));
87 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
88
89 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++)
90 {
91 *t = static_cast<float>(*s);
92 }
93 }
94 }
95
96
78 template <typename TargetType> 97 template <typename TargetType>
79 static void ConvertColorToGrayscale(ImageAccessor& target, 98 static void ConvertColorToGrayscale(ImageAccessor& target,
80 const ImageAccessor& source) 99 const ImageAccessor& source)
81 { 100 {
82 assert(source.GetFormat() == PixelFormat_RGB24); 101 assert(source.GetFormat() == PixelFormat_RGB24);
83 102
84 const TargetType minValue = std::numeric_limits<TargetType>::min(); 103 const TargetType minValue = std::numeric_limits<TargetType>::min();
85 const TargetType maxValue = std::numeric_limits<TargetType>::max(); 104 const TargetType maxValue = std::numeric_limits<TargetType>::max();
376 { 395 {
377 ConvertColorToGrayscale<int16_t>(target, source); 396 ConvertColorToGrayscale<int16_t>(target, source);
378 return; 397 return;
379 } 398 }
380 399
400 if (target.GetFormat() == PixelFormat_Float32 &&
401 source.GetFormat() == PixelFormat_Grayscale8)
402 {
403 ConvertGrayscaleToFloat<uint8_t>(target, source);
404 return;
405 }
406
407 if (target.GetFormat() == PixelFormat_Float32 &&
408 source.GetFormat() == PixelFormat_Grayscale16)
409 {
410 ConvertGrayscaleToFloat<uint16_t>(target, source);
411 return;
412 }
413
414 if (target.GetFormat() == PixelFormat_Float32 &&
415 source.GetFormat() == PixelFormat_SignedGrayscale16)
416 {
417 ConvertGrayscaleToFloat<int16_t>(target, source);
418 return;
419 }
420
381 if (target.GetFormat() == PixelFormat_Grayscale8 && 421 if (target.GetFormat() == PixelFormat_Grayscale8 &&
382 source.GetFormat() == PixelFormat_RGBA32) 422 source.GetFormat() == PixelFormat_RGBA32)
383 { 423 {
384 for (unsigned int y = 0; y < source.GetHeight(); y++) 424 for (unsigned int y = 0; y < source.GetHeight(); y++)
385 { 425 {
436 } 476 }
437 477
438 return; 478 return;
439 } 479 }
440 480
481 if (target.GetFormat() == PixelFormat_RGB24 &&
482 source.GetFormat() == PixelFormat_Grayscale8)
483 {
484 for (unsigned int y = 0; y < source.GetHeight(); y++)
485 {
486 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
487 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
488 for (unsigned int x = 0; x < source.GetWidth(); x++)
489 {
490 q[0] = *p;
491 q[1] = *p;
492 q[2] = *p;
493 p += 1;
494 q += 3;
495 }
496 }
497
498 return;
499 }
500
501 if (target.GetFormat() == PixelFormat_RGBA32 &&
502 source.GetFormat() == PixelFormat_Grayscale8)
503 {
504 for (unsigned int y = 0; y < source.GetHeight(); y++)
505 {
506 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
507 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
508 for (unsigned int x = 0; x < source.GetWidth(); x++)
509 {
510 q[0] = *p;
511 q[1] = *p;
512 q[2] = *p;
513 q[3] = 255;
514 p += 1;
515 q += 4;
516 }
517 }
518
519 return;
520 }
521
441 throw OrthancException(ErrorCode_NotImplemented); 522 throw OrthancException(ErrorCode_NotImplemented);
442 } 523 }
443 524
444 525
445 526
456 SetInternal<uint16_t>(image, value); 537 SetInternal<uint16_t>(image, value);
457 return; 538 return;
458 539
459 case PixelFormat_SignedGrayscale16: 540 case PixelFormat_SignedGrayscale16:
460 SetInternal<int16_t>(image, value); 541 SetInternal<int16_t>(image, value);
542 return;
543
544 case PixelFormat_Float32:
545 assert(sizeof(float) == 4);
546 SetInternal<float>(image, value);
461 return; 547 return;
462 548
463 default: 549 default:
464 throw OrthancException(ErrorCode_NotImplemented); 550 throw OrthancException(ErrorCode_NotImplemented);
465 } 551 }