Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Fix upside-down photos on Nexus 5X #186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gen/
.idea
.idea_modules
target/
libmmcamera_imx179_mod/imx179_patch
libmmcamera_imx179_mod/imx179_patch
project/build.properties
4 changes: 3 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="pkmx.lcamera"
android:versionCode="3"
android:versionName="0.3">
Expand All @@ -12,7 +13,8 @@
<application android:label="L Camera"
android:icon="@drawable/ic_launcher"
android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen"
android:allowBackup="true">
android:allowBackup="true"
tools:replace="android:label">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Screenshot](screenshot.jpg?raw=true)

**L Camera** is an open-source experimental camera app for Android L devices using the new `android.hardware.camera2` API. Currently, the only supported device is Nexus 5 and Nexus 6 running Android 5.0 Lollipop.
**L Camera** is an open-source experimental camera app for Android L (and newer) devices using the new `android.hardware.camera2` API. Currently, supported devices include Nexus 5, 6, 5X and 6P running Android 5.0 Lollipop and 6.0 Marshmallow.

*Please note that this app is intended to test and study new features of the camera API, it is not for general uses as it lacks many basic camera features (location tagging, white balance, photo review, flash control, etc).*

Expand Down Expand Up @@ -116,15 +116,17 @@ The app is written in the [Scala](http://www.scala-lang.org/) programming langua

### How to build

You must have both **scala 2.11.5** and **sbt >= 0.13** installed.
You must have both **scala 2.11.8** and **sbt >= 0.13** installed.
Also, you must ensure that sbt runs with JDK 7, not 8.
For example, `sbt -java-home `/usr/libexec/java_home -v 1.7` on OS X.

To build the app (the resulting APK will be placed in the `bin/` directory):

$ sbt package
$ sbt android:package

To build and run the app on device (assuming you have `adb` and developer mode enabled):

$ sbt run
$ sbt android:run

### Debugging

Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import android.Keys._
import android.Dependencies.aar

android.Plugin.androidBuild

name := "lcamera"

scalaVersion := "2.11.5"
scalaVersion := "2.11.8"

resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"

Expand All @@ -20,9 +18,9 @@ libraryDependencies ++= Seq(
platformTarget in Android := "android-21"

proguardCache in Android ++=
Seq ( ProguardCache("org.scaloid") % "org.scaloid" %% "scaloid"
, ProguardCache("rx") % "com.scalarx" %% "scalarx"
, ProguardCache("akka") % "com.typesafe.akka" %% "akka-actor"
Seq ( "org.scaloid.scaloid"
, "com.scalarx.scalarx"
, "com.typesafe.akka.akka-actor"
)

proguardOptions in Android ++=
Expand All @@ -33,10 +31,12 @@ proguardOptions in Android ++=
, "-dontwarn sun.misc.Unsafe"
)

scalacOptions in Compile ++= Seq("-feature", "-deprecation", "-Xlint", "-Xfuture", "-Ywarn-dead-code", "-Ywarn-unused")
scalacOptions ++= Seq("-target:jvm-1.7", "-feature", "-deprecation", "-Xlint", "-Xfuture", "-Ywarn-dead-code", "-Ywarn-unused")

javacOptions ++= Seq("-source", "1.7")

run <<= run in Android

install <<= install in Android

Keys.`package` <<= `packageT` in Android
//Keys.`package` <<= `packageT` in Android
1 change: 1 addition & 0 deletions project/build.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object Build extends android.AutoBuild
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.3.5")
addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.3")

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")

libraryDependencies += "net.sf.proguard" % "proguard-base" % "5.0"
libraryDependencies += "net.sf.proguard" % "proguard-base" % "5.2.1"
30 changes: 16 additions & 14 deletions src/pkmx/lcamera/MainActivity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object Utils {
setVideoSize(vc.width, vc.height)
setVideoEncodingBitRate(vc.bitrate)
setVideoFrameRate(vc.fps)
setOrientationHint(orientationToDegree(orientation))
setOrientationHint(orientation)
setOutputFile(tmpFilePath)
setVideoEncoder(2) // H264
setAudioEncoder(3) // AAC
Expand All @@ -130,14 +130,6 @@ object Utils {

def renameFile(src: String, dst: String): Unit = { new File(src).renameTo(new File(dst)) }

def orientationToDegree(orientation: Int) = orientation match {
case Surface.ROTATION_0 => 90
case Surface.ROTATION_90 => 0
case Surface.ROTATION_180 => 270
case Surface.ROTATION_270 => 180
case _ => 0
}

def createPathIfNotExist(path: String): String = {
val file = new File(path)
if (!file.exists()) {
Expand Down Expand Up @@ -436,7 +428,7 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager:
setupRequest(request, focus, exposure)
request.set_(LENS_OPTICAL_STABILIZATION_MODE, LENS_OPTICAL_STABILIZATION_MODE_ON)
request.set_(JPEG_QUALITY, 100.toByte)
request.set_(JPEG_ORIENTATION, orientationToDegree(orientation))
request.set_(JPEG_ORIENTATION, orientation)
request.set_(STATISTICS_LENS_SHADING_MAP_MODE, STATISTICS_LENS_SHADING_MAP_MODE_ON) // Required for RAW capture
List(previewSurface, jpegSurface, rawSurface) foreach request.addTarget

Expand Down Expand Up @@ -727,7 +719,17 @@ class MainActivity extends SActivity with Observable {
val userVideoConfiguration = Var(videoConfigurations(0))
val videoConfiguration = Rx { availableVideoConfigurations() find { _ == userVideoConfiguration() } orElse availableVideoConfigurations().lift(0) }

val orientationVar = Var(windowManager.getDefaultDisplay.getRotation)
def orientationToDegree(orientation: Int) = orientation match {
case Surface.ROTATION_0 => 0
case Surface.ROTATION_90 => 90
case Surface.ROTATION_180 => 180
case Surface.ROTATION_270 => 270
case _ => 0
}

val screenOrientationVar = Var(windowManager.getDefaultDisplay.getRotation)
val cameraOrientationVar: Rx[Integer] = Rx { lcamera().map(_.characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION)).getOrElse(0) }
val orientationVar: Rx[Integer] = Rx { (cameraOrientationVar() - orientationToDegree(screenOrientationVar()) + 360) % 360 }

val orientationEventListener = new OrientationEventListener(this) {
override def onOrientationChanged(deg: Int) = {
Expand All @@ -739,8 +741,8 @@ class MainActivity extends SActivity with Observable {
else Surface.ROTATION_0

debug(newOrientation.toString)
if (orientationVar() != newOrientation) {
orientationVar() = newOrientation // FIXME: Re-create video session
if (screenOrientationVar() != newOrientation) {
screenOrientationVar() = newOrientation // FIXME: Re-create video session
}
}
}
Expand Down Expand Up @@ -1324,4 +1326,4 @@ class MainActivity extends SActivity with Observable {
ta.recycle()
resId
}
}
}