PINRemoteImage icon indicating copy to clipboard operation
PINRemoteImage copied to clipboard

Better way for decoding image

Open hovox opened this issue 5 years ago • 2 comments

I'm looking into pin_decodedImageWithData method and wandering can't we find better way for decoding ? With current implementation in order to decode an image we are creating additional bitmap with the same size and draw on it. We could draw into 1x1 context like done here , concrete implementations are here. If there may be issues with image orientation(in which I'm not sure) we can do this way only when image is in portrait mode. By doing this way we can save temporary memory of image size.

hovox avatar Jun 24 '19 14:06 hovox

We can set CGContextSetInterpolationQuality to kCGInterpolationNone it should be more performant than default one. Here is the documentation link.

hovox avatar Jun 26 '19 14:06 hovox

There are cases where suggested solution(drawing on 1x1 canvas) will not work correctly. Specifically if we get HEIC encoded image which alpha is not premultiplied we will get wrong decoded image because when compositing layers iOS considers that alpha should be premultiplied. So I think current solution works right, we still can disable interpolation to have better drawing speed.

hovox avatar Jul 11 '19 06:07 hovox