Skip to content

Fix the CGImageCreateScaled to support 16/32 bit depth CGImage (RGB161616) and always preserve pixel format info#3575

Merged
dreampiggy merged 2 commits intoSDWebImage:masterfrom
dreampiggy:bugfix/CGImageCreateScale
Jul 29, 2023
Merged

Fix the CGImageCreateScaled to support 16/32 bit depth CGImage (RGB161616) and always preserve pixel format info#3575
dreampiggy merged 2 commits intoSDWebImage:masterfrom
dreampiggy:bugfix/CGImageCreateScale

Conversation

@dreampiggy
Copy link
Copy Markdown
Contributor

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

This fix the issue I found in https://github.com/SDWebImage/SDWebImageAVIFCoder
The created 16-bit depth CGImage will fail on this. vImage need to handle the pixel format one by one, let's add the dummy code.....

Test Result :

<CGImage 0x100645080> (DP)
	<<CGColorSpace 0x600002603900> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Rec. ITU-R BT.2100 PQ)>
		width = 4500, height = 3000, bpc = 16, bpp = 48, row bytes = 27000 
		kCGImageAlphaNone | kCGImageByteOrder16Little  | kCGImagePixelFormatPacked 
		is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? No
Printing description of imageRef:
<CGImage 0x100c0c460> (IP)
	<<CGColorSpace 0x600002603900> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Rec. ITU-R BT.2100 PQ)>
		width = 128, height = 86, bpc = 16, bpp = 48, row bytes = 768 
		kCGImageAlphaNone | kCGImageByteOrder16Little  | kCGImagePixelFormatPacked 
		is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes

@dreampiggy dreampiggy changed the title Fix the CGImageCreateScaled to support 16/32 bits CGImage (RGB161616) and always preserve pixel format info Fix the CGImageCreateScaled to support 16/32 bit depth CGImage (RGB161616) and always preserve pixel format info Jul 28, 2023
vImageBuffer_Init(&output_buffer, size.height, size.width, (uint32_t)bitsPerComponent * components, kvImageNoFlags);
if (!output_buffer.data) return NULL;

vImage_Error ret = vImageScale_ARGB8888(&input_buffer, &output_buffer, NULL, kvImageHighQualityResampling);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not found any good way to workaround this below code...Such as template boilerplate...:(

@dreampiggy
Copy link
Copy Markdown
Contributor Author

The unit test is the complicated test I wrote recently....
Test RGB888/RGB16/ARGB8888/RGB16/RGBF works on CGImageCreateScaled, because it's Foundation of coder plugin for thumbnail processing

@dreampiggy dreampiggy force-pushed the bugfix/CGImageCreateScale branch from 0fdfb8e to 0ca66bc Compare July 28, 2023 15:44
Test RGB888/RGB16/ARGB8888/RGB16/RGBF works on CGImageCreateScaled, because it's Foundation of coder plugin for thumbnail processing
@dreampiggy dreampiggy force-pushed the bugfix/CGImageCreateScale branch from 0ca66bc to 68c5808 Compare July 28, 2023 15:45
@dreampiggy dreampiggy merged commit 7e78633 into SDWebImage:master Jul 29, 2023
@dreampiggy dreampiggy added this to the 5.18.0 milestone Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant