Skip to content

Commit

Permalink
renamed Surface source files
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Jun 5, 2017
1 parent af7ebc2 commit 5ccbcd0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
6 changes: 0 additions & 6 deletions Sources/Surface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public class Surface {
cairo_surface_finish(internalPointer)
}

/// Writes the surface's contents to a PNG file.
public final func writePNG(at filepath: String) {

cairo_surface_write_to_png(internalPointer, filepath)
}

// MARK: - Accessors

public final var type: SurfaceType {
Expand Down
20 changes: 15 additions & 5 deletions Sources/ImageSurface.swift → Sources/SurfaceImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ public extension Surface {
/// The contents of bits within a pixel, but not belonging to the given format are undefined.
public init?(format: ImageFormat, width: Int, height: Int) {

let internalFormat = cairo_format_t(format)

guard let internalPointer = cairo_image_surface_create(internalFormat, Int32(width), Int32(height))
guard let internalPointer = cairo_image_surface_create(cairo_format_t(format), Int32(width), Int32(height))
else { return nil }

super.init(internalPointer)
}

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

var data = data

guard let internalPointer = data.withUnsafeMutableBytes({ (bytes: UnsafeMutablePointer<UInt8>) in
cairo_image_surface_create_for_data(bytes, cairo_format_t(format), Int32(width), Int32(height), Int32(stride)) })
else { return nil }

fatalError()
super.init(internalPointer)
}

// MARK: - Class Methods
Expand All @@ -51,6 +55,12 @@ public extension Surface {

// MARK: - Accessors

/// Get the format of the surface.
public var format: ImageFormat? {

return ImageFormat(cairo_image_surface_get_format(internalPointer))
}

/// Get the width of the image surface in pixels.
public var width: Int {

Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions Sources/SurfacePNG.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// SurfacePNG.swift
// Cairo
//
// Created by Alsey Coleman Miller on 6/5/17.
//
//

import CCairo

public extension Surface {

/// Writes the surface's contents to a PNG file.
public func writePNG(at filepath: String) {

cairo_surface_write_to_png(internalPointer, filepath)
}
}
File renamed without changes.

0 comments on commit 5ccbcd0

Please sign in to comment.