https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compose-desktop
  • b

    Bagadeshkumar R

    08/23/2022, 6:31 AM
    Hey!, I'm trying to launch commandline from compose desktop to run a python script. I searched but couldn't find a way to do it. Have any idea about that?
    b
    • 2
    • 1
  • e

    eygraber

    08/23/2022, 11:55 AM
    Is this the best place to find the latest JetBrains compiler version?
    j
    • 2
    • 1
  • j

    jw

    08/23/2022, 2:08 PM
    Are the JetBrains compiler and runtime now versioned independently? I see dev764 of the runtime (also on the GitHub releases) but only 755 of the compiler.
    e
    i
    d
    • 4
    • 10
  • e

    enighma

    08/23/2022, 7:59 PM
    Sometimes I get
    Font transform has NaN position
    when I try to start the app. I can't understand what is causing it, or why it goes away after a while. I see there's an issue for it: https://github.com/JetBrains/compose-jb/issues/2098 Does anyone know what causes it? and if there's a workaround?
  • e

    eygraber

    08/24/2022, 1:03 AM
    I updated to use dev764 this morning, and then renovate (dependency updater bot) found dev765, dev768, and finally dev770 but gradle isn't able to resolve any of those versions, and I don't see releases for them in GitHub. Was there some kind of publishing bug?
    j
    k
    h
    • 4
    • 14
  • o

    oianmol

    08/25/2022, 4:14 PM
    Is there a compositionLocal for ComposeWindow for Desktop ? 🤔 I don’t see anything like LocalConfiguration on jvm 😞
  • s

    spierce7

    08/26/2022, 1:55 PM
    has anyone gotten fastlane working for code signing with MacOS builds yet?
  • s

    spierce7

    08/29/2022, 4:39 AM
    I’m curious does anyone understand how the running of the Mac application with Compose for Desktop works? In the .app folder that’s generated for a mac application, there is a
    Contents/MacOS/<app name>
    file that is a unix binary. Somehow this unix binary is starting up the JVM, and running the JVM inside the same process as the unix binary (at least that’s what it looks like is happening externally). How is this possible? I’m asking because I’m wondering if I could replace the unix binary with a Kotlin Native application that checks for and watches for app updates, and then can restart my application to force an update if necessary.
    r
    e
    m
    • 4
    • 5
  • r

    Radoslaw Juszczyk

    08/29/2022, 7:34 AM
    Hey guys, how do I make a Window modal (with a Window below being not clickable/focusable)? With JavaFX it would be something like that:
    newWindow.initModality(Modality.WINDOW_MODAL)
    newWindow.initOwner(parentStage)
    • 1
    • 1
  • l

    Long Tran

    08/29/2022, 10:06 AM
    Hey guys, I’m using the new animatedImage Composable to play GIFs, but it plays GIFs infinitely as a default behavior. Is there any way to play the GIFs just once?
    loadOrNull { loadResourceAnimatedImage(path) }?.animate() ?: ImageBitmap.Blank
    @Composable
    actual fun AnimatedImage.animate(): ImageBitmap {
        when (codec.frameCount) {
            0 -> return ImageBitmap.Blank // No frames at all
            1 -> {
                // Just one frame, no animation
                val bitmap = remember(codec) { Bitmap().apply { allocPixels(codec.imageInfo) } }
                remember(bitmap) {
                    codec.readPixels(bitmap, 0)
                }
                return bitmap.asComposeImageBitmap()
            }
            else -> {
                val transition = rememberInfiniteTransition()
                val frameIndex by transition.animateValue(
                    initialValue = 0,
                    targetValue = codec.frameCount - 1,
                    Int.VectorConverter,
                    animationSpec = infiniteRepeatable(
                        animation = keyframes {
                            durationMillis = 0
                            for ((index, frame) in codec.framesInfo.withIndex()) {
                                index at durationMillis
                                val frameDuration = calcFrameDuration(frame)
    
                                durationMillis += frameDuration
                            }
                        }
                    )
                )
    
                val bitmap = remember(codec) { Bitmap().apply { allocPixels(codec.imageInfo) } }
    
                remember(bitmap, frameIndex) {
                    codec.readPixels(bitmap, frameIndex)
                }
    
                return bitmap.asComposeImageBitmap()
            }
        }
    }
  • l

    Lucas

    08/29/2022, 5:30 PM
    Is there any default solution in compose for not launching the app twice?
    l
    d
    t
    • 4
    • 6
  • t

    Thomas

    08/30/2022, 7:45 PM
    I noticed that compose-jb was rebased on compose 1.2.1. That is great because now I can use 1.2.1 for Android. However I was not able to figure out which material3 version should be used. Using the wrong version will cause nosuchmethod errors. Does anyone know what material3 version compose-jb is based on? Can be either an official Androidx build or a snapshot, both are fine to me.
    i
    • 2
    • 5
  • z

    zt

    08/30/2022, 8:33 PM
    How can I make a
    SwingPanel
    use a transparent background? I tried passing
    Color.Transparent
    to the background parameter but that didn't work
    k
    • 2
    • 1
  • r

    Radoslaw Juszczyk

    08/30/2022, 9:51 PM
    Hey, Any idea why when I use:
    rememberWindowState(size = DpSize(250.dp, 200.dp))
    the window is not actually 250dp wide? I mean state says it is, but it doesnt fit 250dp of content (five 50dp-wide boxes should be fully visible):
    i
    • 2
    • 6
  • y

    Yevhen Tienkaiev

    08/30/2022, 9:52 PM
    Hello, is there any possibility to show directory selection dialog using JetBrains Compose?
    d
    • 2
    • 4
  • a

    Adam Brown

    08/30/2022, 10:55 PM
    This is really strange, I have a
    composeUi
    module, and
    commonMain
    includes the multiplatform compose artifacts. And I'm able to write desktop specific compose code inside my
    desktopMain
    JVM source set, but then when I try to write some Android specific compose in the
    androidMain
    source set, it doesn't know about the compose dependencies at all. Has anyone else run into this?
    a
    m
    +2
    • 5
    • 18
  • z

    zt

    08/31/2022, 1:49 AM
    I have this code in my build.gradle.kts and it shows a warning to add the opt in option to the compiler options but it's not working
    @OptIn(ExperimentalComposeLibrary::class)
    implementation(compose.material3)
    tasks.withType<KotlinCompile>().configureEach {
        kotlinOptions {
            freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
        }
    }
    j
    g
    • 3
    • 5
  • j

    Jerry Yion

    08/31/2022, 2:11 AM
    Hi all, are there some relationship exists between compose version and idea version? My idea plugin cannot run on 2020.2 since I upgrade compose from 1.0.0 to 1.1.1
    java.lang.ClassCastException: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function2
    e
    • 2
    • 4
  • d

    deviant

    08/31/2022, 8:23 AM
    is it possible to make google's live edit feature working in multiplatform project? at least on android?
  • s

    spierce7

    08/31/2022, 8:23 PM
    Where should I save files in MacOS if I want them to be available after an upgrade?
    c
    e
    • 3
    • 9
  • e

    enighma

    08/31/2022, 11:34 PM
    What is the status of Material3 on CD? as in have anyone tried it. I know there's 1.2 preview builds available, which ought to work with M3 (theoretically at least).
    t
    c
    z
    • 4
    • 5
  • r

    Radoslaw Juszczyk

    09/01/2022, 11:17 AM
    hey guys, I want to use jetpack compose to create an image file. I have an interface like that:
    interface AssetsFactory {
        fun createTextImage(text:String, padding: Int, backgroundColor: Color): File
    }
    With JavaFX I would simply create a layout and use
    SwingFXUtils.fromFXImage
    I want something like:
    fun createImageFile(size: IntSize, content: @Composable ()-> Unit): BufferedImage
    Any ideas/suggestions?
    k
    • 2
    • 2
  • d

    David W

    09/01/2022, 10:55 PM
    Compose Tooltips are stationary and you can't click through them, resulting in them blocking buttons and other UI elements. Any ideas on how to elegantly avoid this? The ideal would be the tooltip following the mouse cursor, a set distance away (like many video games do), but I cannot figure out how to do that. Another option would be dismissing the tooltip or having it recompose when the cursor enters the tooltip, but I'm struggling with that, too. All of my tooltips use a common background component:
    @Composable
    fun SmolTooltipBackground(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
        Box(
            modifier = modifier
                .pointerMoveFilter(
                    onEnter = {
                        println("On Mouse(pointer) Enter")
                        // can i cancel/hide this composable from here?
                        false
                    })
        ) {
            content.invoke()
        }
    }
    g
    d
    • 3
    • 14
  • o

    oianmol

    09/03/2022, 4:16 PM
    Hi Folks! I brought my Slack jetpack compose clone to Compose Multiplatform with Android and Desktop UI, still a wip but learning a lot here, thought of sharing here. https://github.com/Anmol92verma/SlackComposeMultiplatform
    j
    • 2
    • 5
  • j

    John Aoussou

    09/04/2022, 12:08 PM
    I'm really struggling to set up SQL Delight in a Compose Desktop project. This the reference I'm using but I can't quite follow: https://cashapp.github.io/sqldelight/jvm_sqlite/ , does anyone have another template? Please look in the thread to see what I have attempted.
    h
    j
    o
    • 4
    • 21
  • d

    darkmoon_uk

    09/04/2022, 1:14 PM
    Exploring using Shaders with Compose Multiplatform :compose-multiplatform:: It's delightfully straightforward to share SKSL shader code between iOS and Desktop, since both platforms expose Skiko API's. 🎉 Is it possible to use SKSL shader on Android platform in a similar way? I tried naively importing Skiko explicitly but this didn't help -
    RuntimeEffect
    doesn't resolve.
    k
    j
    • 3
    • 4
  • s

    spierce7

    09/06/2022, 9:19 PM
    Has anyone embedded CEF or any other browser into their Compose Desktop application I wonder?
    o
    j
    +3
    • 6
    • 14
  • s

    Stefan Oltmann

    09/07/2022, 9:53 AM
    I use
    ImageComposeScene
    with this code to take screenshots of my Composables which works fine for most things. But now I got a Composable which shows an
    Image
    Composable after a
    produceState()
    loaded the
    BitmapPainter
    . As long as the bitmapPainter has the initialValue of null is just displays an empty
    Box
    as placeholder. My question now is how I can let
    ImageComposeScene
    wait until the
    produceState()
    executed and re-composed until taking the screenshot. Now the screenshot is taken immediately after the first composition which leaves me with an empty
    Box
    .
    val bitmapPainter = produceState<BitmapPainter?>(initialValue = null, thumbnailFileName) {
    
        value = withContext(Dispatchers.Default) {
    
            val image = imageLoader.loadThumbnailImage(thumbnailFileName)
                ?: return@withContext null
    
            return@withContext BitmapPainter(image = image)
        }
    }
    @OptIn(ExperimentalComposeUiApi::class)
    fun takeScreenshot(content: @Composable () -> Unit): ByteArray {
    
        ImageComposeScene(
            width = 1024,
            height = 768,
            density = Density(1f),
            content = content
        ).use {
    
            return@takeScreenshot it.render().encodeToData(EncodedImageFormat.PNG)!!.bytes
        }
    }
    k
    • 2
    • 6
  • s

    Stefan Oltmann

    09/09/2022, 9:51 AM
    Despite setting a density for
    ImageComposeScene
    on different devices I get different screenshots. Difference is in scale of the Composables. I suspect that the devices DPI plays a role here and try to find out if I can set that to a fixed value for rendering.
  • s

    Stefan Oltmann

    09/09/2022, 12:38 PM
    Maybe it's just platform specific. If I run the tests on macos-latest the font don't differ, but the icons still do for some reason. I guess what I'm looking for is something like the stuff that's needed for Android Emulators (for example
    swiftshader_indirect
    ).
    i
    s
    • 3
    • 15
