How fl0p/lg works
Project Type and Purpose
• This is a single-target native iOS application (“Liquid Glass”) whose sole purpose is to render a realistic magnifying-glass effect on images, using a combination of UIKit for the UI, CoreImage for image filtering, and Metal for high-performance custom shaders.
File‐Structure Analysis
• Top-level: Xcode project files (.xcodeproj), app target folder lg/, resources folder lg/Assets.xcassets, Metal shader files (.metal, .ci.metal), source files (.swift), storyboards (.storyboard), and app lifecycle (AppDelegate.swift, SceneDelegate.swift).
• No backend/server components—pure client-side.
• Custom filter code lives in DisplacementMapFilter.swift + .ci.metal; UI and interaction code in ViewController.swift, LGView.swift, DragManager.swift.
README Insights
• The README confirms a focus on a custom “Displacement Map Filter” implemented with Metal and CoreImage, with real-time adjustable parameters via sliders.
Main Components
a. UI Layer
• UIKit Storyboard & Swift UI Controllers:
• LaunchScreen & Main.storyboard
• ViewController.swift (wiring UI elements & sliders)
• LGView.swift (custom UIView subclass that hosts the Metal/CoreImage output)
b. Interaction Layer
• DragManager.swift handles touch events (pan, tap) and forwards adjusted lens parameters.
c. Rendering/Filter Layer
• DisplacementMapFilter.swift: orchestrates a CoreImage filter chain using a custom CIKernel loaded from Displacement.ci.metal.
• Metal runtime: GPU device/context created by CoreImage under the hood; raw Metal entry points in File.metal or the CIKernel.
d. Resources
• Shader sources (.metal, .ci.metal).
e. System & Frameworks
• iOS Application Lifecycle: AppDelegate + SceneDelegate
• Frameworks: UIKit, CoreImage, Metal
Relationships & Data Flow
1. User Input → DragManager
• Touch gestures captured by LGView → delegated to DragManager → updates lens parameters.
2. Parameter Update → ViewController
• DragManager notifies ViewController (or directly LGView) of new parameter values.
3. ViewController → DisplacementMapFilter
• On each frame or slider change, ViewController invokes DisplacementMapFilter, passing the input image + lens parameters.
4. DisplacementMapFilter → GPU/CI Kernel
• Filter compiles CIKernel (from Displacement.ci.metal), executes on GPU via CoreImage’s Metal-backed context.
5. Result → LGView
• The output CIImage (or MTLTexture) is rendered back into LGView’s layer for display.
Architectural Patterns & Principles
• MVC-like separation:
• Model: lens parameters (width, radius, scale, etc.)
• View: storyboards + LGView
• Controller: ViewController + DragManager
• Single Responsibility:
• DragManager only deals with gestures
• DisplacementMapFilter only deals with image processing
• GPU Acceleration: offload heavy compute to Metal