Mercurial > hg > orthanc
comparison OrthancFramework/Sources/Images/ImageProcessing.cpp @ 4529:5774fe497ff2
fix decoding of images on big-endian architectures
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Feb 2021 21:06:34 +0100 |
parents | 8421b3fc02d7 |
children | f9eda86f9045 |
comparison
equal
deleted
inserted
replaced
4528:93a51d228d80 | 4529:5774fe497ff2 |
---|---|
2634 } | 2634 } |
2635 } | 2635 } |
2636 } | 2636 } |
2637 } | 2637 } |
2638 } | 2638 } |
2639 | |
2640 | |
2641 void ImageProcessing::SwapEndianness(ImageAccessor& image /* inplace */) | |
2642 { | |
2643 const unsigned int width = image.GetWidth(); | |
2644 const unsigned int height = image.GetHeight(); | |
2645 | |
2646 switch (image.GetFormat()) | |
2647 { | |
2648 case PixelFormat_Grayscale8: | |
2649 case PixelFormat_RGB24: | |
2650 case PixelFormat_RGBA32: | |
2651 case PixelFormat_BGRA32: | |
2652 // No swapping required | |
2653 break; | |
2654 | |
2655 case PixelFormat_Grayscale16: | |
2656 case PixelFormat_SignedGrayscale16: | |
2657 for (unsigned int y = 0; y < height; y++) | |
2658 { | |
2659 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y)); | |
2660 for (unsigned int x = 0; x < width; x++) | |
2661 { | |
2662 uint8_t a = t[0]; | |
2663 t[0] = t[1]; | |
2664 t[1] = a; | |
2665 t += 2; | |
2666 } | |
2667 } | |
2668 break; | |
2669 | |
2670 case PixelFormat_Grayscale32: | |
2671 case PixelFormat_Float32: | |
2672 for (unsigned int y = 0; y < height; y++) | |
2673 { | |
2674 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y)); | |
2675 for (unsigned int x = 0; x < width; x++) | |
2676 { | |
2677 uint8_t a = t[0]; | |
2678 uint8_t b = t[1]; | |
2679 t[0] = t[3]; | |
2680 t[1] = t[2]; | |
2681 t[2] = b; | |
2682 t[3] = a; | |
2683 t += 4; | |
2684 } | |
2685 } | |
2686 break; | |
2687 | |
2688 case PixelFormat_RGB48: // uint16_t per channel | |
2689 for (unsigned int y = 0; y < height; y++) | |
2690 { | |
2691 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y)); | |
2692 for (unsigned int x = 0; x < 3 * width; x++) | |
2693 { | |
2694 uint8_t a = t[0]; | |
2695 t[0] = t[1]; | |
2696 t[1] = a; | |
2697 t += 2; | |
2698 } | |
2699 } | |
2700 break; | |
2701 | |
2702 default: | |
2703 throw OrthancException(ErrorCode_NotImplemented); | |
2704 } | |
2705 } | |
2639 } | 2706 } |