3434namespace Diligent
3535{
3636
37- void GetImageDifference (const GetImageDifferenceAttribs & Attribs,
38- ImageDiffInfo& Diff)
37+ void ComputeImageDifference (const ComputeImageDifferenceAttribs & Attribs,
38+ ImageDiffInfo& Diff)
3939{
4040 Diff = {};
4141
@@ -68,21 +68,45 @@ void GetImageDifference(const GetImageDifferenceAttribs& Attribs,
6868 return ;
6969 }
7070
71- const Uint32 NumChannels = std::min (Attribs.NumChannels1 , Attribs.NumChannels2 );
71+ const Uint32 NumSrcChannels = std::min (Attribs.NumChannels1 , Attribs.NumChannels2 );
72+ const Uint32 NumDiffChannels = Attribs.NumDiffChannels != 0 ? Attribs.NumDiffChannels : NumSrcChannels;
73+ if (Attribs.pDiffImage != nullptr )
74+ {
75+ if (Attribs.DiffStride < Attribs.Width * NumDiffChannels)
76+ {
77+ UNEXPECTED (" DiffStride is too small. It must be at least " , Attribs.Width * NumDiffChannels, " bytes long." );
78+ return ;
79+ }
80+ }
81+
7282 for (Uint32 row = 0 ; row < Attribs.Height ; ++row)
7383 {
74- const Uint8* pRow1 = reinterpret_cast <const Uint8*>(Attribs.pImage1 ) + row * Attribs.Stride1 ;
75- const Uint8* pRow2 = reinterpret_cast <const Uint8*>(Attribs.pImage2 ) + row * Attribs.Stride2 ;
84+ const Uint8* pRow1 = reinterpret_cast <const Uint8*>(Attribs.pImage1 ) + row * Attribs.Stride1 ;
85+ const Uint8* pRow2 = reinterpret_cast <const Uint8*>(Attribs.pImage2 ) + row * Attribs.Stride2 ;
86+ Uint8* pDiffRow = Attribs.pDiffImage != nullptr ? reinterpret_cast <Uint8*>(Attribs.pDiffImage ) + row * Attribs.DiffStride : nullptr ;
7687
7788 for (Uint32 col = 0 ; col < Attribs.Width ; ++col)
7889 {
7990 Uint32 PixelDiff = 0 ;
80- for (Uint32 ch = 0 ; ch < NumChannels ; ++ch)
91+ for (Uint32 ch = 0 ; ch < NumSrcChannels ; ++ch)
8192 {
8293 const Uint32 ChannelDiff = static_cast <Uint32>(
8394 std::abs (static_cast <int >(pRow1[col * Attribs.NumChannels1 + ch]) -
8495 static_cast <int >(pRow2[col * Attribs.NumChannels2 + ch])));
8596 PixelDiff = std::max (PixelDiff, ChannelDiff);
97+
98+ if (pDiffRow != nullptr && ch < NumDiffChannels)
99+ {
100+ pDiffRow[col * NumDiffChannels + ch] = static_cast <Uint8>(std::min (ChannelDiff * Attribs.Scale , 255 .f ));
101+ }
102+ }
103+
104+ if (pDiffRow != nullptr )
105+ {
106+ for (Uint32 ch = NumSrcChannels; ch < NumDiffChannels; ++ch)
107+ {
108+ pDiffRow[col * NumDiffChannels + ch] = ch == 3 ? 255 : 0 ;
109+ }
86110 }
87111
88112 if (PixelDiff != 0 )
@@ -107,79 +131,13 @@ void GetImageDifference(const GetImageDifferenceAttribs& Attribs,
107131 }
108132}
109133
110- void ComputeDifferenceImage (const ComputeDifferenceImageAttribs& Attribs)
111- {
112- if (Attribs.pImage1 == nullptr || Attribs.pImage2 == nullptr || Attribs.pDiffImage == nullptr )
113- {
114- UNEXPECTED (" Image pointers cannot be null" );
115- return ;
116- }
117-
118- if (Attribs.NumChannels1 == 0 )
119- {
120- UNEXPECTED (" NumChannels1 cannot be zero" );
121- return ;
122- }
123- if (Attribs.Stride1 < Attribs.Width * Attribs.NumChannels1 )
124- {
125- UNEXPECTED (" Stride1 is too small. It must be at least " , Attribs.Width * Attribs.NumChannels1 , " bytes long." );
126- return ;
127- }
128-
129- if (Attribs.NumChannels2 == 0 )
130- {
131- UNEXPECTED (" NumChannels2 cannot be zero" );
132- return ;
133- }
134- if (Attribs.Stride2 < Attribs.Width * Attribs.NumChannels2 )
135- {
136- UNEXPECTED (" Stride2 is too small. It must be at least " , Attribs.Width * Attribs.NumChannels2 , " bytes long." );
137- return ;
138- }
139-
140- const Uint32 NumSrcChannels = std::min (Attribs.NumChannels1 , Attribs.NumChannels2 );
141- const Uint32 NumDiffChannels = Attribs.NumDiffChannels != 0 ? Attribs.NumDiffChannels : NumSrcChannels;
142- if (Attribs.DiffStride < Attribs.Width * NumDiffChannels)
143- {
144- UNEXPECTED (" DiffStride is too small. It must be at least " , Attribs.Width * NumDiffChannels, " bytes long." );
145- return ;
146- }
147-
148- for (Uint32 row = 0 ; row < Attribs.Height ; ++row)
149- {
150- const Uint8* pRow1 = reinterpret_cast <const Uint8*>(Attribs.pImage1 ) + row * Attribs.Stride1 ;
151- const Uint8* pRow2 = reinterpret_cast <const Uint8*>(Attribs.pImage2 ) + row * Attribs.Stride2 ;
152- Uint8* pDiffRow = reinterpret_cast <Uint8*>(Attribs.pDiffImage ) + row * Attribs.DiffStride ;
153-
154- for (Uint32 col = 0 ; col < Attribs.Width ; ++col)
155- {
156- for (Uint32 ch = 0 ; ch < NumDiffChannels; ++ch)
157- {
158- int ChannelDiff = ch == 3 ? 255 : 0 ;
159- if (ch < NumSrcChannels)
160- {
161- ChannelDiff = std::abs (static_cast <int >(pRow1[col * Attribs.NumChannels1 + ch]) -
162- static_cast <int >(pRow2[col * Attribs.NumChannels2 + ch]));
163- ChannelDiff = std::min (255 , static_cast <int >(ChannelDiff * Attribs.Scale ));
164- }
165- pDiffRow[col * NumDiffChannels + ch] = static_cast <Uint8>(ChannelDiff);
166- }
167- }
168- }
169- }
170-
171134} // namespace Diligent
172135
173136extern " C"
174137{
175- void Diligent_GetImageDifference (const Diligent::GetImageDifferenceAttribs& Attribs,
176- Diligent::ImageDiffInfo& ImageDiff)
177- {
178- Diligent::GetImageDifference (Attribs, ImageDiff);
179- }
180-
181- void Diligent_ComputeDifferenceImage (const Diligent::ComputeDifferenceImageAttribs& Attribs)
138+ void Diligent_ComputeImageDifference (const Diligent::ComputeImageDifferenceAttribs& Attribs,
139+ Diligent::ImageDiffInfo& ImageDiff)
182140 {
183- Diligent::ComputeDifferenceImage (Attribs);
141+ Diligent::ComputeImageDifference (Attribs, ImageDiff );
184142 }
185143}
0 commit comments