SwiftDithering

1.3.0

Swift package focused on Dithering Images
lugalu/SwiftDithering

What's New

1.3.0

2023-08-31T22:57:50Z

New release! This is a somewhat big update, but it shouldn't affect any existing implementations. I am just adding more things on top of the code:
Features:

  • Clustered Dots
  • Central White point
  • Balanced Center Point
  • Diagonal Clustered

Bug Fixes:

  • fixed a thresholding problem regarding ordered dithering, where because of the deviation being UInt8 it was always 0 no matter the spread value applied. This fix not only fixes colors in colored mode but also adds more details to grayscale levels

The previous apply Ordered Dither(withSize: BayerSizes) still exists, but as a quick and cleaner way to call Bayer matrices, the implementation is just calling the new applyOrderedDither(withType: OrderedDitherTypes) with the same arguments to ensure your code will continue to work.

SwiftDithering

This is a library focused on bringing dithering to Swift since the CIFilter for dither is mostly noise. The implementation is done via the Accelerate framework.

Examples


  • Floyd-Steinberg:

    • 1-bit:

    • 2-bits:

Usage

To use the library you will have some access points based on UIImages

import SwiftDithering

function yourFunction() {
//Highly Recommended
    Task{
        do{
        let ditheredImage = try image?.applyErrorDifusion(withType: .floydSteinberg)
        //or
        //try image?.applyOrderedDither(withSize: .bayer8x8)
        //or
        //try image?.applyThreshold(withType: .fixed)

        }catch{
          //handle errors here
        }
    }
  
}

the functions also have more accessible parameters, but for simplicity this example does not, for more details check the Sample/DitherTester/DitherControl and go to any of the retrivedDitheredImages

Plans And Features

Since is my first time doing something like this a lot of the code is prone to change, I will try to do it in the most non-disruptive way but I cannot guarantee it will work in every single version.

Currently Features:

  • Bayer matrix;
  • Floyd Steinberg Error Diffusion;
  • Stucky Error Difusion.
  • Fixed Threshold
  • Random Threshold
  • Uniform Threshold

Planned Dithers:

  • Clustered Dots
  • Central White point
  • Balanced Centered point

Maybe Will be added:

  • Diagonal clustered

Others:

  • Documentation and examples outside what the code already provides
  • Tags, tests, and releases automation in Github
  • Cocoa pods integration
  • Small test project with some images Pre-loaded and the ability to add your own from the gallery.
  • Downgrade Minimum version since there's nothing that should be bound to older devices

Considerations

  • Since all runs on the CPU they are calculated as sequential and are expensive so tasks and loadings are needed for the user UI.
  • Feel free to suggest performance improvements and report any bug that you may find while using this lib
  • These dithers are based on the matlab article stored in the archive.today and other researches

Description

  • Swift Tools 5.7.1
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Oct 17 2024 20:51:31 GMT-0900 (Hawaii-Aleutian Daylight Time)