BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.85k stars 605 forks source link

Strange artefacts/shadows when using normal blend of two images #294

Open jwoodrow opened 5 years ago

jwoodrow commented 5 years ago

When capturing still images (to create a gif) from the camera on which I apply a normal blend of the following image for example (transparent background):

Filter

I sendup with some kind of shadow or artefacting on the final image:

Resulting GIF

I managed to reduce it slightly by making the filter image larger (it's originally 480x640 but the artefacting happens less when using 960x1280):

Slightly better GIF

I can't seem to not get any of the grey borders (or shadows or artefacts or whatever it's called).

using PictureInput(image: filter, smoothlyScaleOutput: true, orientation: ImageOrientation.portrait) does not help and I'd even go as far as to say it makes things worse.

My blend workflow is this way: Camera -> xFlip (mirror effect) -> normalBlend (filter) -> pictureOutput (changing encodedImageFormat from jpg to png does not affect this)

any clues on where to look ?

zubco commented 5 years ago

@jwoodrow the issue might be in the (#CliniqueiD) asset itself, try export a cleaner version of it (without shadows/antialiasing) ;)

BradLarson commented 5 years ago

I think what you're seeing is the result of the way that premultiplied alpha is handled with images in the framework. This is something that was the subject of quite a bit of debate in the original GPUImage:

https://github.com/BradLarson/GPUImage/issues/2535 https://github.com/BradLarson/GPUImage/issues/1210#issuecomment-25182881

and honestly I'm not sure where we ended up on how to handle that. It either needs to be fixed in the input so that we don't use premultiplied alpha when loading images or in each shader that works with blended content. The former would be preferred, but I can't recall why I haven't implemented that yet.