Codetown ::: a software developer's community
Welcome to Kotlin Thursdays! Last week, we were able to render an image with TornadoFX and even manipulate its pixels. Today, we will go over Pixel Math!
Think of these resources as supplemental if you happen to be more curious. We always encourage looking into documentation for things you use!
Last week, we got the hang of how to grab these pixels and do something with them. Today, we're going to expand by creating our own filters using operational pixel manipulation.
For all practical purposes, we're going to be talking about monochromatic images. If we try to write filters using colored pixels, it will prove a lot more difficult to work with RGB values as opposed to just black or white.
Best we learn to walk before we start trying to fly!
In order to create our own image filters, we need to have a solid understanding of pixel math, or binary operations.
Binary operations are the bread and butter of computers! You can compute operations on binary values 1 and 0.
AND - both inputs must be true for the output to be true
0 && 0 = 0
0 && 1 = 0
1 && 0 = 0
1 && 1 = 1
OR - one or both inputs must be true for the output to be true
0 || 0 = 0
0 || 1 = 1
1 || 0 = 1
1 || 1 = 1
NOT - inverse result
!0 = 1
!1 = 0
!(0 && 0) = 1
!(1 || 1) = 0
Likewise, if we assign the color BLACK to 1 and the color WHITE to 0, we can easily apply binary operations to to the binary values black and white. Working with colors gets significantly more difficult when there are RGB values to consider. There are other binary operations like XANDS, XORS, and XNORS, but for now, let's just focus on the first three.
Now that we understand how OR, AND, and NOT works, let's implement these functions with colors.
fun or (a: Color, b: Color) {
return if (a == Color.BLACK || b == Color.BLACK) {
Color.BLACK
}
else { Color.WHITE
}
fun and (a: Color, b: Color) {
return if (a == Color.BLACK && b == Color.BLACK) {
Color.BLACK
} else {
Color.WHITE
}
}
fun not (color: Color) {
return if (color == Color.BLACK) Color.WHITE else Color.BLACK
}
You'll notice that these functions are for pixel colors only. Next week, we look into higher-order functions in Kotlin to learn how we can pass functions as a parameter - but you'll welcome to check out the video to see how we can apply one of these primitive filters to our images! See you next week :)
Tags:
Codetown is a social network. It's got blogs, forums, groups, personal pages and more! You might think of Codetown as a funky camper van with lots of compartments for your stuff and a great multimedia system, too! Best of all, Codetown has room for all of your friends.
Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.
Check out the Codetown Jobs group.

AWS has extended Lambda SnapStart to container image functions, which hold up to 10 GB against 250 MB for zip archives. Teams previously chose between dependency headroom and sub-second startup. A Reddit thread from a month earlier shows what that cost: stripping whitespace and docstrings from installed packages to stay under the limit.
By Steef-Jan Wiggers
Rustls, a Rust TLS library, marks its decade-long progression from a grassroots project to a funded open-source initiative. Key contributions from organisations boosted development, resulting in features like post-quantum cryptography and robust performance. The upcoming 0.24 release aims to enhance architecture and flexibility, including new input buffering and improved session handling
By Olimpiu Pop
NVIDIA Personal AI Router (PAIR), now available in beta, lets you combine the inference capacity of multiple computers on your local network and automatically distribute AI requests among them. It is primarily designed for local multi-agent AI workloads, where multiple independent model calls can otherwise overwhelm one GPU.
By Sergio De Simone
Netflix has reworked its Conductor workflow orchestration engine to handle larger workloads, increasing supported workflow size from about 2,500 to 30,000 tasks and reducing p99 workflow evaluation latency by about 40%. Conductor 4.0 separates workflow metadata from task data, moves evaluation to asynchronous processing, and introduces dynamic worker allocation and concurrency controls.
By Leela Kumili
tsgolint has released a stable v7, enhancing TypeScript linting with native Go speed. It offers type-aware linting, leveraging TypeScript's semantic analysis through the typescript-go compiler. Oxlint manages configurations and file discovery. The release, compatible with TypeScript 7.0.2, handles 59 of 61 type-aware rules and shows significant performance improvements over ESLint.
By Daniel Curtis
© 2026 Created by Michael Levin.
Powered by