37wxImage makeOpaquePixel(
unsigned char aR,
unsigned char aG,
unsigned char aB )
40 img.SetRGB( 0, 0, aR, aG, aB );
47unsigned char compositeOver(
int aColour,
int aAlpha,
int aBackground )
49 return ( aColour * aAlpha + aBackground * ( 255 - aAlpha ) ) / 255;
56void checkPixelRGBA(
const wxImage& aImage,
int aX,
int aY,
int aR,
int aG,
int aB,
int aA )
61 <<
static_cast<int>( aImage.GetRed( aX, aY ) ) <<
", "
62 <<
static_cast<int>( aImage.GetGreen( aX, aY ) ) <<
", "
63 <<
static_cast<int>( aImage.GetBlue( aX, aY ) ) <<
", "
64 <<
static_cast<int>( aImage.GetAlpha( aX, aY ) )
65 <<
"), expected rgba(" << aR <<
", " << aG <<
", " << aB <<
", " << aA
83 const wxImage onWhite = makeOpaquePixel( 255, 0, 0 );
84 const wxImage onBlack = onWhite;
92 checkPixelRGBA(
image, 0, 0, 255, 0, 0, 255 );
99 const wxImage onWhite = makeOpaquePixel( 255, 255, 255 );
100 const wxImage onBlack = makeOpaquePixel( 0, 0, 0 );
108 checkPixelRGBA(
image, 0, 0, 0, 0, 0, 0 );
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 );
static bool empty(const wxTextEntryBase *aCtrl)
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.
void ConvertColourToAlphaInPlace(wxImage &aImage, const wxColour &aColour)
Apply the "Color to Alpha" algorithm in place, converting aColour to transparent.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
BOOST_AUTO_TEST_CASE(OpaquePixelIsPreserved)
BOOST_TEST_CONTEXT("Test Clearance")
static wxString render(const std::vector< TEXT_DIFF_LINE > &aLines)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")