comparison Core/Images/ImageProcessing.cpp @ 3547:dabe17e23e23

Copy RGBA to BGRA & Set with alpha
author Alain Mazy <alain@mazy.be>
date Tue, 22 Oct 2019 17:30:43 +0200
parents 551945086617
children e1ce68692069 fab5777f4dd4
comparison
equal deleted inserted replaced
3546:460ba650be6f 3547:dabe17e23e23
801 } 801 }
802 802
803 return; 803 return;
804 } 804 }
805 805
806 if ((target.GetFormat() == PixelFormat_BGRA32 &&
807 source.GetFormat() == PixelFormat_RGBA32)
808 || (target.GetFormat() == PixelFormat_RGBA32 &&
809 source.GetFormat() == PixelFormat_BGRA32))
810 {
811 for (unsigned int y = 0; y < height; y++)
812 {
813 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
814 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
815 for (unsigned int x = 0; x < width; x++)
816 {
817 q[0] = p[2];
818 q[1] = p[1];
819 q[2] = p[0];
820 q[3] = p[3];
821 p += 4;
822 q += 4;
823 }
824 }
825
826 return;
827 }
828
806 if (target.GetFormat() == PixelFormat_RGB24 && 829 if (target.GetFormat() == PixelFormat_RGB24 &&
807 source.GetFormat() == PixelFormat_RGB48) 830 source.GetFormat() == PixelFormat_RGB48)
808 { 831 {
809 for (unsigned int y = 0; y < height; y++) 832 for (unsigned int y = 0; y < height; y++)
810 { 833 {
938 { 961 {
939 q[i] = p[i]; 962 q[i] = p[i];
940 } 963 }
941 964
942 q += size; 965 q += size;
966 }
967 }
968 }
969
970 void ImageProcessing::Set(ImageAccessor& image,
971 uint8_t red,
972 uint8_t green,
973 uint8_t blue,
974 ImageAccessor& alpha)
975 {
976 uint8_t p[4];
977
978 if (alpha.GetWidth() != image.GetWidth() || alpha.GetHeight() != image.GetHeight())
979 {
980 throw OrthancException(ErrorCode_IncompatibleImageSize);
981 }
982
983 if (alpha.GetFormat() != PixelFormat_Grayscale8)
984 {
985 throw OrthancException(ErrorCode_NotImplemented);
986 }
987
988 switch (image.GetFormat())
989 {
990 case PixelFormat_RGBA32:
991 p[0] = red;
992 p[1] = green;
993 p[2] = blue;
994 break;
995
996 case PixelFormat_BGRA32:
997 p[0] = blue;
998 p[1] = green;
999 p[2] = red;
1000 break;
1001
1002 default:
1003 throw OrthancException(ErrorCode_NotImplemented);
1004 }
1005
1006 const unsigned int width = image.GetWidth();
1007 const unsigned int height = image.GetHeight();
1008
1009 for (unsigned int y = 0; y < height; y++)
1010 {
1011 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y));
1012 uint8_t* a = reinterpret_cast<uint8_t*>(alpha.GetRow(y));
1013
1014 for (unsigned int x = 0; x < width; x++)
1015 {
1016 for (unsigned int i = 0; i < 3; i++)
1017 {
1018 q[i] = p[i];
1019 }
1020 q[3] = *a;
1021 q += 4;
1022 ++a;
943 } 1023 }
944 } 1024 }
945 } 1025 }
946 1026
947 1027