Search code examples
iosswiftgpuimage

How can I tailer GPUImage2 to use only a few filters?


I want to use only a few filters within GPUImage2 in my swift project, how can I tailor GPUImage2 to only a few filters that I need?

I am not familiar with the code base, and I don't see any documentation on this.

P.S. My concern is mostly about app size, if including everything doesn't bloat the app size, I am OK with importing GPUImage as a whole.


Solution

  • This is a common question for people who want to shrink their binary size by only bringing over the operations they need, so I'll see if I can provide a canonical reference.

    The easiest way to do this is to remove the dependency on GPUImage from your project and instead manually copy into your project just the files necessary to build the core components of the framework. The platform-independent core files are these:

    • CameraConversion.swift
    • SerialDispatch.swift
    • BasicOperation.swift
    • Color.swift
    • FillMode.swift
    • Matrix.swift
    • OpenGLContext_Shared.swift
    • Timestamp.swift
    • OpenGLRendering.swift
    • ShaderProgram.swift
    • ShaderUniformSettings.swift
    • Framebuffer.swift
    • FramebufferCache.swift
    • Position.swift
    • Size.swift
    • Pipeline.swift
    • ImageOrientation.swift

    The following files also need to come over, but they have platform-specific (Mac, iOS, or Linux) variants, so you'll either need to choose the ones for your specific platform target or selectively include them to each of your various targets:

    • PictureInput.swift
    • PictureOutput.swift
    • MovieInput.swift
    • MovieOutput.swift
    • Camera.swift
    • OpenGLContext.swift
    • RenderView.swift

    With those files, you should be able to build a project that can perform image processing in the same manner as GPUImage, but without the long list of operations. If you have one or two operations you want to bring over, you can selectively copy those files into your project. You might need to copy over one or two dependencies if they are subclassed from another operation.