{"id":17275260,"url":"https://github.com/jflinter/paintbucket","last_synced_at":"2025-09-06T03:46:18.184Z","repository":{"id":56921352,"uuid":"53830218","full_name":"jflinter/PaintBucket","owner":"jflinter","description":"A fast scanline flood fill implementation, written in Swift.","archived":false,"fork":false,"pushed_at":"2019-10-03T13:45:25.000Z","size":9224,"stargazers_count":69,"open_issues_count":3,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-30T04:48:26.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jflinter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-14T05:48:24.000Z","updated_at":"2025-07-22T01:18:59.000Z","dependencies_parsed_at":"2022-08-21T04:50:43.005Z","dependency_job_id":null,"html_url":"https://github.com/jflinter/PaintBucket","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jflinter/PaintBucket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jflinter%2FPaintBucket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jflinter%2FPaintBucket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jflinter%2FPaintBucket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jflinter%2FPaintBucket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jflinter","download_url":"https://codeload.github.com/jflinter/PaintBucket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jflinter%2FPaintBucket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273854602,"owners_count":25180011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T08:55:47.347Z","updated_at":"2025-09-06T03:46:18.159Z","avatar_url":"https://github.com/jflinter.png","language":"Swift","readme":"# PaintBucket\n\n[![Travis branch](https://img.shields.io/travis/jflinter/PaintBucket/master.svg)]()\n\nPaintBucket is pretty literally what its title suggests. It is an implementation of [Scanline Flood Fill](https://en.wikipedia.org/wiki/Flood_fill#Scanline_fill) in Swift, more commonly known as the algorithm that the paint bucket tool in MS Paint uses under the hood (well, it uses something like it, anyway).\n\nThis might, for example, be useful if you have a bunch of product photos shot against a uniformly-colored background and you want to remove said background. Or not, who knows.\n\n## Usage\nThis library exposes a single new category method on `UIImage`:\n\n```swift\nlet image = UIImage(named: \"something\")!\nlet imageWithoutBackground = image.pbk_imageByReplacingColorAt((0, 0), withColor: UIColor.clearColor(), tolerance: 10)\n```\n\nIts parameters should be self-explanatory.\n\n## Performance\nThis is decently fast! That is to say, I was able to speed it up ~100x from my initial implementation (which admittedly was pretty slow). That said, it's not, like, instantaneous. You should probably do this on a background thread unless your images are *tiny*. (For reference, the 2000x1566 benchmark PNG takes like 3 seconds to process in the simulator on a MacBook pro).\n\nThanks to the always-amazing [Mike Ash](https://mikeash.com/pyblog/friday-qa-2012-09-14-implementing-a-flood-fill.html) for the idea to use an `NSIndexSet` for temporary storage, and thanks to [this random website I found](http://lodev.org/cgtutor/floodfill.html#Recursive_Scanline_Floodfill_Algorithm) for some implementation ideas for the scanline optimization. That said, this can almost certainly be faster, and I'd welcome a PR that made it so. There's a benchmark in the test suite you can run to see if your code helps.\n\n## Contributing\nPRs welcome - I'd ask that you open an issue before blindly sending PRs my way just to make sure we agree that your idea is a Good Thing. To get you started, if someone wants to add some kind of clever anti-aliasing to this, I'd sure love that.\n\n## Installation\n[Carthage](https://github.com/Carthage/Carthage): add `github \"jflinter/PaintBucket\", ~\u003e 0.1` to your Cartfile.\n\n[CocoaPods](cocoapods.com): add `pod 'PaintBucket', '~\u003e 0.1'` to your Podfile.\n\n![](http://i.giphy.com/scEmJ6yaTmhrO.gif)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjflinter%2Fpaintbucket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjflinter%2Fpaintbucket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjflinter%2Fpaintbucket/lists"}