Skip to content

Commit

Permalink
Added Surface.Image.init(data:)
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Jun 10, 2017
1 parent 0a46d6b commit 59f8e1e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Cairo/SurfaceImage.swift
Expand Up @@ -39,6 +39,17 @@ public extension Surface {
try super.init(internalPointer)
}

/// Creates an image surface for the provided pixel data, copying the buffer.
public convenience init(data: Data, format: ImageFormat, width: Int, height: Int, stride: Int) throws {

var data = data

// a bit unsafe, but cant use self.init inside closure.
let bytes: UnsafeMutablePointer<UInt8> = data.withUnsafeMutableBytes { $0 }

try self.init(mutableBytes: bytes, format: format, width: width, height: height, stride: stride)
}

/// For internal use with extensions (e.g. `init(png:)`)
internal override init(_ internalPointer: OpaquePointer) throws {

Expand Down

0 comments on commit 59f8e1e

Please sign in to comment.