-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created ExperimentalBasicImages and added annotation to all BasicImage files. * Bump com.android.library from 8.6.0 to 8.6.1 Bumps com.android.library from 8.6.0 to 8.6.1. --- updated-dependencies: - dependency-name: com.android.library dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Dependabot/gradle/com.android.library 8.6.1 (#27) * Init v0.1.8 Increased dependabot.yml frequency * Bump com.android.library from 8.6.0 to 8.6.1 Bumps com.android.library from 8.6.0 to 8.6.1. --- updated-dependencies: - dependency-name: com.android.library dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.jetbrains.kotlinx:kotlinx-serialization-json Bumps [org.jetbrains.kotlinx:kotlinx-serialization-json](https://github.com/Kotlin/kotlinx.serialization) from 1.7.2 to 1.7.3. - [Release notes](https://github.com/Kotlin/kotlinx.serialization/releases) - [Changelog](https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md) - [Commits](Kotlin/kotlinx.serialization@v1.7.2...v1.7.3) --- updated-dependencies: - dependency-name: org.jetbrains.kotlinx:kotlinx-serialization-json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Added Basic-Sound support for wasmJS (untested). * Added JVM support for Basic-Image * Added JVM support for Basic-Image * Updated Basic-Sound README.md * Publish to Maven w/ dokka included * Publish to Maven w/ dokka included --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d40535d
commit 925f1a1
Showing
92 changed files
with
545 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
basic-images/src/commonMain/kotlin/app/lexilabs/basic/images/ExperimentalBasicImages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.lexilabs.basic.images | ||
|
||
/** | ||
* This API is not considered 'production' until reaching version 1.0.0 or higher | ||
*/ | ||
@RequiresOptIn(message = "This API is experimental, unstable, and may change.") | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | ||
public annotation class ExperimentalBasicImages() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
basic-images/src/jvmMain/kotlin/app/lexilabs/basic/images/ImageLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package app.lexilabs.basic.images | ||
|
||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.toComposeImageBitmap | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.awt.image.BufferedImage | ||
import java.io.ByteArrayInputStream | ||
import java.io.File | ||
import javax.imageio.ImageIO | ||
|
||
/** | ||
* Contains [load] functions for [BasicImage] that accepts both [BasicUrl] and [BasicPath] objects. | ||
*/ | ||
@OptIn(ExperimentalBasicImages::class) | ||
public actual object ImageLoader { | ||
|
||
/** | ||
* Downloads a PNG, JPEG, or WEBP file from an internet URL using a [BasicUrl] object, then provides the [ImageBitmap] file, if available. | ||
* | ||
* Example: | ||
* ```kotlin | ||
* val url = BasicUrl("https://picsum.photos/200") | ||
* val bitmap = ImageLoader.load(url) | ||
* ``` | ||
*/ | ||
public actual suspend fun load(url: BasicUrl): ImageBitmap? { | ||
var bitmap: ImageBitmap? = null | ||
return withContext(Dispatchers.IO) { | ||
ImageClient(url.toString())?.let { bitmapByteArray -> | ||
bitmap = bitmapByteArray.toImageBitmap() | ||
} ?: { | ||
bitmap = null | ||
} | ||
return@withContext bitmap | ||
} | ||
} | ||
|
||
/** | ||
* Opens a PNG, JPEG, or WEBP file from a local path using a [BasicPath] object, then provides the [ImageBitmap] file, if available. | ||
* | ||
* Example: | ||
* ```kotlin | ||
* val path = BasicPath("appLocalDirectory/cacheDirectory/images/exampleImage.jpeg") | ||
* val bitmap = ImageLoader.load(path) | ||
* ``` | ||
*/ | ||
public actual suspend fun load(path: BasicPath): ImageBitmap? { | ||
return withContext(Dispatchers.IO) { | ||
val bitmapByteArray = File(path.toString()).readBytes() | ||
return@withContext bitmapByteArray.toImageBitmap() | ||
} | ||
} | ||
|
||
private fun ByteArray.toImageBitmap(): ImageBitmap { | ||
// Convert ByteArray to BufferedImage | ||
val inputStream = ByteArrayInputStream(this) | ||
val bufferedImage: BufferedImage = ImageIO.read(inputStream) | ||
// Convert BufferedImage to ImageBitmap | ||
return bufferedImage.toComposeImageBitmap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.