Skip to content

Commit c739a7a

Browse files
committed
Merge branch 'main' into feature/group_dependencies
# Conflicts: # gradle/libs.versions.toml
2 parents b29b15c + 2441faa commit c739a7a

22 files changed

+1190
-33
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ jobs:
6565
- name: Generate Test Coverage Xml Report
6666
run: ./gradlew koverXmlReport
6767

68-
- name: Upload test coverage to qlty
69-
uses: qltysh/qlty-action/coverage@v2
70-
with:
71-
oidc: true
72-
files: build/reports/jacoco/test/jacocoTestReport.xml
73-
add-prefix: src/main/kotlin
74-
7568
- name: Run codacy-coverage-reporter
7669
uses: codacy/codacy-coverage-reporter-action@v1
7770
with:

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
<p align="center">
44
<a href="https://github.com/ashtanko/kotlab/actions/workflows/build.yml"><img alt="Build" src="https://github.com/ashtanko/kotlab/actions/workflows/build.yml/badge.svg?branch=main"/></a>
55
<a href="https://codecov.io/gh/ashtanko/kotlab"><img alt="Codecov" src="https://codecov.io/gh/ashtanko/kotlab/branch/main/graph/badge.svg?token=JEU9EIJMHA"/></a>
6-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Test Coverage" src="https://qlty.sh/gh/ashtanko/projects/kotlab/coverage.svg"/></a>
76
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage"><img alt="Codacy Coverage Badge" src="https://app.codacy.com/project/badge/Coverage/74cad08184b34038bb5c64c317384367"/></a>
87
<a href="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab"><img alt="CodeFactor" src="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab/badge"/></a>
9-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Maintainability" src="https://qlty.sh/gh/ashtanko/projects/kotlab/maintainability.svg"/></a>
108
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img alt="Codacy Grade Badge" src="https://app.codacy.com/project/badge/Grade/74cad08184b34038bb5c64c317384367"/></a>
119
<a href="https://codebeat.co/projects/github-com-ashtanko-kotlab-main"><img alt="Codebeat Badge" src="https://codebeat.co/badges/b5a26fee-b6d2-46f2-b121-c3d98cb13c9f"/></a>
1210
<a href="https://hitsofcode.com/github/ashtanko/kotlab/view?branch=main"><img alt="Hits-of-Code" src="https://hitsofcode.com/github/ashtanko/kotlab?branch=main"/></a>
@@ -22,23 +20,23 @@
2220

2321
### Metrics
2422
```text
25-
15199 number of properties
26-
10523 number of functions
27-
8940 number of classes
28-
239 number of packages
29-
3531 number of kt files
23+
15288 number of properties
24+
10573 number of functions
25+
8954 number of classes
26+
240 number of packages
27+
3543 number of kt files
3028
```
3129

3230

