diff --git a/macos/Classes/TextRgba.swift b/macos/Classes/TextRgba.swift index 1708c42..c2860bf 100644 --- a/macos/Classes/TextRgba.swift +++ b/macos/Classes/TextRgba.swift @@ -4,6 +4,9 @@ // // Created by kingtous on 2023/2/17. // +// Modified by the Kitedesk fork (2026, T-4204): rows are copied one by one +// when their stride differs from the pixel buffer's. +// import Foundation import FlutterMacOS @@ -34,6 +37,12 @@ import CoreVideo } private func _markFrameAvaliable(buffer: UnsafePointer, len: Int, width: Int, height: Int, stride_align: Int) -> Bool { + // The rows of buffer are padded to stride_align. + let row = width * 4 + let stride = stride_align > 1 ? (row + stride_align - 1) / stride_align * stride_align : row + guard width > 0 && height > 0 && len >= stride * height else { + return false + } var pixelBufferCopy: CVPixelBuffer? // macOS only support 32BGRA currently. let dict: [String: Any] = [ @@ -50,7 +59,14 @@ import CoreVideo CVPixelBufferLockBaseAddress(pixelBufferCopy!, []) let ptr = CVPixelBufferGetBaseAddress(pixelBufferCopy!)! - memcpy(ptr, buffer, len) + let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBufferCopy!) + if (bytesPerRow == stride) { + memcpy(ptr, buffer, stride * height) + } else { + for y in 0..