Skip to content

Commit

Permalink
Merge pull request #30 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.6.1
  • Loading branch information
Alex009 authored Mar 9, 2021
2 parents 5b4013c + e3a9ca1 commit 804f77b
Show file tree
Hide file tree
Showing 20 changed files with 543 additions and 503 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![moko-media](img/logo.png)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-media/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-media/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.0-orange)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-media/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-media/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.21-orange)

# Mobile Kotlin media access
This is a Kotlin MultiPlatform library that provides media picking in common code (photo/video) and video player controls.
Expand Down Expand Up @@ -36,6 +36,8 @@ TODO
- kotlin 1.4.0
- 0.5.0
- 0.6.0
- kotlin 1.4.21
- 0.6.1

## Installation
root build.gradle
Expand All @@ -51,7 +53,7 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:media:0.6.0")
commonMainApi("dev.icerock.moko:media:0.6.1")
}
```

Expand Down
10 changes: 4 additions & 6 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
*/

plugins {
id("org.jetbrains.kotlin.jvm") version("1.4.0")
id("org.jetbrains.kotlin.jvm") version("1.4.21")
}

repositories {
mavenLocal()

jcenter()
google()

maven { url = uri("https://dl.bintray.com/icerockdev/plugins") }
}

dependencies {
implementation("dev.icerock:mobile-multiplatform:0.7.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0")
implementation("com.android.tools.build:gradle:4.0.1")
implementation("dev.icerock:mobile-multiplatform:0.9.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21")
implementation("com.android.tools.build:gradle:4.1.1")
}
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
*/

object Deps {
private const val kotlinVersion = "1.4.0"
private const val kotlinVersion = "1.4.21"

private const val androidAppCompatVersion = "1.1.0"
private const val materialDesignVersion = "1.0.0"
private const val androidLifecycleVersion = "2.1.0"
private const val androidCoreTestingVersion = "2.1.0"
private const val androidExifInterface = "1.0.0"
private const val androidExifInterface = "1.3.2"
private const val androidMediaFilePicker = "1.8"

private const val coroutinesVersion = "1.3.9"
private const val mokoMvvmVersion = "0.8.0"
private const val mokoPermissionsVersion = "0.6.0"
const val mokoMediaVersion = "0.6.0"
private const val coroutinesVersion = "1.4.2"
private const val mokoMvvmVersion = "0.9.1"
private const val mokoPermissionsVersion = "0.7.0"
const val mokoMediaVersion = "0.6.1"

object Android {
const val compileSdk = 28
Expand Down Expand Up @@ -51,7 +51,8 @@ object Deps {
iosX64 = "dev.icerock.moko:permissions-iosx64:$mokoPermissionsVersion",
iosArm64 = "dev.icerock.moko:permissions-iosarm64:$mokoPermissionsVersion"
)
const val mokoMvvm = "dev.icerock.moko:mvvm:$mokoMvvmVersion"
const val mokoMvvmCore = "dev.icerock.moko:mvvm-core:$mokoMvvmVersion"
const val mokoMvvmLiveData = "dev.icerock.moko:mvvm-livedata:$mokoMvvmVersion"
const val mokoMedia = "dev.icerock.moko:media:$mokoMediaVersion"
}

Expand Down
60 changes: 54 additions & 6 deletions media/src/androidMain/kotlin/dev/icerock/moko/media/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,72 @@ package dev.icerock.moko.media
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.media.ExifInterface
import androidx.exifinterface.media.ExifInterface
import java.io.IOException
import java.io.InputStream

object BitmapUtils {

// TODO: unused
@Throws(IOException::class)
fun getAngle(filename: String): Int {
val exif = ExifInterface(filename)
val orientation =
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)

return when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> 90
ExifInterface.ORIENTATION_ROTATE_180 -> 180
ExifInterface.ORIENTATION_ROTATE_270 -> 270
else -> 0
}
}

@Throws(IOException::class)
fun getBitmapOrientation(bitmapStream: InputStream): Int {
val exif = ExifInterface(bitmapStream)
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
}

@Throws(IOException::class)
fun getNormalizedBitmap(
bitmapStream: InputStream,
orientation: Int,
sampleSize: Int? = null
): Bitmap {
val bitmapOptions = if (sampleSize != null) {
BitmapFactory.Options().apply {
inJustDecodeBounds = false
inSampleSize = sampleSize
}
} else null

val bitmap = BitmapFactory.decodeStream(bitmapStream, null, bitmapOptions)
?: throw IOException("Can't decode bitmap stream")

val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> return 90
ExifInterface.ORIENTATION_ROTATE_180 -> return 180
ExifInterface.ORIENTATION_ROTATE_270 -> return 270
else -> return 0
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.setRotate(90f)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180f)
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.setRotate(270f)
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1f, 1f)
ExifInterface.ORIENTATION_FLIP_VERTICAL -> matrix.setScale(1f, -1f)
ExifInterface.ORIENTATION_TRANSPOSE -> {
matrix.setRotate(90f)
matrix.postScale(-1f, 1f)
}
ExifInterface.ORIENTATION_TRANSVERSE -> {
matrix.setRotate(-90f)
matrix.postScale(-1f, 1f)
}
else -> return bitmap
}
val result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
bitmap.recycle()
return result
}

// TODO: unused
fun cloneRotated(bitmap: Bitmap, angle: Int): Bitmap {
if (angle != 0) {
val matrix = Matrix()
Expand Down Expand Up @@ -60,6 +106,7 @@ object BitmapUtils {
}
}

// TODO: unused
fun getBitmapForStream(
inputStream: InputStream,
sampleSize: Int
Expand All @@ -77,7 +124,8 @@ object BitmapUtils {
maxWidth: Int,
maxHeight: Int
): Int {
val (height: Int, width: Int) = options.run { outHeight to outWidth }
val height: Int = options.outHeight
val width: Int = options.outWidth
var inSampleSize = 1

if (height > maxHeight || width > maxWidth) {
Expand Down
Loading

0 comments on commit 804f77b

Please sign in to comment.