Upgrade to Pro — share decks privately, control downloads, hide ads and more …

二次元コードを読み取りやすくするために 画面を強制的に明るくするのは もうやめにしませんか?👀

二次元コードを読み取りやすくするために 画面を強制的に明るくするのは もうやめにしませんか?👀

Ryo Tsuzukihashi

September 03, 2023
Tweet

More Decks by Ryo Tsuzukihashi

Other Decks in Technology

Transcript

  1. public struct MetalKitView: UIViewRepresentable { @StateObject public var renderer: Renderer

    public func makeUIView(context: Context) -> MTKView { let view = MTKView(frame: .zero, device: renderer.device) view.preferredFramesPerSecond = 10 view.delegate = renderer if let layer = view.layer as? CAMetalLayer { layer.wantsExtendedDynamicRangeContent = true layer.colorspace = CGColorSpace( name: CGColorSpace.extendedLinearDisplayP3 ) view.colorPixelFormat = MTLPixelFormat.rgba16Float } return view } 
  2. public struct MetalKitView: UIViewRepresentable { @StateObject public var renderer: Renderer

    public func makeUIView(context: Context) -> MTKView { let view = MTKView(frame: .zero, device: renderer.device) view.preferredFramesPerSecond = 10 view.delegate = renderer if let layer = view.layer as? CAMetalLayer { layer.wantsExtendedDynamicRangeContent = true layer.colorspace = CGColorSpace( name: CGColorSpace.extendedLinearDisplayP3 ) view.colorPixelFormat = MTLPixelFormat.rgba16Float } return view } 
  3. public struct MetalKitView: UIViewRepresentable { @StateObject public var renderer: Renderer

    public func makeUIView(context: Context) -> MTKView { let view = MTKView(frame: .zero, device: renderer.device) view.preferredFramesPerSecond = 10 view.delegate = renderer if let layer = view.layer as? CAMetalLayer { layer.wantsExtendedDynamicRangeContent = true layer.colorspace = CGColorSpace( name: CGColorSpace.extendedLinearDisplayP3 ) view.colorPixelFormat = MTLPixelFormat.rgba16Float } return view } EDRΛ࢖͏͜ͱΛڭ͑Δ 
  4. ϋ Ҿ਺ͷWJFX͔ΒIFBESPPNΛऔಘ͢Δ extension Renderer: MTKViewDelegate { public func mtkView(_ view:

    MTKView, drawableSizeWillChange size: CGSize) {} public func draw(in view: MTKView) { let headroom: CGFloat = view.window ?. screen.currentEDRHeadroom ?? 1.0 guard var image = self.imageProvider(contentScaleFactor, headroom) else { return } 
  5. public struct ContentView: View { var content: String public var

    body: some View { MetalKitView( renderer: Renderer( imageProvider: { (scaleFactor: CGFloat, headroom: CGFloat) -> CIImage? in ……… 
  6. let colorSpace = CGColorSpace( name: CGColorSpace.extendedLinearSRGB )! let maxFillColor =

    CIColor( red: headroom, green: headroom, blue: headroom, colorSpace: colorSpace ) ContentView 
  7.  $*'JMUFSCMFOE8JUI.BTL Ͱ߹੒͢Δ let fillImage = CIImage(color: maxFillColor) let maskFilter

    = CIFilter.blendWithMask() maskFilter.maskImage = image maskFilter.inputImage = fillImage maskFilter.outputImage ? . cropped( .. . ) ContentView