Skip to content

juliand665/Bitmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



Swift Package Manager compatible MIT licensed

Bitmap

Easy low-overhead access to individual pixels.

Bitmap uses low-level data pointers to reduce overhead in working with CGImage.

It allows you to get and set pixels directly through a 2-argument subscript, as well as offering various bulk creation/modification operations.

Example

Identify pixels that are neither fully opaque nor fully transparent and turn them red, clearing the rest.

for y in 0..<bitmap.height {
	for x in 0..<bitmap.width {
		if case 1...254 = bitmap[x, y].alpha {
			bitmap[x, y] = .red
		} else {
			bitmap[x, y] = .clear
		}
	}
}
turns this into this

For more examples, please take a look at the unit tests. All non-trivial public endpoints have documentation attached too, so it shouldn't be too hard to figure out how everything works if you just play around a little.