3331
### Complexity Report
3432
```text
35-
266642 lines of code (loc)
36-
165721 source lines of code (sloc)
37-
121060 logical lines of code (lloc)
38-
72547 comment lines of code (cloc)
39-
25022 cyclomatic complexity (mcc)
40-
20410 cognitive complexity
33+
267458 lines of code (loc)
34+
166374 source lines of code (sloc)
35+
121548 logical lines of code (lloc)
36+
72562 comment lines of code (cloc)
37+
25100 cyclomatic complexity (mcc)
38+
20431 cognitive complexity
4139
0 number of total code smells
4240
43 comment source ratio
4341
206 mcc per 1,000 lloc
44-
```
42+
```

api/Kotlin-Lab.api

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19686,6 +19686,17 @@ public final class dev/shtanko/concurrency/coroutines/actors/ExampleKt {
1968619686
public static synthetic fun main ([Ljava/lang/String;)V
1968719687
}
1968819688

19689+
public final class dev/shtanko/concurrency/coroutines/examples/AdvancedImageProcessingKt {
19690+
public static final fun applyRegionSpecificFilter (Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
19691+
public static final fun blendSegment (Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
19692+
public static final fun detectEdges (Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
19693+
public static final fun main ()V
19694+
public static synthetic fun main ([Ljava/lang/String;)V
19695+
public static final fun mergeSegments (Ljava/util/List;II)Ljava/awt/image/BufferedImage;
19696+
public static final fun processImageParallel (Ljava/awt/image/BufferedImage;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
19697+
public static final fun segmentImage (Ljava/awt/image/BufferedImage;I)Ljava/util/List;
19698+
}
19699+
1968919700
public final class dev/shtanko/concurrency/coroutines/examples/AtomicBankTransfer : dev/shtanko/concurrency/coroutines/examples/IAtomicBankTransfer {
1969019701
public static final field Companion Ldev/shtanko/concurrency/coroutines/examples/AtomicBankTransfer$Companion;
1969119702
public fun <init> ()V
@@ -19733,6 +19744,8 @@ public abstract interface class dev/shtanko/concurrency/coroutines/examples/IAto
1973319744
}
1973419745

1973519746
public final class dev/shtanko/concurrency/coroutines/examples/ImageProcessingKt {
19747+
public static final field MAX_COLOR I
19748+
public static final field MAX_COLOR_VALUE I
1973619749
public static final fun adjustBrightness (Ljava/awt/image/BufferedImage;I)Ljava/awt/image/BufferedImage;
1973719750
public static synthetic fun adjustBrightness$default (Ljava/awt/image/BufferedImage;IILjava/lang/Object;)Ljava/awt/image/BufferedImage;
1973819751
public static final fun applySepia (Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
@@ -21427,6 +21440,96 @@ public final class dev/shtanko/grasp/polymorphism/example1/Triangle : dev/shtank
2142721440
public final class dev/shtanko/grasp/polymorphism/example1/Triangle$Companion {
2142821441
}
2142921442

21443+
public abstract interface class dev/shtanko/http/ConnectionFactory {
21444+
public abstract fun invoke ()Ljava/sql/Connection;
21445+
}
21446+
21447+
public final class dev/shtanko/http/CustomInterceptor : okhttp3/Interceptor {
21448+
public static final field Companion Ldev/shtanko/http/CustomInterceptor$Companion;
21449+
public synthetic fun <init> (Ldev/shtanko/http/HttpLogger;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
21450+
public fun intercept (Lokhttp3/Interceptor$Chain;)Lokhttp3/Response;
21451+
}
21452+
21453+
public final class dev/shtanko/http/CustomInterceptor$Companion {
21454+
public final fun create (Ldev/shtanko/http/HttpLogger;)Ldev/shtanko/http/CustomInterceptor;
21455+
public static synthetic fun create$default (Ldev/shtanko/http/CustomInterceptor$Companion;Ldev/shtanko/http/HttpLogger;ILjava/lang/Object;)Ldev/shtanko/http/CustomInterceptor;
21456+
}
21457+
21458+
public final class dev/shtanko/http/DbHttpLogger : dev/shtanko/http/HttpLogger {
21459+
public fun <init> (Ldev/shtanko/http/HttpLogRepository;)V
21460+
public fun logRequest (Lokhttp3/Request;)V
21461+
public fun logResponse (Lokhttp3/Response;D)V
21462+
}
21463+
21464+
public final class dev/shtanko/http/DefaultHttpLogger : dev/shtanko/http/HttpLogger {
21465+
public fun <init> ()V
21466+
public fun logRequest (Lokhttp3/Request;)V
21467+
public fun logResponse (Lokhttp3/Response;D)V
21468+
}
21469+
21470+
public final class dev/shtanko/http/FileSqliteConnectionFactory : dev/shtanko/http/ConnectionFactory {
21471+
public fun <init> ()V
21472+
public fun <init> (Ljava/lang/String;)V
21473+
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
21474+
public fun invoke ()Ljava/sql/Connection;
21475+
}
21476+
21477+
public final class dev/shtanko/http/HttpLogEntry {
21478+
public fun <init> (Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;DLjava/time/Instant;)V
21479+
public synthetic fun <init> (Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;DLjava/time/Instant;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
21480+
public final fun component1 ()Ljava/lang/Long;
21481+
public final fun component2 ()Ljava/lang/String;
21482+
public final fun component3 ()Ljava/lang/String;
21483+
public final fun component4 ()Ljava/lang/String;
21484+
public final fun component5 ()I
21485+
public final fun component6 ()Ljava/lang/String;
21486+
public final fun component7 ()D
21487+
public final fun component8 ()Ljava/time/Instant;
21488+
public final fun copy (Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;DLjava/time/Instant;)Ldev/shtanko/http/HttpLogEntry;
21489+
public static synthetic fun copy$default (Ldev/shtanko/http/HttpLogEntry;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;DLjava/time/Instant;ILjava/lang/Object;)Ldev/shtanko/http/HttpLogEntry;
21490+
public fun equals (Ljava/lang/Object;)Z
21491+
public final fun getDurationMs ()D
21492+
public final fun getId ()Ljava/lang/Long;
21493+
public final fun getMethod ()Ljava/lang/String;
21494+
public final fun getRequestHeaders ()Ljava/lang/String;
21495+
public final fun getResponseCode ()I
21496+
public final fun getResponseHeaders ()Ljava/lang/String;
21497+
public final fun getTimestamp ()Ljava/time/Instant;
21498+
public final fun getUrl ()Ljava/lang/String;
21499+
public fun hashCode ()I
21500+
public fun toString ()Ljava/lang/String;
21501+
}
21502+
21503+
public final class dev/shtanko/http/HttpLogRepository {
21504+
public static final field Companion Ldev/shtanko/http/HttpLogRepository$Companion;
21505+
public fun <init> (Ljava/sql/Connection;)V
21506+
public final fun count ()J
21507+
public final fun deleteOlderThan (Ljava/time/Instant;)I
21508+
public final fun getAll ()Ljava/util/List;
21509+
public final fun getById (J)Ldev/shtanko/http/HttpLogEntry;
21510+
public final fun getByUrlPattern (Ljava/lang/String;)Ljava/util/List;
21511+
public final fun init ()V
21512+
public final fun insert (Ldev/shtanko/http/HttpLogEntry;)V
21513+
}
21514+
21515+
public final class dev/shtanko/http/HttpLogRepository$Companion {
21516+
}
21517+
21518+
public abstract interface class dev/shtanko/http/HttpLogger {
21519+
public abstract fun logRequest (Lokhttp3/Request;)V
21520+
public abstract fun logResponse (Lokhttp3/Response;D)V
21521+
}
21522+
21523+
public final class dev/shtanko/http/InMemorySqliteConnectionFactory : dev/shtanko/http/ConnectionFactory {
21524+
public fun <init> ()V
21525+
public fun invoke ()Ljava/sql/Connection;
21526+
}
21527+
21528+
public final class dev/shtanko/http/Main {
21529+
public static final fun main ()V
21530+
public static synthetic fun main ([Ljava/lang/String;)V
21531+
}
21532+
2143021533
public final class dev/shtanko/jmm/memory/ManualResourceManagementKt {
2143121534
public static final fun readFromFile (Ljava/lang/String;)V
2143221535
}

build.gradle.kts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ repositories {
7373
application {
7474
mainClass.set("link.kotlin.scripts.Application")
7575
mainClass.set("dev.shtanko.report.ReportParserKt")
76+
mainClass.set("dev.shtanko.http.Main")
77+
}
78+
79+
tasks.register<JavaExec>("dev.shtanko.http.Main.main()") {
80+
mainClass.set("dev.shtanko.http.Main")
81+
group = "application"
82+
mainClass.set("dev.shtanko.http.Main")
83+
classpath = sourceSets["main"].runtimeClasspath
7684
}
7785

7886
pitest {
@@ -339,8 +347,8 @@ dependencies {
339347
implementation("org.openjdk.jol:jol-core:0.17")
340348
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
341349
implementation(jsoup)
342-
implementation("com.google.protobuf:protobuf-java:4.31.1")
343-
implementation("com.google.protobuf:protobuf-kotlin-lite:4.31.1")
350+
implementation("com.google.protobuf:protobuf-java:4.32.0")
351+
implementation("com.google.protobuf:protobuf-kotlin-lite:4.32.0")
344352
implementation("io.grpc:grpc-stub:1.74.0")
345353
implementation("io.grpc:grpc-protobuf:1.74.0")
346354

@@ -368,6 +376,7 @@ dependencies {
368376
testImplementation(turbine)
369377
testImplementation(truth)
370378
}
379+
implementation("org.xerial:sqlite-jdbc:3.50.3.0")
371380
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
372381
}
373382

config/main.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
<p align="center">
44
<a href="https://github.com/ashtanko/kotlab/actions/workflows/build.yml"><img alt="Build" src="https://github.com/ashtanko/kotlab/actions/workflows/build.yml/badge.svg?branch=main"/></a>
55
<a href="https://codecov.io/gh/ashtanko/kotlab"><img alt="Codecov" src="https://codecov.io/gh/ashtanko/kotlab/branch/main/graph/badge.svg?token=JEU9EIJMHA"/></a>
6-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Test Coverage" src="https://qlty.sh/gh/ashtanko/projects/kotlab/coverage.svg"/></a>
76
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage"><img alt="Codacy Coverage Badge" src="https://app.codacy.com/project/badge/Coverage/74cad08184b34038bb5c64c317384367"/></a>
87
<a href="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab"><img alt="CodeFactor" src="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab/badge"/></a>
9-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Maintainability" src="https://qlty.sh/gh/ashtanko/projects/kotlab/maintainability.svg"/></a>
108
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img alt="Codacy Grade Badge" src="https://app.codacy.com/project/badge/Grade/74cad08184b34038bb5c64c317384367"/></a>
119
<a href="https://codebeat.co/projects/github-com-ashtanko-kotlab-main"><img alt="Codebeat Badge" src="https://codebeat.co/badges/b5a26fee-b6d2-46f2-b121-c3d98cb13c9f"/></a>
1210
<a href="https://hitsofcode.com/github/ashtanko/kotlab/view?branch=main"><img alt="Hits-of-Code" src="https://hitsofcode.com/github/ashtanko/kotlab?branch=main"/></a>

config/main.md.bak

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
<p align="center">
44
<a href="https://github.com/ashtanko/kotlab/actions/workflows/build.yml"><img alt="Build" src="https://github.com/ashtanko/kotlab/actions/workflows/build.yml/badge.svg?branch=main"/></a>
55
<a href="https://codecov.io/gh/ashtanko/kotlab"><img alt="Codecov" src="https://codecov.io/gh/ashtanko/kotlab/branch/main/graph/badge.svg?token=JEU9EIJMHA"/></a>
6-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Test Coverage" src="https://qlty.sh/gh/ashtanko/projects/kotlab/coverage.svg"/></a>
76
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage"><img alt="Codacy Coverage Badge" src="https://app.codacy.com/project/badge/Coverage/74cad08184b34038bb5c64c317384367"/></a>
87
<a href="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab"><img alt="CodeFactor" src="https://www.codefactor.io/repository/github/ashtanko/kotlin-lab/badge"/></a>
9-
<a href="https://qlty.sh/gh/ashtanko/projects/kotlab"><img alt="Maintainability" src="https://qlty.sh/gh/ashtanko/projects/kotlab/maintainability.svg"/></a>
108
<a href="https://app.codacy.com/gh/ashtanko/kotlab/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img alt="Codacy Grade Badge" src="https://app.codacy.com/project/badge/Grade/74cad08184b34038bb5c64c317384367"/></a>
119
<a href="https://codebeat.co/projects/github-com-ashtanko-kotlab-main"><img alt="Codebeat Badge" src="https://codebeat.co/badges/b5a26fee-b6d2-46f2-b121-c3d98cb13c9f"/></a>
1210
<a href="https://hitsofcode.com/github/ashtanko/kotlab/view?branch=main"><img alt="Hits-of-Code" src="https://hitsofcode.com/github/ashtanko/kotlab?branch=main"/></a>

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ junit = "5.13.4" # https://junit.org/junit5
1919
kotest = "5.9.1" # https://kotest.io
2020
kotlintest = "3.4.2" # https://mvnrepository.com/artifact/io.kotlintest/kotlintest-core
2121
assertj = "3.27.4" # https://assertj.github.io/doc
22-
mockito = "5.18.0" # https://mvnrepository.com/artifact/org.mockito/mockito-core
22+
mockito = "5.19.0" # https://mvnrepository.com/artifact/org.mockito/mockito-core
2323
mockitoKotlin = "6.0.0" # https://github.com/mockito/mockito-kotlin
2424
mockk = "1.14.5" # https://mockk.io
2525
hamcrest = "3.0" # https://hamcrest.org
@@ -39,8 +39,8 @@ retrofit = "3.0.0" # https://github.com/square/retrofit
3939
okhttp = "5.1.0" # https://square.github.io/okhttp/changelogs/changelog
4040
sandwich = "2.1.2" # https://github.com/skydoves/sandwich
4141
protobufPlugin = "0.9.5" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-gradle-plugin
42-
protobufKotlin = "4.31.1" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-kotlin
43-
protoc = "4.31.1" # https://mvnrepository.com/artifact/com.google.protobuf/protoc
42+
protobufKotlin = "4.32.0" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-kotlin
43+
protoc = "4.32.0" # https://mvnrepository.com/artifact/com.google.protobuf/protoc
4444
jsoup = "1.21.1" # https://jsoup.org/
4545

4646
# --- Dependency Injection ---
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package dev.shtanko.concurrency.coroutines.examples
2+
3+
import dev.shtanko.utils.ResourceFilePath
4+
import dev.shtanko.utils.readImageBytes
5+
import java.awt.Color
6+
import java.awt.image.BufferedImage
7+
import kotlin.math.sqrt
8+
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.async
10+
import kotlinx.coroutines.awaitAll
11+
import kotlinx.coroutines.coroutineScope
12+
import kotlinx.coroutines.runBlocking
13+
14+
private const val KERNEL_RADIUS = 1
15+
16+
private val KERNEL_X = arrayOf(
17+
intArrayOf(-1, 0, 1),
18+
intArrayOf(-2, 0, 2),
19+
intArrayOf(-1, 0, 1),
20+
)
21+
22+
private val KERNEL_Y = arrayOf(
23+
intArrayOf(-1, -2, -1),
24+
intArrayOf(0, 0, 0),
25+
intArrayOf(1, 2, 1),
26+
)
27+
28+
suspend fun processImageParallel(image: BufferedImage): BufferedImage = coroutineScope {
29+
val segments = segmentImage(image, numberOfSegments = 8)
30+
31+
val processedRegions = segments.map { segment ->
32+
async(Dispatchers.Default) {
33+
val edges = detectEdges(segment)
34+
val filtered = applyRegionSpecificFilter(segment)
35+
blendSegment(filtered, edges)
36+
}
37+
}
38+
39+
val finalImage = mergeSegments(processedRegions.awaitAll(), image.width, image.height)
40+
return@coroutineScope finalImage
41+
}
42+
43+
fun segmentImage(image: BufferedImage, numberOfSegments: Int): List<BufferedImage> {
44+
val heightPerSegment = image.height / numberOfSegments
45+
return List(numberOfSegments) { i ->
46+
val y = i * heightPerSegment
47+
val h = if (i == numberOfSegments - 1) image.height - y else heightPerSegment
48+
image.getSubimage(0, y, image.width, h)
49+
}
50+
}
51+
52+
fun detectEdges(image: BufferedImage): BufferedImage {
53+
val w = image.width
54+
val h = image.height
55+
val edgeImage = BufferedImage(w, h, BufferedImage.TYPE_INT_RGB)
56+
57+
for (y in KERNEL_RADIUS until h - KERNEL_RADIUS) {
58+
for (x in KERNEL_RADIUS until w - KERNEL_RADIUS) {
59+
var gx = 0
60+
var gy = 0
61+
62+
for (ky in -KERNEL_RADIUS..KERNEL_RADIUS) {
63+
for (kx in -KERNEL_RADIUS..KERNEL_RADIUS) {
64+
val pixel = Color(image.getRGB(x + kx, y + ky)).red
65+
gx += pixel * KERNEL_X[ky + KERNEL_RADIUS][kx + KERNEL_RADIUS]
66+
gy += pixel * KERNEL_Y[ky + KERNEL_RADIUS][kx + KERNEL_RADIUS]
67+
}
68+
}
69+
70+
val magnitude = sqrt((gx * gx + gy * gy).toDouble())
71+
.toInt()
72+
.coerceIn(0, MAX_COLOR_VALUE)
73+
val gray = Color(magnitude, magnitude, magnitude)
74+
edgeImage.setRGB(x, y, gray.rgb)
75+
}
76+
}
77+
78+
return edgeImage
79+
}
80+
81+
fun applyRegionSpecificFilter(image: BufferedImage): BufferedImage {
82+
val output = BufferedImage(image.width, image.height, BufferedImage.TYPE_INT_RGB)
83+
for (y in 0 until image.height) {
84+
for (x in 0 until image.width) {
85+
val c = Color(image.getRGB(x, y))
86+
val r = MAX_COLOR - c.red
87+
val g = MAX_COLOR - c.green
88+
val b = MAX_COLOR - c.blue
89+
output.setRGB(x, y, Color(r, g, b).rgb)
90+
}
91+
}
92+
return output
93+
}
94+
95+
fun blendSegment(filtered: BufferedImage, edges: BufferedImage): BufferedImage {
96+
val w = filtered.width
97+
val h = filtered.height
98+
val blended = BufferedImage(w, h, BufferedImage.TYPE_INT_RGB)
99+
100+
for (y in 0 until h) {
101+
for (x in 0 until w) {
102+
val c1 = Color(filtered.getRGB(x, y))
103+
val c2 = Color(edges.getRGB(x, y))
104+
105+
val r = ((c1.red + c2.red) / 2).coerceIn(0, MAX_COLOR)
106+
val g = ((c1.green + c2.green) / 2).coerceIn(0, MAX_COLOR)
107+
val b = ((c1.blue + c2.blue) / 2).coerceIn(0, MAX_COLOR)
108+
109+
blended.setRGB(x, y, Color(r, g, b).rgb)
110+
}
111+
}
112+
113+
return blended
114+
}
115+
116+
fun mergeSegments(segments: List<BufferedImage>, totalWidth: Int, totalHeight: Int): BufferedImage {
117+
val result = BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB)
118+
var currentY = 0
119+
for (segment in segments) {
120+
result.graphics.drawImage(segment, 0, currentY, null)
121+
currentY += segment.height
122+
}
123+
return result
124+
}
125+
126+
fun main() = runBlocking {
127+
val path: ResourceFilePath = "images/bd.jpg"
128+
val inputImage = decodeImage(path.readImageBytes())
129+
val result = processImageParallel(inputImage)
130+
131+
val resultBytes = result.toByteArray()
132+
display(resultBytes)
133+
}

0 commit comments

Comments
 (0)