Powered by Linen
Title
s

Stefan Oltmann

09/09/2022, 12:38 PM
Maybe it's just platform specific. If I run the tests on macos-latest the font don't differ, but the icons still do for some reason. I guess what I'm looking for is something like the stuff that's needed for Android Emulators (for example
swiftshader_indirect
).
i

Igor Demin

09/09/2022, 1:19 PM
Differences in rendering on different platforms is a huge pain now when we try to test Compose. I know multiple techniques, that we can apply now and one solution that we can develop in the future. The techniques are: • Prepare screenshots for each platform separately. On Windows/macOs screenshots are usually stable. Can’t tell what is the status on Linux platforms. • Maybe we can create some Docker container, which we will use everywhere, even for local tests. • Try to make screenshots without text. Maybe you can add some Boolean that enables/disables all text. • Don’t compare screenshots pixel-by-pixel. Instead compare screenshots by some similarity index (example). These are huge trade-offs, but that is the current state unfortunately. In the future we can provide out of the box solution with rendering via Freetype for text (it will help to draw text the same on all platforms), disabled antialiasing (which can behave differently too), fixed settings, etc. But we haven’t investigated this path yet, and it is hard to implement it on the user side. Maybe you can build a custom build of Skia/Skiko with Freetype and override it for tests, but that is only a guess that it is possible.
s

