-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
299 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Base64 Extensions | ||
|
||
This extension provides `Base64Loader` a `ImageBitmapLoader` for loading base64 encoded images to a `ImageBitmap`. | ||
|
||
| Loader | Input Class | Demo | | ||
|----------------|-------------|----------------------------------------------------------------------------------------------------------------| | ||
| `Base64Loader` | `String` | [`Base64DemoScreen`](demo/composeApp/src/commonMain/kotlin/dev/jordond/kmpalette/dominant/Base64DemoScreen.kt) | | ||
|
||
# Setup | ||
|
||
You need to add the following to your `build.gradle.kts` file: | ||
|
||
```kotlin | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kmpalette.core) | ||
implementation(libs.kmpalette.extensions.base64) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
You will need to have a image (png, jpg, etc) encoded as a Base64 `String`. You can then | ||
use `Base64Loader` to load the image. | ||
|
||
**Note:** If there is a header on the Base64 `String` it will be stripped and ignored. | ||
|
||
```kotlin | ||
val base64Image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAAD" + | ||
"gdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3" + | ||
"NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQB" + | ||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HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3k" + | ||
"vgLI5AzFfo379UAAAAASUVORK5CYII=" | ||
|
||
val imageBitmap: ImageBitmap = Base64Loader.load(base64Image) | ||
|
||
// Or using one of the composeable functions | ||
val paletteState = rememebrPaletteState(Base64Loader) | ||
LaunchedEffect(base64Image) { | ||
paletteState.generate(base64Image) | ||
} | ||
``` |
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,33 @@ | ||
# ByteArray Extensions | ||
|
||
This extension provides `ByteArrayLoader` a `ImageBitmapLoader` for loading image bytes to | ||
a `ImageBitmap`. | ||
|
||
| Loader | Input Class | Demo | | ||
|-------------------|-------------|------| | ||
| `ByteArrayLoader` | `ByteArray` | N/A | | ||
|
||
# Setup | ||
|
||
You need to add the following to your `build.gradle.kts` file: | ||
|
||
```kotlin | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kmpalette.core) | ||
implementation(libs.kmpalette.extensions.bytearray) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
You will need to have a `ByteArray` containing all the bytes of an image. Typically this extension | ||
isn't used directly, but instead used by other extensions that provide a `ByteArray` as an output: | ||
|
||
- `extensions-resources` | ||
- `extensions-network` |
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,45 @@ | ||
# Libres Extensions | ||
|
||
This extension provides `LibresLoader` a `ImageBitmapLoader` for | ||
loading [Libres](https://github.com/Skeptick/libres) `Image` objects. | ||
|
||
| Library | Loader | Input Class | Demo | | ||
|----------------------------------------------|----------------|-------------|---------------------------------------------------------------------------------------------------------------------| | ||
| [libres](https://github.com/Skeptick/libres) | `LibresLoader` | `Image` | [`LibresPaletteScreen`](demo/composeApp/src/commonMain/kotlin/dev/jordond/kmpalette/palette/LibresPaletteScreen.kt) | | ||
|
||
## Setup | ||
|
||
First you need to follow the setup instructions for [Libres](https://github.com/Skeptick/libres). | ||
|
||
Then you need to add the following to your `build.gradle.kts` file: | ||
|
||
```kotlin | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kmpalette.core) | ||
implementation(libs.kmpalette.extensions.libres) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Warning:** Although Libres supports XML and SVG vector images, this library does not. It will | ||
crash if you attempt to use a vector format. | ||
|
||
## Usage | ||
|
||
Add your images to the `libres/images` folder in the `commonMain` source set. You can then load them | ||
using the `LibresLoader`: | ||
|
||
```kotlin | ||
val imageBitmap: ImageBitmap = LibresLoader.load(Res.image.example1) | ||
|
||
// Or using one of the composeable functions | ||
val paletteState = rememebrPaletteState(loader = Base64Loader) | ||
LaunchedEffect(base64Image) { | ||
paletteState.generate(Res.image.example1) | ||
} | ||
``` |
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,74 @@ | ||
# Network Extensions | ||
|
||
This extension provides `Network` a `ImageBitmapLoader` for loading images from a URL. | ||
|
||
| Library | Loader | Input Class | Demo | | ||
|------------------------------------------------------|----------------------------------------|-----------------|-------| | ||
| [`extensions-network`](extensions-network/README.md) | [ktor](https://github.com/ktorio/ktor) | `NetworkLoader` | `Url` | [`NetworkDemoScreen`](demo/composeApp/src/commonMain/kotlin/dev/jordond/kmpalette/dominant/NetworkDemoScreen.kt) | | ||
|
||
## Setup | ||
|
||
In order to use these extensions you will need to add the Ktor dependency to | ||
your `build.gradle.kts`, you will need the `core` library as well as a client for each of your | ||
supported platforms. | ||
|
||
Then you need to add the following to your `build.gradle.kts` file: | ||
|
||
```kotlin | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kmpalette.core) | ||
implementation("io.ktor:ktor-client-core:$ktor_version") | ||
} | ||
} | ||
|
||
androidMain { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-android:$ktor_version") | ||
} | ||
} | ||
|
||
iosMain { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-darwin:$ktor_version") | ||
} | ||
} | ||
|
||
jvmMain { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-okhttp:$ktor_version") | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Now you can use the `NetworkLoader` to load images from a URL. | ||
|
||
You can customize the behaviour of the request by passing in your own `HttpClient` | ||
of `HttpRequestBuilder`: | ||
|
||
```kotlin | ||
public class NetworkLoader( | ||
private val httpClient: HttpClient = HttpClient(), | ||
private val requestBuilder: HttpRequestBuilder = HttpRequestBuilder(), | ||
) : ImageBitmapLoader<Url> | ||
``` | ||
|
||
Now you can pass a `Url` object to load an image: | ||
|
||
```kotlin | ||
@Composable | ||
fun MyComposable(url: Url) { | ||
val paletteState = rememberPaletteState(loader = NetworkLoader()) | ||
LaunchedEffect(url) { | ||
paletteState.generate(url) | ||
} | ||
} | ||
``` | ||
|
||
The Image will be fetched, converted into a `ImageBitmap` then a palette will be generated. |
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,59 @@ | ||
# Compose Multiplatform Resources Extensions | ||
|
||
This extension provides `ResourceLoader` a `ImageBitmapLoader` for images using Compose | ||
Multiplatform Resources. | ||
|
||
| Library | Loader | Input Class | Demo | | ||
|----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------|------------| | ||
| [`extensions-resources`](extensions-resources/README.md) | [Compose Multiplatform Resources](https://github.com/JetBrains/compose-multiplatform/tree/master/components/resources) | `ResourceLoader` | `Resource` | [`ResourcesPaletteScreen`](demo/composeApp/src/commonMain/kotlin/dev/jordond/kmpalette/palette/ResourcesPaletteScreen.kt) | | ||
|
||
## Setup | ||
|
||
Then you need to add the following to your `build.gradle.kts` file: | ||
|
||
```kotlin | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kmpalette.core) | ||
implementation(libs.kmpalette.extensions.resources) | ||
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) | ||
implementation(compose.components.resources) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ... | ||
|
||
android { | ||
// ... | ||
|
||
sourceSets["main"].apply { | ||
res.srcDirs("src/androidMain/resources") | ||
resources.srcDirs("src/commonMain/resources") | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
**Warning:** Although Compose Resources supports XML and SVG vector images, this library does not. | ||
It will | ||
crash if you attempt to use a vector format. | ||
|
||
## Usage | ||
|
||
Add your images to the `commonMain/resources` folder. You can then load them using | ||
the `ResourceLoader`: | ||
|
||
```kotlin | ||
val imageBitmap: ImageBitmap = ResourceLoader.load(resource("example1.png")) | ||
|
||
// Or using one of the composeable functions | ||
val paletteState = rememebrPaletteState(loader = ResourceLoader) | ||
LaunchedEffect(base64Image) { | ||
paletteState.generate(resource("example1.png")) | ||
} | ||
``` |