Expand DICOM decoding and Enhanced CT support

This commit is contained in:
SantaSpeen committed 2026-11-22 01:37:28 +03:00
1 parent c7f9af8025
commit 6b95fbb1fc
9 files changed
+508 -96

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
import Foundation
enum DICOMCodec {
static func normalized(from source: URL, applyPalette: Bool = false) throws -> Data {
let decoder = Bundle.main.bundleURL.appendingPathComponent("Contents/Helpers/gdcmconv")
guard FileManager.default.isExecutableFile(atPath: decoder.path) else { throw DICOMError.transferSyntax }
let folder = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: false,
attributes: [.posixPermissions: 0o700])
defer { try? FileManager.default.removeItem(at: folder) }
let decoded = folder.appendingPathComponent("decoded.dcm")
let process = Process()
process.executableURL = decoder
process.arguments = (applyPalette ? ["--apply-lut8"] : ["--raw", "--explicit"])
+ ["-i", source.path, "-o", decoded.path]
process.standardOutput = FileHandle.nullDevice
process.standardError = FileHandle.nullDevice
try process.run()
process.waitUntilExit()
guard process.terminationReason == .exit, process.terminationStatus == 0 else {
throw DICOMError.transferSyntax
}
return try Data(contentsOf: decoded, options: .mappedIfSafe)
}
}