Skip to content

Commit

Permalink
V0.1.9 (#29)
Browse files Browse the repository at this point in the history
* 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
robertjamison and dependabot[bot] authored Sep 21, 2024
1 parent d40535d commit 925f1a1
Show file tree
Hide file tree
Showing 92 changed files with 545 additions and 236 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

A Kotlin Multiplatform library to rapidly add basic features like pictures, logging, and audio to any project in a small and fast way.

| Platforms | Basic-Images | Basic-Logging | Basic-Sound |
|:--------------|:--------------------:|:--------------------:|:--------------------:|
| Android | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| iOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| macOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| watchOS | | :white_check_mark: | :white_check_mark: |
| tvOS | | :white_check_mark: | :white_check_mark: |
| nodeJS | | :white_check_mark: | :white_check_mark: |
| jsBrowser | | :white_check_mark: | :white_check_mark: |
| wasmJsBrowser | | :white_check_mark: | |
| JVM | | :white_check_mark: | |
| Linux | | :white_check_mark: | |
| Windows | | :white_check_mark: | |
| Platforms | Basic-Images | Basic-Logging | Basic-Sound |
|:--------------|:------------------:|:--------------------:|:------------------:|
| Android | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| iOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| macOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| watchOS | | :white_check_mark: | :white_check_mark: |
| tvOS | | :white_check_mark: | :white_check_mark: |
| nodeJS | | :white_check_mark: | :white_check_mark: |
| jsBrowser | | :white_check_mark: | :white_check_mark: |
| wasmJsBrowser | | :white_check_mark: | :white_check_mark: |
| JVM | :white_check_mark: | :white_check_mark: | |
| Linux | | :white_check_mark: | |
| Windows | | :white_check_mark: | |

## Documentation
* [Basic-Images](basic-images/README.md) [![Maven Central](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-images?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-images)
Expand Down
2 changes: 1 addition & 1 deletion basic-images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A Kotlin Multiplatform library to rapidly add logging to any project.
![badge-nodejs](https://img.shields.io/badge/jsNode-no_support-red.svg?style=flat)
![badge-jsBrowser](https://img.shields.io/badge/jsBrowser-no_support-red.svg?style=flat)
![badge-wasmJsBrowser](https://img.shields.io/badge/wasmJsBrowser-no_support-red.svg?style=flat)
![badge-jvm](http://img.shields.io/badge/jvm-no_support-red.svg?style=flat)
![badge-jvm](http://img.shields.io/badge/jvm-full_support-65c663.svg?style=flat)
![badge-linux](http://img.shields.io/badge/linux-no_support-red.svg?style=flat)
![badge-windows](http://img.shields.io/badge/windows-no_support-red.svg?style=flat)

Expand Down
9 changes: 7 additions & 2 deletions basic-images/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ kotlin {
// FORCES CHECK OF PUBLIC API DECLARATIONS
explicitApi()

// jvm()
//
jvm()

// js {
// browser {
// webpackTask {
Expand Down Expand Up @@ -87,8 +87,13 @@ kotlin {
implementation(libs.ktor.client.darwin)
implementation(libs.ktor.client.ios)
}
// tvosMain.dependencies {
// implementation(libs.ktor.client.darwin)
// implementation(libs.ktor.client.ios)
// }
// jvmMain.dependencies {}
// jsMain.dependencies {}
// wasmJsMain.dependencies {}
// linuxMain.dependencies {}
// mingwMain.dependencies {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
/**
* Contains [load] functions for [BasicImage] that accepts both [BasicUrl] and [BasicPath] objects.
*/
@OptIn(ExperimentalBasicImages::class)
public actual object ImageLoader {

/**
Expand All @@ -23,9 +24,10 @@ public actual object ImageLoader {
*/
public actual suspend fun load(url: BasicUrl): ImageBitmap? {
var bitmap: ImageBitmap? = null
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
ImageClient(url.toString())?.let { bitmapByteArray ->
bitmap = BitmapFactory.decodeByteArray(bitmapByteArray, 0, bitmapByteArray.size).asImageBitmap()
bitmap = BitmapFactory.decodeByteArray(bitmapByteArray, 0, bitmapByteArray.size)
.asImageBitmap()
} ?: {
bitmap = null
}
Expand All @@ -44,9 +46,10 @@ public actual object ImageLoader {
*/
public actual suspend fun load(path: BasicPath): ImageBitmap? {
var bitmap: ImageBitmap?
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
val bitmapByteArray = File(path.toString()).readBytes()
bitmap = BitmapFactory.decodeByteArray(bitmapByteArray, 0, bitmapByteArray.size).asImageBitmap()
bitmap = BitmapFactory.decodeByteArray(bitmapByteArray, 0, bitmapByteArray.size)
.asImageBitmap()
return@withContext bitmap
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import app.lexilabs.basic.images.ImageLoader.load
* @param placeholderEnabled Boolean value to determine if the image should be preceded by a
* circular progress indicator while loading.
*/
@ExperimentalBasicImages
@Composable
public fun BasicImage(
path: BasicPath,
Expand Down Expand Up @@ -121,6 +122,7 @@ public fun BasicImage(
* @param placeholderEnabled Boolean value to determine if the image should be preceded by a
* circular progress indicator while loading.
*/
@ExperimentalBasicImages
@Composable
public fun BasicImage(
url: BasicUrl,
Expand Down Expand Up @@ -163,6 +165,7 @@ public fun BasicImage(
/**
* A composable that displays while waiting on a [BasicImage] to load.
*/
@ExperimentalBasicImages
@Composable
public fun BasicImagePlaceHolder(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package app.lexilabs.basic.images
* println(path.toString())
* ```
*/
@ExperimentalBasicImages
public class BasicPath(pathString: String) {
private val path: String = pathString

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package app.lexilabs.basic.images
* println(url.toString())
* ```
*/
@ExperimentalBasicImages
public class BasicUrl(urlString: String) {
private val url: String = urlString

Expand Down
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()
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.ktor.utils.io.core.readBytes
* val image = ImageClient(urlString) // instantiate and request response from URL
* ```
*/
@ExperimentalBasicImages
public object ImageClient {

private const val TAG = "ImageClient"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.graphics.ImageBitmap
/**
* Contains [load] functions for [BasicImage] that accepts both [BasicUrl] and [BasicPath] objects.
*/
@ExperimentalBasicImages
public expect object ImageLoader {
/**
* Downloads a PNG, JPEG, or WEBP file from an internet URL using a [BasicUrl] object, then provides the [ImageBitmap] file, if available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package app.lexilabs.basic.images
* @property ImageState.SHOWING The [BasicImage] is displaying the bitmap
* @property ImageState.ERROR An error has occurred
*/
@ExperimentalBasicImages
public sealed class ImageState {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.lexilabs.basic.images

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import app.lexilabs.basic.images.ImageLoader.load
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.allocArrayOf
Expand Down Expand Up @@ -35,7 +36,7 @@ import platform.UIKit.UIImage
/**
* Contains [load] functions for [BasicImage] that accepts both [BasicUrl] and [BasicPath] objects.
*/
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
@OptIn(ExperimentalForeignApi::class, ExperimentalBasicImages::class)
public actual object ImageLoader {

/**
Expand All @@ -49,7 +50,7 @@ public actual object ImageLoader {
*/
public actual suspend fun load(url: BasicUrl): ImageBitmap? {
var bitmap: ImageBitmap? = null
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
ImageClient(url.toString())?.let { bitmapByteArray ->
bitmap = bitmapByteArray.toImageBitmap()
} ?: {
Expand All @@ -70,7 +71,7 @@ public actual object ImageLoader {
*/
public actual suspend fun load(path: BasicPath): ImageBitmap? {
var bitmap: ImageBitmap? = null
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
getFileAsImageBitmap(path.toString())
}
}
Expand All @@ -85,10 +86,13 @@ public actual object ImageLoader {
return this@toImageBitmap.toNSData().toUIImage().toSkiaImage()?.toComposeImageBitmap()
}

@OptIn(BetaInteropApi::class)
private fun ByteArray.toNSData(): NSData {
memScoped {
return NSData.create(bytes = allocArrayOf(this@toNSData),
length = this@toNSData.size.toULong())
return NSData.create(
bytes = allocArrayOf(this@toNSData),
length = this@toNSData.size.toULong()
)
}
}

Expand Down
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import platform.Foundation.create
/**
* Contains [load] functions for [BasicImage] that accepts both [BasicUrl] and [BasicPath] objects.
*/
@OptIn(ExperimentalForeignApi::class)
@OptIn(ExperimentalForeignApi::class, ExperimentalBasicImages::class)
public actual object ImageLoader {

/**
Expand All @@ -48,7 +48,7 @@ public actual object ImageLoader {
*/
public actual suspend fun load(url: BasicUrl): ImageBitmap? {
var bitmap: ImageBitmap? = null
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
ImageClient(url.toString())?.let { bitmapByteArray ->
bitmap = bitmapByteArray.toImageBitmap()
} ?: {
Expand All @@ -68,7 +68,7 @@ public actual object ImageLoader {
* ```
*/
public actual suspend fun load(path: BasicPath): ImageBitmap? {
return withContext(Dispatchers.IO){
return withContext(Dispatchers.IO) {
return@withContext getFileAsImageBitmap(filePath = path.toString())
}
}
Expand All @@ -86,8 +86,10 @@ public actual object ImageLoader {
@OptIn(BetaInteropApi::class)
private fun ByteArray.toNSData(): NSData {
memScoped {
return NSData.create(bytes = allocArrayOf(this@toNSData),
length = this@toNSData.size.toULong())
return NSData.create(
bytes = allocArrayOf(this@toNSData),
length = this@toNSData.size.toULong()
)
}
}

Expand Down
6 changes: 3 additions & 3 deletions basic-sound/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Basic-Sound](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-sound?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-sound)

A Kotlin Multiplatform library to rapidly integrate audio across all your Kotlin Multiplatform apps.
Currently, this library only ingests URLs; objects and files on the local path are not yet supported.
Currently, this library only ingests URLs and local paths. Composable Resources are also possible, but may be finicky.

![badge-android](http://img.shields.io/badge/android-full_support-65c663.svg?style=flat)
![badge-ios](http://img.shields.io/badge/ios-full_support-65c663.svg?style=flat)
Expand All @@ -13,13 +13,13 @@ Currently, this library only ingests URLs; objects and files on the local path a
![badge-tvos](http://img.shields.io/badge/tvos-full_support-65c663.svg?style=flat)
![badge-nodejs](https://img.shields.io/badge/jsNode-full_support-65c663.svg?style=flat)
![badge-jsBrowser](https://img.shields.io/badge/jsBrowser-full_support-65c663.svg?style=flat)
![badge-wasmJsBrowser](https://img.shields.io/badge/wasmJsBrowser-no_support-red.svg?style=flat)
![badge-wasmJsBrowser](https://img.shields.io/badge/wasmJsBrowser-full_support-65c663.svg?style=flat)
![badge-jvm](http://img.shields.io/badge/jvm-no_support-red.svg?style=flat)
![badge-linux](http://img.shields.io/badge/linux-no_support-red.svg?style=flat)
![badge-windows](http://img.shields.io/badge/windows-no_support-red.svg?style=flat)

## Supported Filetypes
| Format | Android | iOS | javascript | File / Container Types |
| Format | Android | iOS | javascript / wasm | File / Container Types |
|:----------|:------------------:|:------------------:|:------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| AAC LC | :white_check_mark: | :white_check_mark: | :x: | 3GPP (.3gp) MPEG-4 (.mp4, .m4a) ADTS raw AAC (.aac, decode in Android 3.1+, encode in Android 4.0+, ADIF not supported) MPEG-TS (.ts, not seekable, Android 3.0+) |
| AMR-NB | :white_check_mark: | :x: | :x: | 3GPP (.3gp) AMR (.amr) |
Expand Down
Loading

0 comments on commit 925f1a1

Please sign in to comment.