본문 바로가기
#컴퓨터 과학 [Computer Science]/운영체제 (Operating System)

[OS - 🍎 macOS] macOS 디스플레이 정보 가져오는 방법 (How to get display information on macOS)

by cy_mos 2023. 3. 27.
반응형
카테고리 게시글 작성 날짜 게시글 최근 수정 날짜 작성자
Operating System 2023.03.27. 22:39 2023.03.27. 22:39 Dev.Yang

 

※ 색 심도 (Color Depth)

1개의 픽셀에서 표현할 수 있는 색의 수. RGB(적·녹·청) 각각에 대해 몇 비트씩 할당해서 이의 조합으로 여러 가지 색을 나타내는, 즉 비트 수로 색의 수를 표현하는 것을 말한다. RGB 각 8비트인 경우에 24비트이므로 색심도는 24비트가 된다. 경우에 따라서는 RGB 외에 투명도 8비트를 추가하여 RGBA 32비트가 되는 경우도 있다. 24비트로 표현할 수 있는 색의 수는 16,777,216색이며, 이것을 "24비트 컬러" 라 부르기도 한다. 

[네이버 지식백과] 색심도 [color depth, 色深度] (IT용어사전, 한국정보통신기술협회)

※ 색 공간 (Color Space)

일반적으로 적·녹·청 3원색의 조합으로 표현되는 색 모델 좌표계에서 나타낼 수 있는 색상의 범위.사람의 눈은 전자 장치가 복사할 수 없는 다양한 색을 감지할 수 있기 때문에 가장 포괄적인 색 공간이라 할 수 있다. 실제적으로는 효율적인 컬러 영상 처리를 목적으로 개발되어 국제적으로 표준화된 국제조명위원회(CIE) 색도도가 주로 사용된다. 모니터나 인쇄기가 재현하는 색상의 범위를 말하며, 색상 범위와 같은 의미이다. 

[네이버 지식백과] 색 공간 [color space, 色空間] (IT용어사전, 한국정보통신기술협회)


🛠 소스 코드 (Source Code)

public struct SKDisplayOutputUnitResult: Codable {
    
    // MARK: Integer Properties
    
    /// The window number of the window’s window device.
    public let windowNumber: Int
    
    /// the bit depth of the window’s raster image (2-bit, 8-bit, and so forth)
    public var bitsPerSample: Optional<Int> = nil
    
    // MARK: Double Properties
    
    /// A screen resolution width value.
    public var frameWidth: Optional<Double> = nil
    
    /// A screen resolution height value.
    public var frameHeight: Optional<Double> = nil
    
    /// A raster screen resolution width value.
    public var rasterWidth: Optional<Double> = nil
    
    /// A raster screen resolution height value.
    public var rasterHeight: Optional<Double> = nil
    
    // MARK: String Properties
    
    /// The name of the window’s color space.
    public var colorSpaceName: Optional<String> = nil
    
    // MARK: Bool Properties
    
    /// The display device is a screen.
    public var isScreen: Optional<Bool> = nil
    
    /// The display device is a printer.
    public var isPrinter: Optional<Bool> = nil
}

/**
        출력장치 (Output Device) 정보를 가져오는 함수입니다.
     
        - Authors: `ChangYeop-Yang`
        - Returns: `Array<SKDisplayOutputUnitResult>`
     */
    final func getDisplayOutputUnit() -> Array<SKDisplayOutputUnitResult> {
        
        var result: Array<SKDisplayOutputUnitResult> = Array.init()
        
        for (windowNumber, screen) in NSScreen.screens.enumerated() {
            
            var newElement = SKDisplayOutputUnitResult(windowNumber: windowNumber)

            // The bit depth of the window’s raster image (2-bit, 8-bit, and so forth).
            let bitsPerSampleKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.bitsPerSample
            if let bitsPerSample = screen.deviceDescription[bitsPerSampleKey] as? NSNumber {
                
                // RGB(적·녹·청) 각각에 대해 몇 비트씩 할당해서 이의 조합으로 여러 가지 색을 나타내는, 즉 비트 수로 색의 수를 표현하는 것을 말한다.
                newElement.bitsPerSample = bitsPerSample.intValue
            }
            
            // The name of the window’s color space.
            let colorSpaceNameKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.colorSpaceName
            if let colorSpaceName = screen.deviceDescription[colorSpaceNameKey] as? NSString {
                
                // 일반적으로 적·녹·청 3원색의 조합으로 표현되는 색 모델 좌표계에서 나타낼 수 있는 색상의 범위를 뜻한다.
                newElement.colorSpaceName = colorSpaceName as String
            }
            
            // The size of the window’s frame rectangle.
            let sizeKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.size
            if let size = screen.deviceDescription[sizeKey] as? NSSize {
                
                // 내장 디스플레이의 해상도의 크기를 뜻합니다.
                newElement.frameWidth = size.width
                newElement.frameHeight = size.height
            }
            
            // The window’s raster resolution in dots per inch (dpi).
            let resolutionKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.resolution
            if let resolution = screen.deviceDescription[resolutionKey] as? NSSize {

                // 내장 디스플레이의 래스터 해상도의 단위 인 DPI(인치당 도트수)의 크기를 뜻합니다.
                newElement.rasterWidth = resolution.width
                newElement.rasterHeight = resolution.height
            }
            
            // The display device is a screen.
            let isScreenKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.isScreen
            if let isScreen = screen.deviceDescription[isScreenKey] as? NSString {
                
                // 해당 디스플레이 장치가 화면을 나타내는 출력 장치 여부를 확인합니다.
                newElement.isScreen = isScreen.boolValue
            }
            
            // The display device is a printer.
            let isPrinterKey: NSDeviceDescriptionKey = NSDeviceDescriptionKey.isPrinter
            if let isPrinter = screen.deviceDescription[isPrinterKey] as? NSString {
                
                // 해당 디스플레이 장치가 프린터 출력 장치 여부를 확인합니다.
                newElement.isPrinter = isPrinter.boolValue
            }
    
            result.append(newElement)
        }
        
        return result
    }

🚀 REFERENCE

반응형

댓글