Skip to content

Commit

Permalink
Merge pull request #37 from tamimattafi/0.1.6
Browse files Browse the repository at this point in the history
Release 0.1.6

Fixed #33 in #35
Fixed #32 in #36
  • Loading branch information
tamimattafi authored Jan 23, 2025
2 parents 0c239c9 + da57265 commit c9359c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.attafitamim.krop.core.utils
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.toIntRect
import com.attafitamim.krop.core.images.DecodeParams
import com.attafitamim.krop.core.images.DecodeResult
import com.attafitamim.krop.core.images.ImageSrc
Expand Down Expand Up @@ -38,6 +39,8 @@ class UIImageSrc(
override val size: IntSize
) : ImageSrc {

private val resultParams = DecodeParams(1, size.toIntRect())

companion object {
operator fun invoke(sourceImage: UIImage): UIImageSrc {
val image = sourceImage.ensureCorrectOrientation()
Expand All @@ -50,8 +53,8 @@ class UIImageSrc(
}

override suspend fun open(params: DecodeParams): DecodeResult? {
val bitmap = image.toImageBitmap(params) ?: return null
return DecodeResult(params, bitmap)
val bitmap = image.toImageBitmap(COMPRESSION_QUALITY) ?: return null
return DecodeResult(resultParams, bitmap)
}
}

Expand All @@ -69,8 +72,13 @@ fun UIImage.toByteArray(quality: Double): ByteArray? {
return ByteArray(length.toInt()) { index -> data[index] }
}

@Deprecated("params will be removed in future major releases. Use quality instead.")
fun UIImage.toImageBitmap(params: DecodeParams): ImageBitmap? {
val quality = params.sampleSize * COMPRESSION_QUALITY
return toImageBitmap(quality)
}

fun UIImage.toImageBitmap(quality: Double): ImageBitmap? {
val byteArray = toByteArray(quality) ?: return null
return Image.makeFromEncoded(byteArray).toComposeImageBitmap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ fun CropperPreview(
zoomLimits = zoomLimits,
)
) {
withTransform({ transform(totalMat) }) {
image?.let { (params, bitmap) ->
image?.let { (params, bitmap) ->
withTransform({ transform(totalMat) }) {
drawImage(
bitmap, dstOffset = params.subset.topLeft,
dstSize = params.subset.size
)
}
}
with(style) {
clipPath(cropPath, ClipOp.Difference) {
drawRect(color = overlayColor)
with(style) {
clipPath(cropPath, ClipOp.Difference) {
drawRect(color = overlayColor)
}
drawCropRect(cropRect)
}
drawCropRect(cropRect)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.gradle.api.publish.maven.MavenPomScm

class PublishConventions : Plugin<Project> {

private val version = "0.1.5"
private val version = "0.1.6"
private val group = "com.attafitamim.krop"

override fun apply(project: Project) {
Expand Down Expand Up @@ -49,8 +49,8 @@ private fun MavenPom.configure() {
}

private fun MavenPomLicense.configure() {
name.set("Apache License 2.0")
url.set("https://github.com/tamimattafi/krop/blob/main/LICENSE.md")
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}

private fun MavenPomDeveloper.configure() {
Expand Down

0 comments on commit c9359c5

Please sign in to comment.