Rudimentary implementation of a uncompressed PNG encoder in Swift without any dependencies

Related tags

Image SwiftMicroPNG
Overview

MicroPNG

Swift

This package currently offers a very minimal PNG encoder for uncompressed RGB and RGBA PNG files.

It does not rely on any frameworks and should work on all Swift supported platforms.

Some of the work is based on this implementation: https://github.com/jamesbowman/pngout/blob/master/pngout.c

Example usage

let width = UInt32(512)
let height = UInt32(512)

var imageData: [UInt32] = .init(repeating: 0, count: Int(width * height))

var index = 0
for y: UInt32 in 0 ..< height {
    for x: UInt32 in 0 ..< width {
        let r: UInt32 = y & 0xFF
        let g: UInt32 = x & 0xFF
        let b: UInt32 = (0xFF - x & 0xFF)

        imageData[index] = (r << 16) + (g << 8) + (b << 0)

        index += 1
    }
}

let encoder = MicroPNG()

let pngData = try! encoder.encodeRGBUncompressed(data: imageData,
                                                 width: width,
                                                 height: height)

pngData.withUnsafeBytes { pointer in
    let data = Data(bytes: pointer.baseAddress!, count: pointer.count)

    try! data.write(to: URL(fileURLWithPath: "EXPORT PATH"))
}
You might also like...
Create an '.icns' file from any image

createicns Create an '.icns' file from any image. Usage This command line tool makes it incredibly simple to create an '.icns' icon file from an image

Patch out the GPU checks for any x86-64 macOS Unreal Engine-based game
Patch out the GPU checks for any x86-64 macOS Unreal Engine-based game

UnrealGPUPatcher Download here Patch out the GPU checks for any x86-64 macOS Unreal Engine-based game, particularly ARK: Survival Evolved. Requirement

A beautiful and flexible text field control implementation of
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

An implementation of High Pass Skin Smoothing using Apple's Core Image Framework
An implementation of High Pass Skin Smoothing using Apple's Core Image Framework

YUCIHighPassSkinSmoothing An implementation of High Pass Skin Smoothing using CoreImage.framework Available on both OS X and iOS. Ports A MetalPetal b

PublisherKit - An open source implementation of Apple's Combine framework for processing asynchronous events over time

Publisher Kit Overview PublisherKit provides a declarative Swift API for processing asynchronous events over time. It is an open source version of App

BeatboxiOS - A sample implementation for merging multiple video files and/or image files using AVFoundation

MergeVideos This is a sample implementation for merging multiple video files and

A Metal re-implementation of GLKit's GLKBaseEffect
A Metal re-implementation of GLKit's GLKBaseEffect

MBEBaseEffect: Antique Fixed-Function Features for Modern Apps When GLKit was introduced with iOS 5 (2011), it included the GLKBaseEffect class to all

API surface for Swift plug-ins using the Swift Plugin Manager

SwiftPlugin The minimal API surface required for the Swift Plugin Manager to create instances from a loaded plugin. Additional documentation and refer

Contentful.swift : Swift Delivery SDK for Contentful
Contentful.swift : Swift Delivery SDK for Contentful

contentful.swift - Swift Delivery SDK for Contentful Swift SDK for the Contentfu

Owner
Robert Bruinier
Robert Bruinier
A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.

ImageScout ImageScout is a Swift implementation of fastimage. It allows you to find the size and type of a remote image by downloading as little as po

Reda Lemeden 967 Dec 30, 2022
IconsMaker - Create your app icon with SwiftUI and generate PNG images in all needed sizes

IconsMaker - Create your app icon with SwiftUI and generate PNG images in all needed sizes

Jonathan Gander 14 Oct 20, 2022
ImageView - Component for loading and displaying different images aka SVG/PNG/JPG/JPEG

ImageView Component that loads and displays images(.svg/.png/.jpg/.jpeg) form as

Sergei 1 Mar 23, 2022
Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Arnold Rozon 2 May 9, 2022
ZImageCropper is a simplest way to crop image to any shapes you like.

ZImageCropper ZImageCropper is a simplest way to crop image to any shapes you like. Example To run the example project, clone the repo, and run pod in

Mohammad Zaid Pathan 219 Dec 17, 2022
PrettyBorder is a SwiftUI package for managing an customized border and background at any kind of view.

PrettyBorder Description PrettyBorder is a SwiftUI package for managing an customized border and background at any kind of view. Preview of end result

Ahmet Giray Uçar 2 Oct 13, 2021
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022
A free, multiplatform SDK for real-time facial motion capture using blendshapes, and rigid head pose in 3D space from any RGB camera, photo, or video.

mocap4face by Facemoji mocap4face by Facemoji is a free, multiplatform SDK for real-time facial motion capture based on Facial Action Coding System or

Facemoji 592 Jan 1, 2023
iOS Framework that makes it easy to preview images on any UIImageView.

AZImagePreview iOS Framework that makes it easy to preview images on any UIImageView. Screenshots Installation: Cocoa Pods: pod 'AZImagePreview' Swift

Antonio Zaitoun 25 Dec 11, 2022
Pipable is an iOS library to implement Picture in Picture for any UIView.

Pipable Pipable is an iOS library to implement Picture in Picture for any UIView. This is done just by conforming to a protocol. The "Audio, AirPlay a

Emma Cold 11 Nov 3, 2022