diff --git a/Frameworks/CoreGraphics/CGContext.mm b/Frameworks/CoreGraphics/CGContext.mm index 54f72f6405..9aa7b1af23 100644 --- a/Frameworks/CoreGraphics/CGContext.mm +++ b/Frameworks/CoreGraphics/CGContext.mm @@ -2145,12 +2145,19 @@ void CGContextDrawGlyphRun(CGContextRef context, const DWRITE_GLYPH_RUN* glyphRu struct __CGBitmapContext : CoreFoundation::CppBase<__CGBitmapContext, __CGContext> { woc::unique_cf _image; - __CGBitmapContext(ID2D1RenderTarget* renderTarget) : Parent(renderTarget) { + __CGBitmapContext(ID2D1RenderTarget* renderTarget, REFWICPixelFormatGUID outputPixelFormat) : Parent(renderTarget), _outputPixelFormat(outputPixelFormat) { } inline void SetImage(CGImageRef image) { _image.reset(CGImageRetain(image)); } + + inline REFWICPixelFormatGUID GetOutputPixelFormat() const { + return _outputPixelFormat; + } + +private: + WICPixelFormatGUID _outputPixelFormat; }; /** @@ -2187,11 +2194,15 @@ CGContextRef CGBitmapContextCreateWithData(void* data, // bitsperpixel = ((bytesPerRow/width) * 8bits/byte) size_t bitsPerPixel = ((bytesPerRow / width) << 3); - REFGUID pixelFormat = _CGImageGetWICPixelFormatFromImageProperties(bitsPerComponent, bitsPerPixel, space, bitmapInfo); + REFWICPixelFormatGUID outputPixelFormat = _CGImageGetWICPixelFormatFromImageProperties(bitsPerComponent, bitsPerPixel, space, bitmapInfo); + WICPixelFormatGUID pixelFormat = outputPixelFormat; if (!_CGIsValidRenderTargetPixelFormat(pixelFormat)) { - UNIMPLEMENTED_WITH_MSG("CGBitmapContext does not currently support conversion and can only render into 32bpp PRGBA buffers."); - return nullptr; + if (data) { + UNIMPLEMENTED_WITH_MSG("CGBitmapContext does not currently support input conversion and can only render into 32bpp PRGBA buffers."); + return nullptr; + } + pixelFormat = GUID_WICPixelFormat32bppPRGBA; } // if data is null, enough memory is allocated via CGIWICBitmap @@ -2206,7 +2217,8 @@ CGContextRef CGBitmapContextCreateWithData(void* data, ComPtr renderTarget; RETURN_NULL_IF_FAILED(factory->CreateWicBitmapRenderTarget(customBitmap.Get(), D2D1::RenderTargetProperties(), &renderTarget)); - return _CGBitmapContextCreateWithRenderTarget(renderTarget.Get(), image.get()); + CGContextRef context = _CGBitmapContextCreateWithRenderTarget(renderTarget.Get(), image.get(), outputPixelFormat); + return context; } /** @@ -2288,7 +2300,14 @@ size_t CGBitmapContextGetBytesPerRow(CGContextRef context) { */ CGImageRef CGBitmapContextCreateImage(CGContextRef context) { NOISY_RETURN_IF_NULL(context, nullptr); - return CGImageCreateCopy(CGBitmapContextGetImage(context)); + if (CFGetTypeID(context) != __CGBitmapContext::GetTypeID()) { + TraceError(TAG, L"Image requested from non-bitmap CGContext."); + return nullptr; + } + + // This copy is a no-op if the output format requested matches the backing image format. + __CGBitmapContext* bitmapContext = (__CGBitmapContext*)context; + return _CGImageCreateCopyWithPixelFormat(bitmapContext->_image.get(), bitmapContext->GetOutputPixelFormat()); } CGImageRef CGBitmapContextGetImage(CGContextRef context) { @@ -2300,9 +2319,9 @@ CGImageRef CGBitmapContextGetImage(CGContextRef context) { return ((__CGBitmapContext*)context)->_image.get(); } -CGContextRef _CGBitmapContextCreateWithRenderTarget(ID2D1RenderTarget* renderTarget, CGImageRef img) { +CGContextRef _CGBitmapContextCreateWithRenderTarget(ID2D1RenderTarget* renderTarget, CGImageRef img, WICPixelFormatGUID outputPixelFormat) { RETURN_NULL_IF(!renderTarget); - __CGBitmapContext* context = __CGBitmapContext::CreateInstance(kCFAllocatorDefault, renderTarget); + __CGBitmapContext* context = __CGBitmapContext::CreateInstance(kCFAllocatorDefault, renderTarget, outputPixelFormat); __CGContextPrepareDefaults(context); context->SetImage(img); return context; diff --git a/Frameworks/ImageIO/CGImageDestination.mm b/Frameworks/ImageIO/CGImageDestination.mm index 9e7bc97749..7a6d28deb1 100644 --- a/Frameworks/ImageIO/CGImageDestination.mm +++ b/Frameworks/ImageIO/CGImageDestination.mm @@ -18,6 +18,7 @@ #import #import "CGImageDestinationInternal.h" #import +#import #include #include @@ -979,6 +980,14 @@ void CGImageDestinationAddImage(CGImageDestinationRef idst, CGImageRef image, CF } } + // Turn image into a WIC Bitmap + ComPtr inputImage; + status = _CGImageGetWICImageSource(image, &inputImage); + if (!SUCCEEDED(status)) { + NSTraceInfo(TAG, @"_CGImageGetWICImageSource failed with status=%x\n", status); + return; + } + IWICMetadataQueryWriter* propertyWriter = imageFrameMetadataWriter.Get(); // Set the pixel format based on file format and write necessary metadata @@ -998,7 +1007,11 @@ void CGImageDestinationAddImage(CGImageDestinationRef idst, CGImageRef image, CF writeGIFProperties(propertyWriter, properties, imageWidth, imageHeight); break; case typePNG: - formatGUID = GUID_WICPixelFormat32bppRGBA; + status = inputImage->GetPixelFormat(&formatGUID); + if (!SUCCEEDED(status)) { + NSTraceInfo(TAG, @"Get Image Source Pixel Format failed with status=%x\n", status); + return; + } writePNGProperties(propertyWriter, properties, imageWidth, imageHeight); break; case typeBMP: @@ -1015,27 +1028,6 @@ void CGImageDestinationAddImage(CGImageDestinationRef idst, CGImageRef image, CF return; } - CGDataProviderRef provider = CGImageGetDataProvider(image); - NSData* imageByteData = (id)CGDataProviderCopyData(provider); - - // Turn image into a WIC Bitmap - ComPtr inputImage; - - // All our input coming in from CGImagesource is in 32bppRGBA - ComPtr imageFactory = imageDestination.idFactory; - status = imageFactory->CreateBitmapFromMemory(imageWidth, - imageHeight, - GUID_WICPixelFormat32bppRGBA, - imageWidth * 4, - imageHeight * imageWidth * 4, - (unsigned char*)[imageByteData bytes], - &inputImage); - [imageByteData release]; - if (!SUCCEEDED(status)) { - NSTraceInfo(TAG, @"CreateBitmapFromMemory failed with status=%x\n", status); - return; - } - ComPtr inputBitmapSource; status = WICConvertBitmapSource(formatGUID, inputImage.Get(), &inputBitmapSource); if (!SUCCEEDED(status)) { diff --git a/Frameworks/ImageIO/CGImageSource.mm b/Frameworks/ImageIO/CGImageSource.mm index 29999661f4..3a8d7eb1f6 100644 --- a/Frameworks/ImageIO/CGImageSource.mm +++ b/Frameworks/ImageIO/CGImageSource.mm @@ -31,6 +31,8 @@ #include #include "COMIncludes_End.h" +#import + using namespace Microsoft::WRL; static const wchar_t* TAG = L"CGImageSource"; @@ -1684,48 +1686,10 @@ CGImageRef CGImageSourceCreateImageAtIndex(CGImageSourceRef isrc, size_t index, ComPtr imageFrame; RETURN_NULL_IF_FAILED(imageDecoder->GetFrame(index, &imageFrame)); - unsigned int frameWidth = 0; - unsigned int frameHeight = 0; - RETURN_NULL_IF_FAILED(imageFrame->GetSize(&frameWidth, &frameHeight)); - - ComPtr imageFormatConverter; - RETURN_NULL_IF_FAILED(imageFactory->CreateFormatConverter(&imageFormatConverter)); - - if (options && CFDictionaryContainsKey(options, kCGImageSourceShouldAllowFloat)) { - UNIMPLEMENTED_WITH_MSG("kCGImageSourceShouldAllowFloat is not supported in current implementation."); - } + ComPtr imageBitmap; + RETURN_NULL_IF_FAILED(imageFactory->CreateBitmapFromSource(imageFrame.Get(), WICBitmapCacheOnDemand, &imageBitmap)); - RETURN_NULL_IF_FAILED(imageFormatConverter->Initialize( - imageFrame.Get(), GUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeNone, nullptr, 0.f, WICBitmapPaletteTypeCustom)); - - const unsigned int frameSize = frameWidth * frameHeight * 4; - unsigned char* frameByteArray = static_cast(IwMalloc(frameSize)); - if (!frameByteArray) { - NSTraceInfo(TAG, @"CGImageSourceCreateImageAtIndex cannot allocate memory"); - return nullptr; - } - - auto cleanup = wil::ScopeExit([&]() { IwFree(frameByteArray); }); - RETURN_NULL_IF_FAILED(imageFormatConverter->CopyPixels(0, frameWidth * 4, frameSize, frameByteArray)); - cleanup.Dismiss(); - - NSData* frameData = [NSData dataWithBytesNoCopy:frameByteArray length:frameSize freeWhenDone:YES]; - CGDataProviderRef frameDataProvider = CGDataProviderCreateWithCFData((CFDataRef)frameData); - CGColorSpaceRef colorspaceRgb = CGColorSpaceCreateDeviceRGB(); - CGImageRef imageRef = CGImageCreate(frameWidth, - frameHeight, - 8, - 32, - frameWidth * 4, - colorspaceRgb, - kCGImageAlphaLast, - frameDataProvider, - nullptr, - true, - kCGRenderingIntentDefault); - CGDataProviderRelease(frameDataProvider); - CGColorSpaceRelease(colorspaceRgb); - return imageRef; + return _CGImageCreateWithWICBitmap(imageBitmap.Get()); } /** @@ -1825,37 +1789,10 @@ CGImageRef CGImageSourceCreateThumbnailAtIndex(CGImageSourceRef isrc, size_t ind UNIMPLEMENTED_WITH_MSG("kCGImageSourceShouldAllowFloat is not supported in current implementation."); } - RETURN_NULL_IF_FAILED(imageFormatConverter->Initialize( - imageScaler.Get(), GUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeNone, nullptr, 0.f, WICBitmapPaletteTypeCustom)); - - const unsigned int thumbnailSize = thumbnailWidth * thumbnailHeight * 4; - unsigned char* thumbnailByteArray = static_cast(IwMalloc(thumbnailSize)); - if (!thumbnailByteArray) { - NSTraceInfo(TAG, @"CGImageSourceCreateThumbnailAtIndex cannot allocate memory"); - return nullptr; - } + ComPtr imageBitmap; + RETURN_NULL_IF_FAILED(imageFactory->CreateBitmapFromSource(imageScaler.Get(), WICBitmapCacheOnDemand, &imageBitmap)); - auto cleanup = wil::ScopeExit([&]() { IwFree(thumbnailByteArray); }); - RETURN_NULL_IF_FAILED(imageFormatConverter->CopyPixels(0, thumbnailWidth * 4, thumbnailSize, thumbnailByteArray)); - cleanup.Dismiss(); - - NSData* thumbnailData = [NSData dataWithBytesNoCopy:thumbnailByteArray length:thumbnailSize freeWhenDone:YES]; - CGDataProviderRef thumbnailDataProvider = CGDataProviderCreateWithCFData((CFDataRef)thumbnailData); - CGColorSpaceRef colorspaceRgb = CGColorSpaceCreateDeviceRGB(); - CGImageRef imageRef = CGImageCreate(thumbnailWidth, - thumbnailHeight, - 8, - 32, - thumbnailWidth * 4, - colorspaceRgb, - kCGImageAlphaLast, - thumbnailDataProvider, - nullptr, - true, - kCGRenderingIntentDefault); - CGDataProviderRelease(thumbnailDataProvider); - CGColorSpaceRelease(colorspaceRgb); - return imageRef; + return _CGImageCreateWithWICBitmap(imageBitmap.Get()); } /** diff --git a/Frameworks/QuartzCore/CALayer.mm b/Frameworks/QuartzCore/CALayer.mm index cb0011e795..92d2301a53 100644 --- a/Frameworks/QuartzCore/CALayer.mm +++ b/Frameworks/QuartzCore/CALayer.mm @@ -317,7 +317,7 @@ CGContextRef CreateLayerContentsBitmapContext32(int width, int height, float sca RETURN_NULL_IF_FAILED(factory->CreateWicBitmapRenderTarget(customWICBtmap.Get(), D2D1::RenderTargetProperties(), &renderTarget)); renderTarget->SetDpi(c_windowsDPI * scale, c_windowsDPI * scale); - return _CGBitmapContextCreateWithRenderTarget(renderTarget.Get(), image.get()); + return _CGBitmapContextCreateWithRenderTarget(renderTarget.Get(), image.get(), GUID_WICPixelFormat32bppPBGRA); } return nullptr; diff --git a/Frameworks/include/CGContextInternal.h b/Frameworks/include/CGContextInternal.h index be27a644f0..5152c93a66 100644 --- a/Frameworks/include/CGContextInternal.h +++ b/Frameworks/include/CGContextInternal.h @@ -22,6 +22,7 @@ #include #import #import +#import #include #import "CoreGraphicsInternal.h" @@ -40,6 +41,6 @@ COREGRAPHICS_EXPORT bool CGContextIsPointInPath(CGContextRef c, bool eoFill, flo COREGRAPHICS_EXPORT void CGContextDrawGlyphRun(CGContextRef ctx, const DWRITE_GLYPH_RUN* glyphRun); // Bitmap Context Internal -COREGRAPHICS_EXPORT CGContextRef _CGBitmapContextCreateWithRenderTarget(ID2D1RenderTarget* renderTarget, CGImageRef img = nullptr); +COREGRAPHICS_EXPORT CGContextRef _CGBitmapContextCreateWithRenderTarget(ID2D1RenderTarget* renderTarget, CGImageRef img, WICPixelFormatGUID outputPixelFormat); COREGRAPHICS_EXPORT CGContextRef _CGBitmapContextCreateWithFormat(int width, int height, __CGSurfaceFormat fmt); COREGRAPHICS_EXPORT CGImageRef CGBitmapContextGetImage(CGContextRef ctx); diff --git a/Frameworks/include/CGIWICBitmap.h b/Frameworks/include/CGIWICBitmap.h index c04d6f8569..10d2ce907b 100644 --- a/Frameworks/include/CGIWICBitmap.h +++ b/Frameworks/include/CGIWICBitmap.h @@ -152,7 +152,7 @@ class CGIWICBitmap : public Microsoft::WRL::RuntimeClass lock; - RETURN_IF_FAILED(Lock(copyRect, 0, &lock)); + // TODO #1379: Support sub-regional locking. + RETURN_IF_FAILED(Lock(&fullRect, 0, &lock)); + + if (!copyRect) { + copyRect = &fullRect; + } - UINT sourceDataSize; - BYTE* sourceData; - RETURN_IF_FAILED(lock->GetDataPointer(&sourceDataSize, &sourceData)); + RETURN_HR_IF(E_INVALIDARG, copyRect->Width == 0 || copyRect->Height == 0 || copyRect->X < 0 || copyRect->Y < 0); - RETURN_HR_IF(E_INVALIDARG, sourceDataSize > bufferSize); + unsigned int srcStride; + unsigned int srcSize; + uint8_t* srcData; + RETURN_IF_FAILED(lock->GetStride(&srcStride)); + RETURN_IF_FAILED(lock->GetDataPointer(&srcSize, &srcData)); - // TODO #1379 - should support regional copying. - RETURN_HR_IF(E_UNEXPECTED, memcpy_s(buffer, bufferSize, sourceData, sourceDataSize) != 0); + if (copyRect->X == 0 && copyRect->Y == 0 && copyRect->Width == m_width && copyRect->Height == m_height) { + RETURN_HR_IF(E_INVALIDARG, srcSize > bufferSize); + RETURN_HR_IF(E_UNEXPECTED, memcpy_s(buffer, bufferSize, srcData, srcSize) != 0); + } else { + // Once we support sub-regional locking we can fix this stride copier. + + // Invalid state: Source stride is less than the width of the image. + // We can't copy regions from sub-8bpp images. + RETURN_HR_IF(E_NOTIMPL, srcStride < fullRect.Width); + + size_t bytesPerPixel = srcStride / fullRect.Width; + ptrdiff_t srcOffset = (copyRect->X * bytesPerPixel) + (copyRect->Y * srcStride); + const uint8_t* end = buffer + (stride * copyRect->Height); + for (uint8_t *src = srcData + srcOffset, *dest = buffer; + dest < end; + src += srcStride, dest += stride) { + RETURN_HR_IF(E_UNEXPECTED, + memcpy_s(dest, + end - dest, // Total remaining bytes available in the destination buffer. + src, + stride) + ); + } + } return S_OK; } diff --git a/Frameworks/include/CGImageInternal.h b/Frameworks/include/CGImageInternal.h index 7c87505c00..71a08604dd 100644 --- a/Frameworks/include/CGImageInternal.h +++ b/Frameworks/include/CGImageInternal.h @@ -49,27 +49,32 @@ struct GuidPixelLess : public std::binary_function { } }; -static const std::map s_ValidRenderTargetPixelFormat = { { GUID_WICPixelFormat8bppAlpha, 1 }, - { GUID_WICPixelFormat32bppPRGBA, 1 }, - { GUID_WICPixelFormat32bppBGR, 1 }, - { GUID_WICPixelFormat32bppPBGRA, 1 } }; +static const std::map s_ValidRenderTargetPixelFormat = { { GUID_WICPixelFormat8bppAlpha, 1 }, // A8 Straight + { GUID_WICPixelFormat32bppRGB, 1 }, // RGBX + { GUID_WICPixelFormat32bppPRGBA, 1 }, // RGBA Premultiplied + { GUID_WICPixelFormat32bppBGR, 1 }, // BGRX + { GUID_WICPixelFormat32bppPBGRA, 1 } }; // BGRX Premultiplied static const std::map s_PixelFormats = { - /*Alpha First,Last*/ - { GUID_WICPixelFormat32bppRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaLast | kCGBitmapByteOrderDefault), 8, 32 } }, - { GUID_WICPixelFormat32bppBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaLast | kCGBitmapByteOrderDefault), 8, 32 } }, + // Last = RGBA, 32Little = forward: RGBA + // First = ARGB, 32Big = backward: BGRA + { GUID_WICPixelFormat32bppRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaLast | kCGBitmapByteOrder32Little), 8, 32 } }, + { GUID_WICPixelFormat32bppBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaFirst | kCGBitmapByteOrder32Big), 8, 32 } }, + { GUID_WICPixelFormat32bppPRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Little), 8, 32 } }, + { GUID_WICPixelFormat32bppPBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big), 8, 32 } }, + + // 64bpp formats (CoreGraphics has limited support for these.) { GUID_WICPixelFormat64bppRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaLast | kCGBitmapByteOrderDefault), 16, 64 } }, { GUID_WICPixelFormat64bppBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaLast | kCGBitmapByteOrderDefault), 16, 64 } }, - /*Alpha Premultiplied Last/First */ - { GUID_WICPixelFormat32bppPRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault), 8, 32 } }, - { GUID_WICPixelFormat32bppPBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault), 8, 32 } }, { GUID_WICPixelFormat64bppPRGBA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault), 16, 64 } }, { GUID_WICPixelFormat64bppPBGRA, { kCGColorSpaceModelRGB, (kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault), 16, 64 } }, - /*Alpha None, AlphaNoneSkipFirst, AlphaNoneSkipLast*/ + + // Non-alpha formats. { GUID_WICPixelFormat24bppRGB, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 8, 24 } }, { GUID_WICPixelFormat24bppBGR, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 8, 24 } }, - { GUID_WICPixelFormat32bppRGB, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 8, 32 } }, - { GUID_WICPixelFormat32bppBGR, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 8, 32 } }, + // Alpha-Skip formats (32bpp, but has alpha) + { GUID_WICPixelFormat32bppRGB, { kCGColorSpaceModelRGB, (kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Little), 8, 32 } }, + { GUID_WICPixelFormat32bppBGR, { kCGColorSpaceModelRGB, (kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big), 8, 32 } }, { GUID_WICPixelFormat48bppRGB, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 16, 48 } }, { GUID_WICPixelFormat48bppBGR, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 16, 48 } }, { GUID_WICPixelFormat64bppRGB, { kCGColorSpaceModelRGB, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 16, 64 } }, @@ -87,9 +92,9 @@ static const std::map s_PixelForm { GUID_WICPixelFormat32bppGrayFloat, { kCGColorSpaceModelMonochrome, (kCGImageAlphaNone | kCGBitmapFloatComponents), 32, 32 } }, /*Indexed*/ { GUID_WICPixelFormat1bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 1, 1 } }, - { GUID_WICPixelFormat2bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 1, 2 } }, - { GUID_WICPixelFormat4bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 1, 4 } }, - { GUID_WICPixelFormat8bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 1, 8 } } + { GUID_WICPixelFormat2bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 2, 2 } }, + { GUID_WICPixelFormat4bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 4, 4 } }, + { GUID_WICPixelFormat8bppIndexed, { kCGColorSpaceModelIndexed, (kCGImageAlphaNone | kCGBitmapByteOrderDefault), 8, 8 } } }; bool _CGIsValidRenderTargetPixelFormat(WICPixelFormatGUID pixelFormat); @@ -117,7 +122,7 @@ COREGRAPHICS_EXPORT NSData* _CGImageRepresentation(CGImageRef image, REFGUID gui COREGRAPHICS_EXPORT CGImageRef _CGImageCreateWithWICBitmap(IWICBitmap* bitmap); -HRESULT _CGImageGetWICImageSource(CGImageRef image, IWICBitmap** source); +COREGRAPHICS_EXPORT HRESULT _CGImageGetWICImageSource(CGImageRef image, IWICBitmap** source); // Obtain a direct pointer to the data. COREGRAPHICS_EXPORT void* _CGImageGetRawBytes(CGImageRef image); diff --git a/build/CoreGraphics/dll/CoreGraphics.def b/build/CoreGraphics/dll/CoreGraphics.def index 96b9fd4d26..e934abcd8f 100644 --- a/build/CoreGraphics/dll/CoreGraphics.def +++ b/build/CoreGraphics/dll/CoreGraphics.def @@ -361,6 +361,7 @@ LIBRARY CoreGraphics _CGImageJPEGRepresentation _CGImageRepresentation _CGImageCreateWithWICBitmap + _CGImageGetWICImageSource _CGImageCreateCopyWithPixelFormat _CGImageGetRawBytes _CGImageGetDisplayTexture diff --git a/tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp b/tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp index 956eeae48f..2fa0d66b8b 100644 --- a/tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp +++ b/tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp @@ -222,3 +222,11 @@ DISABLED_DRAW_TEST_F(CGContext, ChangeCTMAfterCreatingPath, WhiteBackgroundTest) CGContextStrokePath(context); CGContextRestoreGState(context); } + +DRAW_TEST(CGContext, PremultipliedAlphaImage) { + CGContextRef context = GetDrawingContext(); + CGRect bounds = GetDrawingBounds(); + + CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 0.5); + CGContextFillRect(context, { 0, 0, 100, 100 }); +} diff --git a/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp b/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp index 1ed95c41ee..bdefe2cc21 100644 --- a/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp +++ b/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp @@ -18,91 +18,213 @@ #include "ImageHelpers.h" #include +#include +#include -struct bgraPixel { - uint8_t b, g, r, a; +struct Pixel { + uint8_t r, g, b, a; + bool operator==(const Pixel& o) const { + return r == o.r && g == o.g && g == o.g && a == o.a; + } + bool operator!=(const Pixel& o) const { + return !(*this == o); + } }; -struct rgbaPixel { - uint8_t r, g, b, a; +struct ImagePixelAccess { +private: + woc::unique_cf _image; + woc::unique_cf _cfData; + const uint8_t* _data; // view into cfData + CGBitmapInfo _byteOrder; + CGImageAlphaInfo _alphaInfo; + bool _premultiplied; + bool _alphaFirst; + bool _alphaSkip; + + static uint8_t unpremultiply(uint8_t val, uint8_t alpha) { + if (alpha == 0) { + return 0; + } + + if (alpha == 255) { + return val; + } + + uint32_t multiplier16bpp = (uint32_t)floor((255. / double(alpha)) * 65536.); + // Use the above multiplier to calculate the pixel's 16bpp unpremultiplied value. + uint32_t pixelValue = val * multiplier16bpp; + return std::min(255U, (pixelValue >> 16)); + } + +public: + const size_t width; + const size_t height; + + ImagePixelAccess(CGImageRef image) + : _image(CGImageRetain(image)), + _cfData(_CFDataCreateFromCGImage(image)), + _data(reinterpret_cast(CFDataGetBytePtr(_cfData.get()))), + _alphaInfo(CGImageGetAlphaInfo(image)), + width(CGImageGetWidth(image)), + height(CGImageGetHeight(image)) { + _premultiplied = _alphaInfo == kCGImageAlphaPremultipliedFirst || _alphaInfo == kCGImageAlphaPremultipliedLast; + _alphaFirst = + _alphaInfo == kCGImageAlphaPremultipliedFirst || _alphaInfo == kCGImageAlphaFirst || _alphaInfo == kCGImageAlphaNoneSkipFirst; + _alphaSkip = _alphaInfo == kCGImageAlphaNoneSkipFirst || _alphaInfo == kCGImageAlphaNoneSkipLast; + + CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(image); + _byteOrder = bitmapInfo & kCGBitmapByteOrderMask; + if (_byteOrder == kCGBitmapByteOrderDefault) { + _byteOrder = kCGBitmapByteOrder32Host; + } + } + + Pixel at(size_t x, size_t y) { + if (_alphaInfo == kCGImageAlphaNone) { + uint8_t(&rawData)[3] = *(((decltype(&rawData))_data) + (y * width) + x); + switch (_byteOrder) { + case kCGBitmapByteOrder32Big: + // raw data is B G R + return { rawData[2], rawData[1], rawData[0], 255 }; + case kCGBitmapByteOrder32Little: + // raw data is R G B + return { rawData[0], rawData[1], rawData[2], 255 }; + default: + return { 0, 0, 0, 255 }; + } + } else if (_alphaInfo != kCGImageAlphaOnly) { + uint8_t(&rawData)[4] = *(((decltype(&rawData))_data) + (y * width) + x); + Pixel p; + if (_alphaFirst) { + switch (_byteOrder) { + case kCGBitmapByteOrder32Big: + // raw data is B G R A + p = { rawData[2], rawData[1], rawData[0], rawData[3] }; + break; + case kCGBitmapByteOrder32Little: + // raw data is A R G B + p = { rawData[1], rawData[2], rawData[3], rawData[0] }; + break; + } + } else { + switch (_byteOrder) { + case kCGBitmapByteOrder32Big: + // raw data is A B G R + p = { rawData[3], rawData[2], rawData[1], rawData[0] }; + break; + case kCGBitmapByteOrder32Little: + // raw data is R G B A + p = { rawData[0], rawData[1], rawData[2], rawData[3] }; + break; + } + } + + if (_alphaSkip) { + p.a = 255; + } + + if (_premultiplied) { + p.r = unpremultiply(p.r, p.a); + p.g = unpremultiply(p.g, p.a); + p.b = unpremultiply(p.b, p.a); + } + + return p; + } else { + // Alpha-only images are not supported. + return { 0, 0, 0, 255 }; + } + } }; -template -bool operator==(const T& t, const U& u) { - return t.r == u.r && t.g == u.g && t.b == u.b && t.a == u.a; -} +struct RGBAImageBuffer { +private: + std::vector _pixels; + RGBAImageBuffer(const RGBAImageBuffer& other) = delete; -ImageDelta PixelByPixelImageComparator::CompareImages(CGImageRef left, CGImageRef right) { - if (!left || !right) { - return { ImageComparisonResult::Incomparable }; +public: + const size_t width; + const size_t height; + + RGBAImageBuffer(size_t width, size_t height) : _pixels(width * height, { 0, 0, 0, 0 }), width(width), height(height) { } - CGSize leftSize{ - (CGFloat)CGImageGetWidth(left), (CGFloat)CGImageGetHeight(left), - }; + Pixel& at(size_t x, size_t y) { + return _pixels[(y * width) + x]; + } + + const void* data() const { + return _pixels.data(); + } - CGSize rightSize{ - (CGFloat)CGImageGetWidth(right), (CGFloat)CGImageGetHeight(right), + const size_t len() const { + return stride() * height; }; - size_t leftPixelCount = leftSize.width * leftSize.height; - size_t rightPixelCount = rightSize.width * rightSize.height; + const size_t stride() const { + return width * sizeof(decltype(_pixels[0])); + } +}; - if (leftPixelCount != rightPixelCount) { +ImageDelta PixelByPixelImageComparator::CompareImages(CGImageRef left, CGImageRef right) { + if (!left || !right) { return { ImageComparisonResult::Incomparable }; } - woc::unique_cf leftData{ _CFDataCreateFromCGImage(left) }; - woc::unique_cf rightData{ _CFDataCreateFromCGImage(right) }; + ImagePixelAccess leftAccess{ left }; + ImagePixelAccess rightAccess{ right }; - CFIndex leftLength = CFDataGetLength(leftData.get()); - if (leftLength != CFDataGetLength(rightData.get())) { + size_t leftPixelCount = leftAccess.width * leftAccess.height; + size_t rightPixelCount = rightAccess.width * rightAccess.height; + + if (leftPixelCount != rightPixelCount) { return { ImageComparisonResult::Incomparable }; } - woc::unique_iw deltaBuffer{ static_cast(IwCalloc(leftLength, 1)) }; - - const bgraPixel* leftPixels{ reinterpret_cast(CFDataGetBytePtr(leftData.get())) }; - const rgbaPixel* rightPixels{ reinterpret_cast(CFDataGetBytePtr(rightData.get())) }; - rgbaPixel* deltaPixels{ reinterpret_cast(deltaBuffer.get()) }; + RGBAImageBuffer deltaBuffer{ leftAccess.width, leftAccess.height }; // ASSUMPTION: The context draw did not cover the top left pixel; // We can use it as the background to detect accidental background deletion and miscomposition. - auto background = leftPixels[0]; + Pixel background = leftAccess.at(0, 0); size_t npxchg = 0; - for (off_t i = 0; i < leftLength / sizeof(rgbaPixel); ++i) { - auto& bp = leftPixels[i]; - auto& cp = rightPixels[i]; - auto& gp = deltaPixels[i]; - if (!(bp == cp)) { - ++npxchg; - if (cp == background) { - // Pixel is in EXPECTED but not ACTUAL - gp.r = gp.a = 255; - } else if (bp == background) { - // Pixel is in ACTUAL but not EXPECTED - gp.g = gp.a = 255; + for (off_t y = 0; y < leftAccess.height; ++y) { + for (off_t x = 0; x < leftAccess.width; ++x) { + auto bp = leftAccess.at(x, y); + auto cp = rightAccess.at(x, y); + auto& gp = deltaBuffer.at(x, y); + if (bp != cp) { + ++npxchg; + if (cp == background) { + // Pixel is in EXPECTED but not ACTUAL + gp.r = gp.a = 255; + } else if (bp == background) { + // Pixel is in ACTUAL but not EXPECTED + gp.g = gp.a = 255; + } else { + // Pixel is in BOTH but DIFFERENT + gp.r = gp.g = gp.a = 255; + } } else { - // Pixel is in BOTH but DIFFERENT - gp.r = gp.g = gp.a = 255; + gp.r = gp.g = gp.b = 0; + gp.a = 255; } - } else { - gp.r = gp.g = gp.b = 0; - gp.a = 255; } } - woc::unique_cf deltaData{ CFDataCreateWithBytesNoCopy(nullptr, deltaBuffer.release(), leftLength, kCFAllocatorDefault) }; + woc::unique_cf deltaData{ + CFDataCreateWithBytesNoCopy(nullptr, reinterpret_cast(deltaBuffer.data()), deltaBuffer.len(), kCFAllocatorNull) + }; woc::unique_cf deltaProvider{ CGDataProviderCreateWithCFData(deltaData.get()) }; - woc::unique_cf deltaImage{ CGImageCreate(leftSize.width, - leftSize.height, + woc::unique_cf deltaImage{ CGImageCreate(deltaBuffer.width, + deltaBuffer.height, 8, 32, - leftSize.width * 4, + deltaBuffer.stride(), CGImageGetColorSpace(left), - CGImageGetBitmapInfo(left), + kCGBitmapByteOrder32Little | kCGImageAlphaLast, deltaProvider.get(), nullptr, FALSE, diff --git a/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CGContext.PremultipliedAlphaImage.png b/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CGContext.PremultipliedAlphaImage.png new file mode 100644 index 0000000000..b46a1065f9 --- /dev/null +++ b/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CGContext.PremultipliedAlphaImage.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b347035f3e9f7927668c822c4911adebb41172b5ee0f4c24e9baa98bd175c4cc +size 2736 diff --git a/tests/unittests/CoreGraphics/CGBitmapContextTests.mm b/tests/unittests/CoreGraphics/CGBitmapContextTests.mm index e0fc000df5..1df4a75d0a 100644 --- a/tests/unittests/CoreGraphics/CGBitmapContextTests.mm +++ b/tests/unittests/CoreGraphics/CGBitmapContextTests.mm @@ -159,7 +159,7 @@ static void _expectArrayValues(const BYTE* res, const BYTE* source, int size) { EXPECT_EQ(context, nullptr); context = CGBitmapContextCreate(nullptr, 120, 20, 8, 480, grayColorSpace, 0); - EXPECT_EQ(context, nullptr); + EXPECT_NE(context, nullptr); } TEST(CGBitmapContext, BitmapInfoAPIs_RGB) { @@ -215,3 +215,67 @@ static void _expectArrayValues(const BYTE* res, const BYTE* source, int size) { const BYTE* rData = static_cast(CFDataGetBytePtr(rawData.get())); _expectArrayValues(result, rData, 4); } + +struct BitmapFormatTestCase { + CGBitmapInfo bitmapInfo; + uint32_t nComponents; + uint32_t bitsPerPixel; + std::vector mask; + std::vector expectedPixelValues; +}; + +class BitmapFormats : public ::testing::TestWithParam {}; + +TEST_P(BitmapFormats, BufferCompare) { + const BitmapFormatTestCase& testInfo = GetParam(); + const size_t width = 4; + const size_t height = 1; + size_t bytesPerPixel = 2 << (testInfo.bitsPerPixel >> 3); + size_t stride = width * bytesPerPixel; + std::vector data(stride * height, 0xAB); + woc::unique_cf rgbColorSpace{ CGColorSpaceCreateDeviceRGB() }; + woc::unique_cf context{ CGBitmapContextCreateWithData(data.data(), + width, + height, + testInfo.bitsPerPixel / testInfo.nComponents, + stride, + rgbColorSpace.get(), + testInfo.bitmapInfo, + nullptr, + nullptr) }; + ASSERT_NE(nullptr, context); + + // Pixel values: 0x20 0x40 0x00 0x80 + // Premultiplied: 0x10 0x20 0x00 0x80 + CGContextSetRGBFillColor(context.get(), 32. / 255., 64. / 255., 0.0, 128. / 255.); + CGContextFillRect(context.get(), { CGPointZero, { width, height } }); + + size_t maskLength = testInfo.mask.size(); + size_t compareBufferLength = testInfo.expectedPixelValues.size(); + for (size_t i; i < data.size(); ++i) { + uint8_t maskedValue = data[i] & testInfo.mask[i % maskLength]; + EXPECT_EQ(maskedValue, testInfo.expectedPixelValues[i % compareBufferLength]); + } +} + +// clang-format off +static BitmapFormatTestCase bitmapFormatTestCases[]{ + // CGBitmapInfo (pixel format, order) | #channels| bpp| pixel mask | expected pixel values | + // Alpha only (8bpp format) + { kCGImageAlphaOnly, 1, 8, { 0xFF } , { 0x80 } }, + + // RGBX (32bpp) + { kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Little, 4, 32, { 0xFF, 0xFF, 0xFF, 0x00 }, { 0x20, 0x40, 0x00, 0x00 } }, + + // RGBA (32bpp premultiplied) + { kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Little, 4, 32, { 0xFF, 0xFF, 0xFF, 0xFF }, { 0x10, 0x20, 0x00, 0x80 } }, + + // BGRX (32bpp) + { kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big, 4, 32, { 0xFF, 0xFF, 0xFF, 0x00 }, { 0x00, 0x40, 0x20, 0x00 } }, + + // BGRX (32bpp premultiplied) + { kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big, 4, 32, { 0xFF, 0xFF, 0xFF, 0xFF }, { 0x00, 0x20, 0x10, 0x80 } }, +}; +// clang-format on + +INSTANTIATE_TEST_CASE_P(CGBitmapContextFormat, BitmapFormats, ::testing::ValuesIn(bitmapFormatTestCases)); diff --git a/tests/unittests/CoreGraphics/CGImageTests.mm b/tests/unittests/CoreGraphics/CGImageTests.mm index 9d3cbbcf1b..121e965ce0 100644 --- a/tests/unittests/CoreGraphics/CGImageTests.mm +++ b/tests/unittests/CoreGraphics/CGImageTests.mm @@ -41,7 +41,7 @@ static const _ImageInfo imagesPNG[] = { /*{"filename",height,width,isMask,bit per pixel, bits per component} */ { @"data/png1.png", 700, 1044, false, 32, 8 }, - { @"data/png2.png", 136, 370, false, 8, 1 }, + { @"data/png2.png", 136, 370, false, 8, 8 }, { @"data/png3.png", 795, 1197, false, 32, 8 }, }; diff --git a/tests/unittests/ImageIO/ImageIOTest.mm b/tests/unittests/ImageIO/ImageIOTest.mm index 8e55dad97c..ed22b7161f 100644 --- a/tests/unittests/ImageIO/ImageIOTest.mm +++ b/tests/unittests/ImageIO/ImageIOTest.mm @@ -70,33 +70,33 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, ImageAtIndexWithData) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(670, CGImageGetHeight(imageRef)); + EXPECT_EQ(1024, CGImageGetWidth(imageRef)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); } TEST(ImageIO, ImageAtIndexWithDataProvider) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @@ -104,18 +104,18 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { }; CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)imageData); CGImageSourceRef imageSource = CGImageSourceCreateWithDataProvider(imgDataProvider, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(670, CGImageGetHeight(imageRef)); + EXPECT_EQ(1024, CGImageGetWidth(imageRef)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); } @@ -129,29 +129,29 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imgUrl, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithURL returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithURL returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(670, CGImageGetHeight(imageRef)); + EXPECT_EQ(1024, CGImageGetWidth(imageRef)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); } TEST(ImageIO, ImageTypeTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nullptr); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFStringRef imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"public.jpeg", "FAILED: ImageIOTest::Incorrect Image Type"); CFRelease(imageSource); } @@ -159,7 +159,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, ThumbnailAtIndexFromSrcWithoutThumbnail) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @@ -170,23 +170,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { @"kCGImageSourceCreateThumbnailWithTransform" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(670, CGImageGetHeight(imageRef)); + EXPECT_EQ(1024, CGImageGetWidth(imageRef)); CFRelease(imageSource); } TEST(ImageIO, ThumbnailAtIndexFromAsymmetricSrcWithThumbnail) { const wchar_t* imageFile = L"photo6_1024x670_thumbnail_227x149.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @@ -197,23 +197,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { @"kCGImageSourceCreateThumbnailWithTransform" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(149, CGImageGetHeight(imageRef)); + EXPECT_EQ(227, CGImageGetWidth(imageRef)); CFRelease(imageSource); } TEST(ImageIO, ThumbnailSizesRelativeToImage) { const wchar_t* imageFile = L"photo6_1024x670_thumbnail_227x149.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @@ -224,16 +224,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { @"kCGImageSourceCreateThumbnailWithTransform" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 10, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 10, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(10, CGImageGetHeight(imageRef)); + EXPECT_EQ(10, CGImageGetWidth(imageRef)); CFRelease(imageSource); options = @{ @@ -246,177 +246,179 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { @"kCGImageSourceCreateThumbnailWithTransform" : @"kCFBooleanTrue" }; imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(149, CGImageGetHeight(imageRef)); + EXPECT_EQ(227, CGImageGetWidth(imageRef)); CFRelease(imageSource); } TEST(ImageIO, GIF_TIFF_MultiFrameSourceTest) { const wchar_t* imageFile = L"photo7_4layers_683x1024.gif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeGIF", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 2, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); CFStringRef imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"com.compuserve.gif", "FAILED: ImageIOTest::Incorrect Image Type"); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 4, "FAILED: ImageIOTest::FrameCount"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 683, "FAILED: ImageIOTest::Width"); + EXPECT_EQ(4, frameCount); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRef)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(1024, CGImageGetHeight(imageRef)); + EXPECT_EQ(683, CGImageGetWidth(imageRef)); imageFile = L"photo8_4layers_1024x683.tif"; imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeTIFF", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRef = CGImageSourceCreateImageAtIndex(imageSource, 3, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"public.tiff", "FAILED: ImageIOTest::Incorrect Image Type"); frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 4, "FAILED: ImageIOTest::FrameCount"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 683, "FAILED: ImageIOTest::Width"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(1024, CGImageGetHeight(imageRef)); + EXPECT_EQ(683, CGImageGetWidth(imageRef)); CFRelease(imageSource); } TEST(ImageIO, BMP_ICO_PNG_SingleFrameSourceTest) { const wchar_t* imageFile = L"testimg_227x149.bmp"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeBMP", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); CFStringRef imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"com.microsoft.bmp", "FAILED: ImageIOTest::Incorrect Image Type"); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 227, "FAILED: ImageIOTest::Width"); - + EXPECT_EQ(1, frameCount); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRef)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(149, CGImageGetHeight(imageRef)); + EXPECT_EQ(227, CGImageGetWidth(imageRef)); + + // RGBA 8-bit ICO frame imageFile = L"photo2_683x1024.ico"; imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeICO", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"com.microsoft.ico", "FAILED: ImageIOTest::Incorrect Image Type"); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 683, "FAILED: ImageIOTest::Width"); - + EXPECT_EQ(1, frameCount); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRef)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(1024, CGImageGetHeight(imageRef)); + EXPECT_EQ(683, CGImageGetWidth(imageRef)); + + // Paletted/Indexed PNG imageFile = L"seafloor_256x256.png"; imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypePNG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); imageType = CGImageSourceGetType(imageSource); - ASSERT_TRUE_MSG(imageType != nil, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); + ASSERT_NE_MSG(nil, imageType, "FAILED: ImageIOTest::CGImageSourceGetType returned nullptr"); ASSERT_OBJCEQ_MSG(static_cast(imageType), @"public.png", "FAILED: ImageIOTest::Incorrect Image Type"); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRef), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRef), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRef), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRef), 256, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRef), 256, "FAILED: ImageIOTest::Width"); + EXPECT_EQ(1, frameCount); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRef)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRef)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRef)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(256, CGImageGetHeight(imageRef)); + EXPECT_EQ(256, CGImageGetWidth(imageRef)); CFRelease(imageSource); } TEST(ImageIO, NegativeScenarioTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData(nullptr, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData should return nullptr"); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nullptr); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageSource = CGImageSourceCreateWithData(nullptr, nullptr); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData should return nullptr"); CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)imageData); imageSource = CGImageSourceCreateWithDataProvider(nullptr, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider should return nullptr"); imageSource = CGImageSourceCreateWithDataProvider(imgDataProvider, nullptr); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider returned nullptr"); imageSource = CGImageSourceCreateWithDataProvider(nullptr, nullptr); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithDataProvider should return nullptr"); // get test startup full path wchar_t fullPath[_MAX_PATH]; @@ -436,25 +438,25 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFURLRef imgUrl = (CFURLRef)[NSURL fileURLWithPath:directoryWithFile]; imageSource = CGImageSourceCreateWithURL(nullptr, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithURL should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithURL should return nullptr"); imageSource = CGImageSourceCreateWithURL(nullptr, nullptr); - ASSERT_TRUE_MSG(imageSource == nil, "FAILED: ImageIOTest::CGImageSourceCreateWithURL should return nullptr"); + ASSERT_EQ_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithURL should return nullptr"); imageSource = CGImageSourceCreateWithURL(imgUrl, nullptr); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithURL returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithURL returned nullptr"); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 5, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); imageRef = CGImageSourceCreateImageAtIndex(imageSource, -1, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, nullptr); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); imageRef = CGImageSourceCreateImageAtIndex(nullptr, 0, nullptr); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); size_t frameCount = CGImageSourceGetCount(nullptr); ASSERT_EQ_MSG(frameCount, 0, "FAILED: ImageIOTest::FrameCount"); @@ -469,13 +471,13 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { }; imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 5, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); imageRef = CGImageSourceCreateThumbnailAtIndex(nullptr, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, nullptr); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateThumbnailAtIndex should return nullptr"); CFRelease(imageSource); } @@ -495,14 +497,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyJPEGPropertiesTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 218940, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(218940, fileSize); } CFRelease(imageSource); @@ -511,14 +513,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyGIFPropertiesTest) { const wchar_t* imageFile = L"photo7_4layers_683x1024.gif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 669893, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(669893, fileSize); } CFRelease(imageSource); @@ -527,14 +529,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyTIFFPropertiesTest) { const wchar_t* imageFile = L"photo8_4layers_1024x683.tif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 4187742, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(4187742, fileSize); } CFRelease(imageSource); @@ -543,14 +545,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyPNGPropertiesTest) { const wchar_t* imageFile = L"seafloor_256x256.png"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 59506, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(59506, fileSize); } CFRelease(imageSource); @@ -559,14 +561,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyBMPPropertiesTest) { const wchar_t* imageFile = L"testimg_227x149.bmp"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 35050, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(35050, fileSize); } CFRelease(imageSource); @@ -575,14 +577,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyICOPropertiesTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nil); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, nil); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); if (imageProperties && CFDictionaryContainsKey(imageProperties, kCGImagePropertyFileSize)) { int fileSize = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyFileSize) intValue]; - ASSERT_EQ_MSG(fileSize, 1041876, "FAILED: ImageIOTest::FileSize"); + EXPECT_EQ(1041876, fileSize); } CFRelease(imageSource); @@ -591,16 +593,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyJPEGPropertiesAtIndexTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeJPEG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyJFIFDictionary), "FAILED: ImageIOTest::JFIF dictionary not found"); @@ -616,28 +618,28 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyGIFPropertiesAtIndexTest) { const wchar_t* imageFile = L"photo7_4layers_683x1024.gif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeGIF", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPixelHeight), "FAILED: ImageIOTest::GIF PixelHeight Property not found"); int actualHeight = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) intValue]; - ASSERT_EQ_MSG(actualHeight, 1024, "FAILED: ImageIOTest::ActualHeight"); + EXPECT_EQ(1024, actualHeight); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyGIFDictionary), "FAILED: ImageIOTest::GIF Dictionary not found"); CFDictionaryRef gifDictionary = (CFDictionaryRef)CFDictionaryGetValue(imageProperties, kCGImagePropertyGIFDictionary); ASSERT_TRUE_MSG(CFDictionaryContainsKey(gifDictionary, kCGImagePropertyGIFDelayTime), "FAILED: ImageIOTest::GIF dictionary does not contain Delay Time"); double actualDelayTime = [(id)CFDictionaryGetValue(gifDictionary, kCGImagePropertyGIFDelayTime) doubleValue]; - ASSERT_NEAR_MSG(actualDelayTime, 0.1, 0.01, "FAILED: ImageIOTest::Delay Time mismatch"); + EXPECT_NEAR_MSG(actualDelayTime, 0.1, 0.01, "FAILED: ImageIOTest::Delay Time mismatch"); CFRelease(imageSource); } @@ -645,16 +647,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyTIFFPropertiesAtIndexTest) { const wchar_t* imageFile = L"photo8_4layers_1024x683.tif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypeTIFF", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyTIFFDictionary), "FAILED: ImageIOTest::TIFF dictionary not found"); @@ -662,7 +664,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(tiffDictionary, kCGImagePropertyTIFFResolutionUnit), "FAILED: ImageIOTest::TIFF dictionary does not contain Resolution Unit"); int actualResolutionUnit = [(id)CFDictionaryGetValue(tiffDictionary, kCGImagePropertyTIFFResolutionUnit) intValue]; - ASSERT_EQ_MSG(actualResolutionUnit, 2, "FAILED: ImageIOTest::ResolutionUnit"); + EXPECT_EQ(2, actualResolutionUnit); CFRelease(imageSource); } @@ -670,16 +672,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, CopyPNGPropertiesAtIndexTest) { const wchar_t* imageFile = L"seafloor_256x256.png"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSDictionary* options = @{ @"kCGImageSourceTypeIdentifierHint" : @"kUTTypePNG", @"kCGImageSourceShouldAllowFloat" : @"kCFBooleanTrue", @"kCGImageSourceShouldCache" : @"kCFBooleanTrue" }; CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPNGDictionary), "FAILED: ImageIOTest::PNG dictionary not found"); @@ -687,18 +689,19 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(pngDictionary, kCGImagePropertyPNGGamma), "FAILED: ImageIOTest::PNG dictionary does not contain Gamma"); int actualGamma = [(id)CFDictionaryGetValue(pngDictionary, kCGImagePropertyPNGGamma) intValue]; - ASSERT_EQ_MSG(actualGamma, 45455, "FAILED: ImageIOTest::PngGamma"); + EXPECT_EQ(45455, actualGamma); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationTest) { +TEST(ImageIO, DestinationTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); CFRelease(imageSource); + // Written as BGRA const wchar_t* outFile = L"outphoto.tif"; CFURLRef imgUrl = getURLRefForOutFile(outFile); @@ -709,22 +712,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); + // Written as RGB const wchar_t* outFile2 = L"outphoto.jpg"; imgUrl = getURLRefForOutFile(outFile2); @@ -735,22 +739,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile2); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); + // Written as RGB const wchar_t* outFile3 = L"outphoto.png"; imgUrl = getURLRefForOutFile(outFile3); @@ -761,22 +766,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile3); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile3); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile3); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); + // Written as BGRX const wchar_t* outFile4 = L"outphoto.bmp"; imgUrl = getURLRefForOutFile(outFile4); @@ -787,22 +793,23 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile4); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile4); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile4); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNoneSkipFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); + // Written as Paletted/Indexed const wchar_t* outFile5 = L"outphoto.gif"; imgUrl = getURLRefForOutFile(outFile5); @@ -813,29 +820,30 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile5); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile5); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile5); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); CFRelease(myImageDest); } -DISABLED_TEST(ImageIO, DestinationFromSourceTest) { +TEST(ImageIO, DestinationFromSourceTest) { const wchar_t* imageFile = L"testimg_227x149.bmp"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); + // Written as BGRA const wchar_t* outFile = L"outphoto2.tif"; CFURLRef imgUrl = getURLRefForOutFile(outFile); @@ -847,21 +855,22 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties CFRelease(imageSource); imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(149, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(227, CGImageGetWidth(imageRefOut)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); + // Written as RGB const wchar_t* outFile2 = L"outphoto2.jpg"; imgUrl = getURLRefForOutFile(outFile2); @@ -873,21 +882,22 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile2); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(149, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(227, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); + // Written as RGB const wchar_t* outFile3 = L"outphoto2.png"; imgUrl = getURLRefForOutFile(outFile3); @@ -899,21 +909,22 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile3); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile3); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile3); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(149, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(227, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); + // Written as BGRX const wchar_t* outFile4 = L"outphoto2.bmp"; imgUrl = getURLRefForOutFile(outFile4); @@ -925,24 +936,24 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile4); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile4); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile4); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 149, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 227, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNoneSkipFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(149, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(227, CGImageGetWidth(imageRefOut)); frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationMultiFrameTest) { +TEST(ImageIO, DestinationMultiFrameTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -953,6 +964,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CGImageSourceRef imageSource2 = CGImageSourceCreateWithData((CFDataRef)imageData2, NULL); CGImageRef imageRef2 = CGImageSourceCreateImageAtIndex(imageSource2, 0, NULL); + // Written as BGRA const wchar_t* outFile = L"outphoto_multiframe.tif"; CFURLRef imgUrl = getURLRefForOutFile(outFile); @@ -967,46 +979,46 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); size_t frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 3, "FAILED: ImageIOTest::FrameCount"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 683, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(1024, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(683, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 1, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 2, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationMultiFrameGifTest) { +TEST(ImageIO, DestinationMultiFrameGifTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1017,6 +1029,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CGImageSourceRef imageSource2 = CGImageSourceCreateWithData((CFDataRef)imageData2, NULL); CGImageRef imageRef2 = CGImageSourceCreateImageAtIndex(imageSource2, 0, NULL); + // Written as Paletted/Indexed const wchar_t* outFile = L"outphoto_multiframe.gif"; CFURLRef imgUrl = getURLRefForOutFile(outFile); @@ -1031,46 +1044,46 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); size_t frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 3, "FAILED: ImageIOTest::FrameCount"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 683, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(1024, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(683, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 1, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 2, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationDataTest) { +TEST(ImageIO, DestinationDataTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1086,22 +1099,22 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFRelease(myImageDest); imageSource = CGImageSourceCreateWithData((CFDataRef)dataBuffer, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); size_t frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 683, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRef))); + EXPECT_EQ(1024, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(683, CGImageGetWidth(imageRefOut)); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationMultiFrameDataTest) { +TEST(ImageIO, DestinationMultiFrameDataTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1125,44 +1138,44 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageSource = CGImageSourceCreateWithData((CFDataRef)dataBuffer, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); size_t frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 3, "FAILED: ImageIOTest::FrameCount"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 683, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(1024, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(683, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 1, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 2, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaFirst, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaFirst | kCGBitmapByteOrder32Big, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(32, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationOptionsTest) { +TEST(ImageIO, DestinationOptionsTest) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1185,20 +1198,20 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CGImageRef imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 670, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(24, CGImageGetBitsPerPixel(imageRefOut)); + EXPECT_EQ(3, CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut))); + EXPECT_EQ(670, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); size_t frameCount = CGImageSourceGetCount(imageSource); - ASSERT_EQ_MSG(frameCount, 1, "FAILED: ImageIOTest::FrameCount"); + EXPECT_EQ(1, frameCount); CFRelease(imageSource); imageFile = L"photo2_683x1024.ico"; @@ -1237,14 +1250,14 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { // Read back in the newly written image to check properties imageData = getDataFromImageFile(outFile2); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile2); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); frameCount = CGImageSourceGetCount(imageSource); ASSERT_EQ_MSG(frameCount, 3, "FAILED: ImageIOTest::FrameCount"); CFDictionaryRef imageProperties = CGImageSourceCopyProperties(imageSource, NULL); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyProperties returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyGIFDictionary), "FAILED: ImageIOTest::GIF dictionary not found"); @@ -1252,42 +1265,42 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(gifDictionary, kCGImagePropertyGIFLoopCount), "FAILED: ImageIOTest::GIF dictionary does not contain Loop Count"); int actualLoopCount = [(id)CFDictionaryGetValue(gifDictionary, kCGImagePropertyGIFLoopCount) intValue]; - ASSERT_EQ_MSG(actualLoopCount, loopCount, "FAILED: ImageIOTest::LoopCount"); + EXPECT_EQ(loopCount, actualLoopCount); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 1024, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 683, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(1024, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(683, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 1, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); imageRefOut = CGImageSourceCreateImageAtIndex(imageSource, 2, NULL); - ASSERT_TRUE_MSG(imageRefOut != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageGetAlphaInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::AlphaInfo"); - ASSERT_EQ_MSG(CGImageGetBitmapInfo(imageRefOut), kCGImageAlphaLast, "FAILED: ImageIOTest::BitmapInfo"); - ASSERT_EQ_MSG(CGImageGetBitsPerComponent(imageRefOut), 8, "FAILED: ImageIOTest::BitsPerComponent"); - ASSERT_EQ_MSG(CGImageGetBitsPerPixel(imageRefOut), 32, "FAILED: ImageIOTest::BitsPerPixel"); - ASSERT_EQ_MSG(CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(imageRefOut)), 3, "FAILED: ImageIOTest::ColorSpaceComponentCount"); - ASSERT_EQ_MSG(CGImageGetHeight(imageRefOut), 683, "FAILED: ImageIOTest::Height"); - ASSERT_EQ_MSG(CGImageGetWidth(imageRefOut), 1024, "FAILED: ImageIOTest::Width"); + ASSERT_NE_MSG(nil, imageRefOut, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetAlphaInfo(imageRefOut)); + EXPECT_EQ(kCGImageAlphaNone, CGImageGetBitmapInfo(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerComponent(imageRefOut)); + EXPECT_EQ(8, CGImageGetBitsPerPixel(imageRefOut)); + // TODO: Check Paletted/Indexed color space. + EXPECT_EQ(683, CGImageGetHeight(imageRefOut)); + EXPECT_EQ(1024, CGImageGetWidth(imageRefOut)); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationImageOptionsTIFFTest) { +TEST(ImageIO, DestinationImageOptionsTIFFTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1339,11 +1352,11 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFRelease(myImageDest); imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); // Note that this XResolution was actually passed in as 100. This field aliases with DPIWidth. // As observed on iOS, for TIFF, DPIWidth takes precedence, while for JPEG, XResolution takes precedence. @@ -1365,16 +1378,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPixelHeight), "FAILED: ImageIOTest::Pixel Height not found"); int actualPixelHeight = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) intValue]; - ASSERT_EQ_MSG(actualPixelHeight, 1024, "FAILED: ImageIOTest::Height"); + EXPECT_EQ(1024, actualPixelHeight); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyOrientation), "FAILED: ImageIOTest::Orientation not found"); int actualOrientation = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyOrientation) intValue]; - ASSERT_EQ_MSG(actualOrientation, 3, "FAILED: ImageIOTest::Orientation"); + EXPECT_EQ(3, actualOrientation); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationImageOptionsJPEGTest) { +TEST(ImageIO, DestinationImageOptionsJPEGTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1426,11 +1439,11 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFRelease(myImageDest); imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyJFIFDictionary), "FAILED: ImageIOTest::JFIF dictionary not found"); @@ -1438,7 +1451,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(jfifDictionary, kCGImagePropertyJFIFXDensity), "FAILED: ImageIOTest::JFIF dictionary does not contain XDensity"); double actualXDensity = [(id)CFDictionaryGetValue(jfifDictionary, kCGImagePropertyJFIFXDensity) doubleValue]; - ASSERT_NEAR_MSG(actualXDensity, 0.0, 0.01, "FAILED: ImageIOTest::XDensity mismatch"); // Not set, should be 0 + ASSERT_NEAR_MSG(actualXDensity, 96.0, 0.01, "FAILED: ImageIOTest::XDensity mismatch"); // By default, set to 96.0 (Windows Direct2D/WIC DPI) ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyGPSDictionary), "FAILED: ImageIOTest::GPS dictionary not found"); @@ -1450,16 +1463,16 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPixelHeight), "FAILED: ImageIOTest::Pixel Height not found"); int actualPixelHeight = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) intValue]; - ASSERT_EQ_MSG(actualPixelHeight, 1024, "FAILED: ImageIOTest::Height"); + EXPECT_EQ(1024, actualPixelHeight); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyOrientation), "FAILED: ImageIOTest::Orientation not found"); int actualOrientation = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyOrientation) intValue]; - ASSERT_EQ_MSG(actualOrientation, 2, "FAILED: ImageIOTest::Orientation"); + EXPECT_EQ(2, actualOrientation); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationImageOptionsGIFTest) { +TEST(ImageIO, DestinationImageOptionsGIFTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1490,11 +1503,11 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFRelease(myImageDest); imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyGIFDictionary), "FAILED: ImageIOTest::GIF dictionary not found"); @@ -1510,12 +1523,12 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPixelHeight), "FAILED: ImageIOTest::Pixel Height not found"); int actualPixelHeight = [(id)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) intValue]; - ASSERT_EQ_MSG(actualPixelHeight, 1024, "FAILED: ImageIOTest::Height"); + EXPECT_EQ(1024, actualPixelHeight); CFRelease(imageSource); } -DISABLED_TEST(ImageIO, DestinationImageOptionsPNGTest) { +TEST(ImageIO, DestinationImageOptionsPNGTest) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); @@ -1546,11 +1559,11 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { CFRelease(myImageDest); imageData = getDataFromImageFile(outFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", outFile); imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - ASSERT_TRUE_MSG(imageProperties != nil, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); + ASSERT_NE_MSG(nil, imageProperties, "FAILED: ImageIOTest::CGImageSourceCopyPropertiesAtIndex returned nullptr"); ASSERT_TRUE_MSG(CFDictionaryContainsKey(imageProperties, kCGImagePropertyPNGDictionary), "FAILED: ImageIOTest::PNG dictionary not found"); @@ -1558,7 +1571,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { ASSERT_TRUE_MSG(CFDictionaryContainsKey(pngDictionary, kCGImagePropertyPNGGamma), "FAILED: ImageIOTest::PNG dictionary does not contain Gamma"); int actualGamma = [(id)CFDictionaryGetValue(pngDictionary, kCGImagePropertyPNGGamma) intValue]; - ASSERT_EQ_MSG(actualGamma, 45045, "FAILED: ImageIOTest::PngGamma"); + EXPECT_EQ(45045, actualGamma); CFRelease(imageSource); } @@ -1571,7 +1584,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalJPEGImageWithFrameCheck) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -1592,7 +1605,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame = { 1, 95, 96, 3850, 3851, 218939, 218940 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -1628,7 +1641,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalBMPImageWithFrameCheck) { const wchar_t* imageFile = L"testimg_227x149.bmp"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -1651,7 +1664,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame = { 1, 95, 96, 35049, 35050 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -1687,7 +1700,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalPNGImageWithFrameCheck) { const wchar_t* imageFile = L"seafloor_256x256.png"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references - 907 for Apple's implementation @@ -1709,7 +1722,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame = { 1, 95, 96, 906, 907, 59505, 59506 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -1745,7 +1758,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalTIFFImageWithFrameCheck) { const wchar_t* imageFile = L"photo8_4layers_1024x683.tif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -1787,7 +1800,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame4 = { 1, 95, 96, 4184267, 4184268, 4187741, 4187742 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -1876,7 +1889,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalGIFImageWithFrameCheck) { const wchar_t* imageFile = L"photo7_4layers_683x1024.gif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -1922,7 +1935,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame4 = { 1, 95, 96, 613937, 613938, 613946, 613947, 614712, 614713, 669892, 669893 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -2011,7 +2024,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalICOImageWithFrameCheck) { const wchar_t* imageFile = L"photo2_683x1024.ico"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -2034,7 +2047,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame = { 1, 95, 96, 1041875, 1041876 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Check container status change sequence at corresponding stream lengths for (int index = 0; index < c_streamLengthForContainer.size(); index++) { @@ -2070,7 +2083,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, IncrementalTIFFNegativeScenario) { const wchar_t* imageFile = L"photo8_4layers_1024x683.tif"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); NSUInteger imageLength = [imageData length]; // Minimum Stream Length at which CGImageSourceCreateImageAtIndex returns valid image references @@ -2096,7 +2109,7 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { static const std::vector c_streamLengthForFrame3 = { 1, 95, 96, 3129165, 3129166, 4184257, 4184258 }; CGImageSourceRef imageRef = CGImageSourceCreateIncremental(nil); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: CGImageSourceCreateIncremental returned nullptr"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: CGImageSourceCreateIncremental returned nullptr"); // Different indices fed to CGImageSourceCreateImageAtIndex and CGImageSourceGetStatusAtIndex bool imageStart = false; @@ -2151,21 +2164,21 @@ static CFURLRef getURLRefForOutFile(const wchar_t* filename) { TEST(ImageIO, NonIncrementalJPEGSource) { const wchar_t* imageFile = L"photo6_1024x670.jpg"; NSData* imageData = getDataFromImageFile(imageFile); - ASSERT_TRUE_MSG(imageData != nil, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); + ASSERT_NE_MSG(nil, imageData, "FAILED: ImageIOTest::Could not find file: [%s]", imageFile); CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, nullptr); - ASSERT_TRUE_MSG(imageSource != nil, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); + ASSERT_NE_MSG(nil, imageSource, "FAILED: ImageIOTest::CGImageSourceCreateWithData returned nullptr"); - ASSERT_EQ_MSG(CGImageSourceGetStatus(imageSource), kCGImageStatusComplete, "FAILED: ImageIOTest::ContainerStatus"); - ASSERT_EQ_MSG(CGImageSourceGetStatusAtIndex(imageSource, 0), kCGImageStatusUnknownType, "FAILED: ImageIOTest::ImageStatusAtIndex"); + EXPECT_EQ(kCGImageStatusComplete, CGImageSourceGetStatus(imageSource)); + ASSERT_EQ(kCGImageStatusUnknownType, CGImageSourceGetStatusAtIndex(imageSource, 0)); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, nullptr); - ASSERT_TRUE_MSG(imageRef != nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); - ASSERT_EQ_MSG(CGImageSourceGetStatusAtIndex(imageSource, 0), kCGImageStatusComplete, "FAILED: ImageIOTest::ImageStatusAtIndex"); + ASSERT_NE_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex returned nullptr"); + EXPECT_EQ(kCGImageStatusComplete, CGImageSourceGetStatusAtIndex(imageSource, 0)); imageRef = CGImageSourceCreateImageAtIndex(imageSource, 1, nullptr); - ASSERT_TRUE_MSG(imageRef == nil, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); - ASSERT_EQ_MSG(CGImageSourceGetStatusAtIndex(imageSource, 1), kCGImageStatusUnknownType, "FAILED: ImageIOTest::ImageStatusAtIndex"); + ASSERT_EQ_MSG(nil, imageRef, "FAILED: ImageIOTest::CGImageSourceCreateImageAtIndex should return nullptr"); + EXPECT_EQ(kCGImageStatusUnknownType, CGImageSourceGetStatusAtIndex(imageSource, 1)); CFRelease(imageSource); } \ No newline at end of file