                  shouldInterpolate: true,
                             intent: .defaultIntent)
     }
+    
+    // MARK: - JPEG and PNG Support
+    
+    func imageFrom(_ data: Data, format: Format) -> CGImage? {
+        switch format {
+        case jpeg:
+            return (image: CGImage(jpegDataProviderSource: CGDataProvider(data), decode: nil, shouldInterpolate: true, intent: .default), data: data)
+        case png:
+            return init(image: CGImage(pngDataProviderSource: CGDataProvider(data), decode: nil, shouldInterpolate: true, intent: .default), data: data)
+        default:
+            return nil
+        }
+    }
 }

///
/// To draw an image, use 2DContext.drawImage(:in:).
open struct Image {
    
    private var image: CGImage
    let size: Size {
        return Size(image.size.width, image.size.height)
    }

    var bytesPerRow: UInt {
        return image.bytesPerRow
    }
    var colorSpace: ColorSpace {
        return ColorSpace(image.colorSpace)
    }
    var data: Data
    
    // MARK: - Initialization

    convenience init(url: URL) throws {
        guard let format = formatFileExtensions[url.pathExtension] else {
            throw Error.unsupportedImageFormat
        }
        return init(data: Data(url: url), format: format)
    }
    
    required init(data: Data, format: Format) throws {
        guard let image = formatSources[format](data, format: format) else {
            throw Error.unsupportedFormat
        }
        self.image = image
        self.data = data
        self.format = format
    }
    
    required init(size: Size) {
    
    }
    
    private required init(size: Size, bitsPerComponent: BitsPerComponent, bitsPerPixel: UIInt8, bytesPerRow: UIInt, info: CGBitmapInfo, provider: CGDataProvider) {
        self.data = data
        self.image = CGImage(width: size.width,
                            height: size.height,
