DEV Community

gezilinll
gezilinll

Posted on

I have implemented a GPU version of Pica which is high quailty image resizer

πŸ”— GitHub Repo: https://github.com/gezilinll/pica-gpu
πŸ”— Demo: https://pica-gpu.gezilinll.com

Recently, while using Pica in a project, I noticed that both CPU and memory usage were quite high. When processing multiple images, the application would sometimes freeze or even crash. After reviewing the source code, I have to say that Pica's current CPU-based implementation is already optimized to an extreme level.

From what I observed, Pica's main optimization lies in its use of advanced filters for image scaling instead of conventional methods like nearest-neighbor interpolation (which prioritizes performance over quality). These filters have higher computational complexity but produce better results. Since filtering mainly controls how target pixels sample from the original image, and each pixel can be processed independently, this logic is inherently well-suited for GPU execution.

I have ported all of Pica's filtering algorithms to WebGL, creating a GPU-based version of Pica. In theory, using Compute Shaders could further improve performance, but since it requires WebGPU, which has compatibility concerns, I have not implemented that yet.

On the algorithm side, apart from mks2013, other filters theoretically support additional sharpening parameters. However, since our project primarily uses mks2013, which already provides excellent results, I haven't introduced sharpening logic to other filters yetβ€”this is something I may improve in the future.

Currently, the GPU version of Pica achieves the same anti-moirΓ© effect and sharpness as the original Pica while improving performance by 2-10Γ—, with greater speedup for larger images. Additionally, because the GPU implementation avoids creating extra buffers, memory usage is lower. CPU load is also significantly reduced, which should help prevent performance bottlenecks.

Since Pica is designed as a CPU-based, JavaScript implementation, modifying it directly via a PR might be challenging for me. Instead, I have created a separate project.

I’d love for the community to collaborate on this! Any feedback or contributions would be greatly appreciated. Lastly, huge thanks to Pica for making our project possible! 😊

Top comments (0)