SDWebImage / SDWebImageAVIFCoder

A SDWebImage coder plugin to support AVIF(AV1 Image File Format) image
MIT License
55 stars 14 forks source link

Some HDR contents can not render correctly using AVIFCoder #54

Closed dreampiggy closed 1 year ago

dreampiggy commented 1 year ago

Sample: example.avif.zip

image

image

image Seems HDR contents ?

weaming commented 1 year ago

any update?

dreampiggy commented 1 year ago

I' have a try with libavif's YUVToRGB16 convert method, instead of current conversion written using Apple's vImage.

dreampiggy commented 1 year ago

Seems this image use Color Space transfer function AVIF_TRANSFER_CHARACTERISTICS_SMPTE2084

which is not supported by CGColorSpace. Different naming, CGColorSpace has PQ suffix one

However, it supported by CVPixelBuffer and CoreVideo: https://developer.apple.com/documentation/corevideo/kcvimagebuffertransferfunction_smpte_st_2084_pq

We can use the CoreVideo, which use CVPixelBuffer (instead of current vImage_Buffer), and call VTCreateCGImageFromCVPixelBuffer(https://developer.apple.com/documentation/videotoolbox/1536089-vtcreatecgimagefromcvpixelbuffer) to get CGImage

dreampiggy commented 1 year ago

A stupid solution:

  1. If we detect some color space or format can not supported by Apple's Image/Video Framework, then call avifImageRGBToYUV
  2. For others, use the exists code which use vImageConvert and CGColorSpace to convert, seems faster
dreampiggy commented 1 year ago

😂 @ledyba-z

image

Seems this code is from you ?

I'll decide to revert back to old avifImageRGBToYUV (slow but work) and color space convert for those non-supported image. Any idea or can you have time for help ? Seems the color space convert is complicated beyond my knowledge.

dreampiggy commented 1 year ago

Should I hack to just use kCGColorSpaceITUR_2100_PQ in RGB instead ?😂 Looks visible similar

image