Skip to content

Commit

Permalink
Fix Accelerate.UnitTests. Fixes microsoft#1285.
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Jan 11, 2017
1 parent 9e4f794 commit 689ced2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build/Tests/UnitTests/Accelerate/Accelerate.UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<ProjectReference Include="..\..\..\Foundation\dll\Foundation.vcxproj">
<Project>{86127226-9A6E-439B-A070-420A572AF0C7}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\CoreFoundation\dll\CoreFoundation.vcxproj">
<Project>{81F30AF6-EAC3-4DFA-929A-C25D69E8080B}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\Logging\dll\Logging.vcxproj">
<Project>{862d36c2-cc83-4d04-b9b8-bef07f479905}</Project>
</ProjectReference>
Expand Down
17 changes: 13 additions & 4 deletions tests/unittests/Accelerate/vImageTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ static void vImageTestGetFormatFromCgImage(CGImageRef imageRef, vImage_CGImageFo
ASSERT_TRUE(imageRef != nullptr);

format->bitmapInfo = CGImageGetBitmapInfo(imageRef);
format->colorSpace = CGImageGetColorSpace(imageRef);
format->colorSpace = CGColorSpaceRetain(CGImageGetColorSpace(imageRef));
format->bitsPerComponent = (uint32_t)CGImageGetBitsPerComponent(imageRef);

const uint32_t alphaInfo = format->bitmapInfo & kCGBitmapAlphaInfoMask;
Expand Down Expand Up @@ -821,7 +821,7 @@ static void vImageTestSetAlphaAndUnpremultiply(CGImageRef imageRef, vImage_Buffe
vImageTestBufferFree(&rgbDest);
}

DISABLED_TEST(Accelerate, AlphaUnpremultiply) {
TEST(Accelerate, AlphaUnpremultiply) {
SetCACompositor(new NullCompositor);

char fullPath[_MAX_PATH];
Expand All @@ -831,14 +831,23 @@ static void vImageTestSetAlphaAndUnpremultiply(CGImageRef imageRef, vImage_Buffe
strncpy(executablePath, relativePathToPhoto, strlen(relativePathToPhoto) + 1);
UIImage* photo = [UIImage imageNamed:[NSString stringWithCString:fullPath]];

woc::unique_cf<CGColorSpaceRef> rgbColorSpace(CGColorSpaceCreateDeviceRGB());
woc::unique_cf<CGContextRef> rgbaConversionContext{
CGBitmapContextCreate(nullptr, photo.size.width, photo.size.height, 8, photo.size.width * 4, rgbColorSpace.get(), kCGBitmapByteOrder32Big | kCGImageAlphaLast)
};
CGContextDrawImage(rgbaConversionContext.get(), {CGPointZero, photo.size}, photo.CGImage);
woc::unique_cf<CGImageRef> rgbaImage{
CGBitmapContextCreateImage(rgbaConversionContext.get())
};

vImage_Buffer unpremultipliedBufferSimd, unpremultipliedBufferNormal;
const uint8_t alphaVal = 0x80;

_vImageSetSimdOptmizationsState(false);
vImageTestSetAlphaAndUnpremultiply(photo.CGImage, &unpremultipliedBufferNormal, alphaVal);
vImageTestSetAlphaAndUnpremultiply(rgbaImage.get(), &unpremultipliedBufferNormal, alphaVal);

_vImageSetSimdOptmizationsState(true);
vImageTestSetAlphaAndUnpremultiply(photo.CGImage, &unpremultipliedBufferSimd, alphaVal);
vImageTestSetAlphaAndUnpremultiply(rgbaImage.get(), &unpremultipliedBufferSimd, alphaVal);

ASSERT_TRUE_MSG(vImageTestCompare8888Buffers(&unpremultipliedBufferSimd, &unpremultipliedBufferNormal),
"SIMD and non-SIMD output of AlphaUnpremultiply do not match");
Expand Down

0 comments on commit 689ced2

Please sign in to comment.