40 img.SetRGB( 0, 0, aR, aG, aB );
83 const wxImage onWhite = makeOpaquePixel( 255, 0, 0 );
84 const wxImage onBlack = onWhite;
92 checkPixelRGBA(
image, 0, 0, 255, 0, 0, 255 );
116 const wxImage onWhite = makeOpaquePixel( 255, 128, 128 );
117 const wxImage onBlack = makeOpaquePixel( 128, 0, 0 );
119 const tl::expected<wxImage, std::string>
result =
126 checkPixelRGBA(
image, 0, 0, 255, 0, 0, 128 );
137 unsigned char r, g, b, a;
140 const std::vector<PIXEL> cases = {
145 { 200, 100, 50, 80 },
146 { 255, 255, 255, 30 },
150 const auto checkNear =
151 [](
int a,
int b,
const char* channel )
153 BOOST_TEST_INFO(
"channel " << channel <<
": got " << a <<
", expected " << b );
154 BOOST_CHECK( a >= b - 1 && a <= b + 1 );
157 for(
const PIXEL& pix : cases )
159 BOOST_TEST_CONTEXT(
"rgba(" << pix.r <<
", " << pix.g <<
", " << pix.b <<
", " << pix.a <<
")" )
161 const wxImage onWhite = makeOpaquePixel( compositeOver( pix.r, pix.a, 255 ),
162 compositeOver( pix.g, pix.a, 255 ),
163 compositeOver( pix.b, pix.a, 255 ) );
164 const wxImage onBlack = makeOpaquePixel( compositeOver( pix.r, pix.a, 0 ),
165 compositeOver( pix.g, pix.a, 0 ),
166 compositeOver( pix.b, pix.a, 0 ) );
177 const int alpha =
image.GetAlpha( 0, 0 );
178 BOOST_CHECK( alpha >= pix.a - 1 && alpha <= pix.a + 1 );
181 for(
const int bg : { 255, 0 } )
183 const wxImage& render = bg ? onWhite : onBlack;
185 checkNear( compositeOver(
image.GetRed( 0, 0 ), alpha, bg ), render.GetRed( 0, 0 ),
"red" );
186 checkNear( compositeOver(
image.GetGreen( 0, 0 ), alpha, bg ), render.GetGreen( 0, 0 ),
"green" );
187 checkNear( compositeOver(
image.GetBlue( 0, 0 ), alpha, bg ), render.GetBlue( 0, 0 ),
"blue" );
197 const wxImage pixel = makeOpaquePixel( 0, 0, 0 );
199 wxImage wide( 2, 1 );
200 wide.SetRGB( 0, 0, 0, 0, 0 );
201 wide.SetRGB( 1, 0, 0, 0, 0 );
204 BOOST_CHECK( !emptyInput.has_value() );
205 BOOST_CHECK( !emptyInput.error().empty() );
208 BOOST_CHECK( !emptyInput2.has_value() );
209 BOOST_CHECK( !emptyInput2.error().empty() );
212 BOOST_CHECK( !sizeMismatch.has_value() );
213 BOOST_CHECK( !sizeMismatch.error().empty() );
224 img.SetRGB( 0, 0, 255, 255, 255 );
225 img.SetRGB( 1, 0, 42, 42, 42 );
226 img.SetRGB( 2, 0, 0, 0, 0 );
tl::expected< wxImage, std::string > CreateAlphaImageFromTwoRenders(const wxImage &aOnWhite, const wxImage &aOnBlack)
Combine two opaque renders of the same content into a single image with an alpha channel.
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")