Stefan Oltmann

09/09/2022, 1:21 PM
Thank you for this exhaustive answer! 🙏 In addition to your points I try to set "SKIKO_RENDER_API" to "SOFTWARE_COMPAT" as I hope this may eliminate nuances between METAL and OPENGL for instance.
i

Igor Demin

09/09/2022, 1:22 PM
SKIKO_RENDER_API doesn’t affect
ImageComposeScene
, that is always rendered with software renderer.
s

Stefan Oltmann

09/09/2022, 1:22 PM
Oh, okay. Thank you. Then that's not the source of the differences.
Execute the tests in Docker also sounds reasonable. I need to look for an example how to do it.
It's not only text. This seems to be stable if I choose a macOS 12 based CI runner and compare it with my local dev machine running macOS 12. But for some reason SVG based icons also differ a bit. I load them this way:
private val imageVectorCache = mutableMapOf<VectorRes, ImageVector>()

@Composable
actual fun painter(res: VectorRes): Painter {

    val imageVector = imageVectorCache.getOrPut(res) {

        val inputSource = object : InputSource() {
            override fun getByteStream() = openResource(res.path)
        }

        loadXmlImageVector(inputSource, LocalDensity.current)
    }

    return rememberVectorPainter(imageVector)
}

private fun openResource(resourcePath: String): InputStream {

    val classLoader = Thread.currentThread().contextClassLoader!!

    return requireNotNull(classLoader.getResourceAsStream(resourcePath)) {
        "Resource $resourcePath not found"
    }
}
i

