I am coding a basic fps app on Xcode 12.5. As of right now, Im working on a file that acts as a bridge between UIKit and the game engine used for this game. The code is provided below:
Bitmap.swift
import UIKit
public struct Bitmap
{
public private(set) var pixels: [Color]
public let width: Int
public init(width: Int, pixels: [Color])
{
self.width = width
self.pixels = pixels
}
}
public extension Bitmap
{
var height: Int
{
return pixels.count / width
}
subscript(x: Int, y: Int) -> Color
{
get { return pixels[y * width + x] }
set { pixels[y * width + x] = newValue}
}
init(width: Int, height: Int, color: Color) {
self.pixels = Array(repeating: color, count: width * height)
self.width = width
}
}
UIImage+Bitmap.swift
import UIKit
import Engine
extension UIImage {
convenience init?(bitmap: Bitmap) {
let alphaInfo = CGImageAlphaInfo.premultipliedLast
let bytesPerPixel = MemoryLayout<Color>.size
let bytesPerRow = bitmap.width * bytesPerPixel
guard let providerRef = CGDataProvider(data: Data(
bytes: bitmap.pixels, count: bitmap.height * bytesPerRow
) as CFData) else {
return nil
}
guard let cgImage = CGImage(
width: bitmap.width,
height: bitmap.height,
bitsPerComponent: 8,
bitsPerPixel: bytesPerPixel * 8,
bytesPerRow: bytesPerRow,
space: CGColorSpaceCreateDeviceRGB(),
bitmapInfo: CGBitmapInfo(rawValue: alphaInfo.rawValue),
provider: providerRef,
decode: nil,
shouldInterpolate: true,
intent: .defaultIntent
) else {
return nil
}
self.init(bitmap: cgImage)
}
}
For my UIImage+Bitmap.swift code I get the following error: "'height' is inaccessible due to 'internal' protection level"
Any help will be appreciated!