diff --git a/Frameworks/CoreGraphics/CGImage.mm b/Frameworks/CoreGraphics/CGImage.mm index c8239ca863..7c6c861ece 100644 --- a/Frameworks/CoreGraphics/CGImage.mm +++ b/Frameworks/CoreGraphics/CGImage.mm @@ -45,6 +45,187 @@ COREGRAPHICS_EXPORT void CGImageAddDestructionListener(CGImageDestructionListene #pragma endregion OLD_CODE +#pragma region CGImageImplementation + +struct __CGImageImpl { + Microsoft::WRL::ComPtr bitmapImageSource; + bool isMask; + bool interpolate; + woc::unique_cf colorSpace; + CGImageAlphaInfo alphaInfo; + size_t height; + size_t width; + size_t bitsPerPixel; + size_t bitsPerComponent; + size_t bytesPerRow; + CGBitmapInfo bitmapInfo; + CGColorRenderingIntent renderingIntent; + + __CGImageImpl() { + height = 0; + width = 0; + bitsPerComponent = 0; + bitsPerPixel = 0; + bytesPerRow = 0; + bitmapInfo = kCGBitmapByteOrderDefault; + alphaInfo = kCGImageAlphaNone; + isMask = false; + interpolate = false; + renderingIntent = kCGRenderingIntentDefault; + } + + inline WICPixelFormatGUID PixelFormat() const { + WICPixelFormatGUID pixelFormat; + RETURN_RESULT_IF_FAILED(bitmapImageSource->GetPixelFormat(&pixelFormat), GUID_WICPixelFormatUndefined); + return pixelFormat; + } + + inline const __CGImagePixelProperties* Properties() const { + WICPixelFormatGUID pixelFormat = PixelFormat(); + return _CGGetPixelFormatProperties(pixelFormat); + } + + inline size_t BitsPerPixel() const { + const __CGImagePixelProperties* properties = Properties(); + RETURN_RESULT_IF_NULL(properties, 0); + return properties->bitsPerPixel; + } + + inline size_t BitsPerComponent() const { + const __CGImagePixelProperties* properties = Properties(); + RETURN_RESULT_IF_NULL(properties, 0); + return properties->bitsPerComponent; + } + + inline CGBitmapInfo BitmapInfo() const { + const __CGImagePixelProperties* properties = Properties(); + RETURN_RESULT_IF_NULL(properties, 0); + return properties->bitmapInfo; + } + + inline CGImageAlphaInfo AlphaInfo() const { + return static_cast(BitmapInfo() & kCGBitmapAlphaInfoMask); + } + + inline CGColorSpaceRef ColorSpace() { + const __CGImagePixelProperties* properties = Properties(); + RETURN_NULL_IF(!properties); + return _CGColorSpaceCreate(properties->colorSpaceModel); + } + + inline void SetImageSource(Microsoft::WRL::ComPtr source) { + bitmapImageSource = std::move(source); + // populate the image info. + if (FAILED(bitmapImageSource->GetSize(&width, &height))) { + height = 0; + width = 0; + } + + bitmapInfo = BitmapInfo(); + alphaInfo = AlphaInfo(); + bitsPerPixel = BitsPerPixel(); + bitsPerComponent = BitsPerComponent(); + bytesPerRow = (bitsPerPixel >> 3) * width; + if (!colorSpace) { + colorSpace.reset(ColorSpace()); + } + } +}; + +struct __CGImage : CoreFoundation::CppBase<__CGImage> { + // TODO(JJ) REMOVE THIS; Merge Impl into __CGImage. + __CGImageImpl _impl; + + inline Microsoft::WRL::ComPtr& ImageSource() { + return _impl.bitmapImageSource; + } + + inline void* Data() const { + Microsoft::WRL::ComPtr lock; + RETURN_NULL_IF_FAILED(_impl.bitmapImageSource->Lock(nullptr, WICBitmapLockWrite, &lock)); + BYTE* data; + UINT size; + RETURN_NULL_IF_FAILED(lock->GetDataPointer(&size, &data)); + return static_cast(data); + } + + inline size_t Height() const { + return _impl.height; + } + + inline size_t Width() const { + return _impl.width; + } + + inline bool IsMask() const { + return _impl.isMask; + } + + inline bool Interpolate() const { + return _impl.interpolate; + } + + inline CGColorSpaceRef ColorSpace() { + return _impl.colorSpace.get(); + } + + inline CGColorRenderingIntent RenderingIntent() const { + return _impl.renderingIntent; + } + + inline CGBitmapInfo BitmapInfo() const { + return _impl.bitmapInfo; + } + + inline CGImageAlphaInfo AlphaInfo() const { + return _impl.alphaInfo; + } + + inline size_t BitsPerPixel() const { + return _impl.bitsPerPixel; + } + + inline size_t BytesPerRow() const { + return _impl.bytesPerRow; + } + + inline size_t BitsPerComponent() const { + return _impl.bitsPerComponent; + } + + inline WICPixelFormatGUID PixelFormat() const { + return _impl.PixelFormat(); + } + + inline __CGImage& SetImageSource(Microsoft::WRL::ComPtr source) { + _impl.SetImageSource(source); + return *this; + } + + inline __CGImage& SetIsMask(bool mask) { + _impl.isMask = mask; + return *this; + } + + inline __CGImage& SetInterpolate(bool interpolate) { + _impl.interpolate = interpolate; + return *this; + } + + inline __CGImage& SetColorSpace(CGColorSpaceRef space) { + _impl.colorSpace.reset(space); + CGColorSpaceRetain(space); + return *this; + } + + inline __CGImage& SetRenderingIntent(CGColorRenderingIntent intent) { + _impl.renderingIntent = intent; + return *this; + } +}; + +#pragma endregion CGImageImplementation + /** @Status Interoperable */ @@ -346,8 +527,7 @@ CGImageRef CGImageCreateCopyWithColorSpace(CGImageRef ref, CGColorSpaceRef color @Status Stub */ CGImageRef CGImageCreateWithMask(CGImageRef image, CGImageRef mask) { - // TODO #1124: Given how masks are applied during rendering via D2D, we will hold onto the - // mask then apply it at the appropriate time. + // TODO #1425 - masks are applied during rendering via D2D. RETURN_NULL_IF(!image); UNIMPLEMENTED(); return StubReturn(); diff --git a/Frameworks/include/CGImageInternal.h b/Frameworks/include/CGImageInternal.h index a049c49a21..b4372e655d 100644 --- a/Frameworks/include/CGImageInternal.h +++ b/Frameworks/include/CGImageInternal.h @@ -36,8 +36,6 @@ #import #include -class CGContextImpl; - typedef struct { CGColorSpaceModel colorSpaceModel; CGBitmapInfo bitmapInfo; @@ -97,185 +95,6 @@ static const std::map s_PixelForm bool _CGIsValidRenderTargetPixelFormat(WICPixelFormatGUID pixelFormat); const __CGImagePixelProperties* _CGGetPixelFormatProperties(WICPixelFormatGUID pixelFormat); -struct __CGImageImpl { - Microsoft::WRL::ComPtr bitmapImageSource; - bool isMask; - bool interpolate; - woc::unique_cf colorSpace; - CGImageAlphaInfo alphaInfo; - size_t height; - size_t width; - size_t bitsPerPixel; - size_t bitsPerComponent; - size_t bytesPerRow; - CGBitmapInfo bitmapInfo; - CGColorRenderingIntent renderingIntent; - - __CGImageImpl() { - height = 0; - width = 0; - bitsPerComponent = 0; - bitsPerPixel = 0; - bytesPerRow = 0; - bitmapInfo = kCGBitmapByteOrderDefault; - alphaInfo = kCGImageAlphaNone; - isMask = false; - interpolate = false; - renderingIntent = kCGRenderingIntentDefault; - } - - inline WICPixelFormatGUID PixelFormat() const { - WICPixelFormatGUID pixelFormat; - RETURN_RESULT_IF_FAILED(bitmapImageSource->GetPixelFormat(&pixelFormat), GUID_WICPixelFormatUndefined); - return pixelFormat; - } - - inline const __CGImagePixelProperties* Properties() const { - WICPixelFormatGUID pixelFormat = PixelFormat(); - return _CGGetPixelFormatProperties(pixelFormat); - } - - inline size_t BitsPerPixel() const { - const __CGImagePixelProperties* properties = Properties(); - RETURN_RESULT_IF_NULL(properties, 0); - return properties->bitsPerPixel; - } - - inline size_t BitsPerComponent() const { - const __CGImagePixelProperties* properties = Properties(); - RETURN_RESULT_IF_NULL(properties, 0); - return properties->bitsPerComponent; - } - - inline CGBitmapInfo BitmapInfo() const { - const __CGImagePixelProperties* properties = Properties(); - RETURN_RESULT_IF_NULL(properties, 0); - return properties->bitmapInfo; - } - - inline CGImageAlphaInfo AlphaInfo() const { - return static_cast(BitmapInfo() & kCGBitmapAlphaInfoMask); - } - - inline CGColorSpaceRef ColorSpace() { - const __CGImagePixelProperties* properties = Properties(); - RETURN_NULL_IF(!properties); - return _CGColorSpaceCreate(properties->colorSpaceModel); - } - - inline void SetImageSource(Microsoft::WRL::ComPtr source) { - bitmapImageSource = std::move(source); - // populate the image info. - if (FAILED(bitmapImageSource->GetSize(&width, &height))) { - height = 0; - width = 0; - } - - bitmapInfo = BitmapInfo(); - alphaInfo = AlphaInfo(); - bitsPerPixel = BitsPerPixel(); - bitsPerComponent = BitsPerComponent(); - bytesPerRow = (bitsPerPixel >> 3) * width; - if (!colorSpace) { - colorSpace.reset(ColorSpace()); - } - } -}; - -struct __CGImage : CoreFoundation::CppBase<__CGImage> { - // TODO(JJ) REMOVE THIS; Merge Impl into __CGImage. - __CGImageImpl _impl; - - inline Microsoft::WRL::ComPtr& ImageSource() { - return _impl.bitmapImageSource; - } - - inline void* Data() const { - Microsoft::WRL::ComPtr lock; - RETURN_NULL_IF_FAILED(_impl.bitmapImageSource->Lock(nullptr, WICBitmapLockWrite, &lock)); - BYTE* data; - UINT size; - RETURN_NULL_IF_FAILED(lock->GetDataPointer(&size, &data)); - return static_cast(data); - } - - inline size_t Height() const { - return _impl.height; - } - - inline size_t Width() const { - return _impl.width; - } - - inline bool IsMask() const { - return _impl.isMask; - } - - inline bool Interpolate() const { - return _impl.interpolate; - } - - inline CGColorSpaceRef ColorSpace() { - return _impl.colorSpace.get(); - } - - inline CGColorRenderingIntent RenderingIntent() const { - return _impl.renderingIntent; - } - - inline CGBitmapInfo BitmapInfo() const { - return _impl.bitmapInfo; - } - - inline CGImageAlphaInfo AlphaInfo() const { - return _impl.alphaInfo; - } - - inline size_t BitsPerPixel() const { - return _impl.bitsPerPixel; - } - - inline size_t BytesPerRow() const { - return _impl.bytesPerRow; - } - - inline size_t BitsPerComponent() const { - return _impl.bitsPerComponent; - } - - inline WICPixelFormatGUID PixelFormat() const { - return _impl.PixelFormat(); - } - - inline __CGImage& SetImageSource(Microsoft::WRL::ComPtr source) { - _impl.SetImageSource(source); - return *this; - } - - inline __CGImage& SetIsMask(bool mask) { - _impl.isMask = mask; - return *this; - } - - inline __CGImage& SetInterpolate(bool interpolate) { - _impl.interpolate = interpolate; - return *this; - } - - inline __CGImage& SetColorSpace(CGColorSpaceRef space) { - _impl.colorSpace.reset(space); - CGColorSpaceRetain(space); - return *this; - } - - inline __CGImage& SetRenderingIntent(CGColorRenderingIntent intent) { - _impl.renderingIntent = intent; - return *this; - } -}; - -//--Helpers-- - COREGRAPHICS_EXPORT CGImageRef _CGImageLoadGIF(void* bytes, int length); COREGRAPHICS_EXPORT CGImageRef _CGImageLoadBMP(void* bytes, size_t length);