Igor Demin

09/09/2022, 3:03 PM
I am not sure, but it can be related to the fact that different macOS versions/installations have different color profiles in
System preferences -> Display
Also, Skia can use some platform API’s for rasterisation. For example, for antialiasing. But I am not sure about it too. Also, different platforms/versions can do math differently, and we can have some round error for colors (+-1)
s

Stefan Oltmann

09/09/2022, 3:40 PM
Thank you for the hint.
s

saket

09/11/2022, 7:24 AM
IIRC text rendering will also depend on the jdk. Are you using the same distribution on both ci and your machine?
s

Stefan Oltmann

09/12/2022, 8:06 AM
I got behind what makes the difference. I use Eclipse Adoptium 17.0.4+8 on both machines, but the macOS GitHub runner is an Intel machine and therefore has the x64 version installed. My dev machine is a MacBook M1 and therefore has the aarch64 installed. After locally installing the x64 JVM on my dev machine the screenshots fail in the same manner: Subtle differences in the antialiasing of vector images.
I guess my plan is now to use the macOS GitHub runner until we get a platform-independent rendering with Freetype to avoid the relatively huge differences in font rendering. And this subtle color changes between x64 and aarch64 can be compensated by changing my pixel-by-pixel comparison to allow a difference of 10 in the color of a pixel.
It's just what Igor said:
Also, different platforms/versions can do math differently, and we can have some round error for colors (+-1)
Thank you both a lot for figuring this out 🙏
In the end I gave it up doing this on GitHub. I wrote a comparison logic that allows colors to be rounded a bit. That crashes the VM by trying to call
skia.Bitmap.getColor()
on CI. I take that as the final sign that I'm just not supposed to compare screenshots on CI. 🙈
# A fatal error has been detected by the Java Runtime Environment: 

# 
# SIGSEGV (0xb) at pc=0x000000012f6949dd, pid=23658, tid=6147 
# 

# JRE version: OpenJDK Runtime Environment Temurin-17.0.4+8 (17.0.4+8) (build 17.0.4+8) 

# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (17.0.4+8, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-amd64) 

# Problematic frame: 
# C [libskiko-macos-x64.dylib+0xf69dd] _ZNK8SkPixmap8getColorEii+0x2cd 

Compiled method (n/a) 19811 2768 n 0 org.jetbrains.skia.BitmapKt::Bitmap_nGetColor (native)
I share my code with you, so I didn't write it for nothing. Hopefully someone has a use for this.
val expectedBitmap = Bitmap.makeFromImage(Image.makeFromEncoded(expectedImageBytes))
val actualBitmap = Bitmap.makeFromImage(Image.makeFromEncoded(actualImageBytes))

if (!expectedBitmap.isEquals(actualBitmap, tolerance = 3)) {

    fail("Image $fileName is not equal to reference image.")
}
private fun Bitmap.isEquals(other: Bitmap, tolerance: Int = 0): Boolean {

    if (this.width != other.width || this.height != other.height)
        return false

    for (x in 0..width) {
        for (y in 0..height) {

            val thisColor = this.getColor(x, y)
            val otherColor = other.getColor(x, y)

            if (thisColor != otherColor) {

                val redDelta = abs(getRed(thisColor) - getRed(otherColor))
                val greenDelta = abs(getGreen(thisColor) - getGreen(otherColor))
                val blueDelta = abs(getBlue(thisColor) - getBlue(otherColor))

                if (redDelta > tolerance || greenDelta > tolerance || blueDelta > tolerance)
                    return false
            }
        }
    }

    return true
}

private fun getRed(pixelValue: Int) =
    pixelValue and (255 shl 16) shr 16

private fun getGreen(pixelValue: Int) =
    pixelValue and (255 shl 8) shr 8

private fun getBlue(pixelValue: Int) =
    pixelValue and 255
View count: 9