Skip to content

Commit

Permalink
Update RICOH THETA Plugin Library to v3.3.0, and Add ImageFormat.NV21…
Browse files Browse the repository at this point in the history
… for pictureFormat (#16)

Co-authored-by: DaisukeHohjoh <dyhojo0816>
  • Loading branch information
DaisukeHohjoh authored Oct 19, 2023
1 parent 77d223f commit 7d58847
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THETA X Plug-in : Camera API Sample

Version: 1.3.1
Version: 1.4.0

This sample project shows how to implement a plug-in using Camera API for RICOH THETA X.
The program language is Kotlin, please checkout [java branch](https://github.com/ricohapi/theta-plugin-camera-api-sample-x/tree/java) to see Java code.
Expand Down Expand Up @@ -33,6 +33,7 @@ The program language is Kotlin, please checkout [java branch](https://github.com
> * ⑥ Spinner to choose RIC_SHOOTING_MODE for video mode
> * ⑦ Spinner to choose RIC_PROC_STITCHING
> * ⑧ Spinner to choose RIC_PROC_ZENITH_CORRECTION
> * ⑩ Spinner to choose ImageFormat.JPEG or ImageFormat.NV21 for image mode
> * Shutter Key : press to execute take picture ; same function as ②
> * Mode Key : long press to exit plug-in
Expand Down Expand Up @@ -78,7 +79,7 @@ The program language is Kotlin, please checkout [java branch](https://github.com
```gradle
dependencies {
...
implementation 'com.theta360:pluginlibrary:3.2.0'
implementation 'com.theta360:pluginlibrary:3.3.0'
...
}
```
Expand Down Expand Up @@ -252,6 +253,14 @@ The program language is Kotlin, please checkout [java branch](https://github.com
| RicPreview3840:2160 | 3840 | 2160 |
| RicPreview5760 | 5760 | 2880 |

### Capture Image as NV21 Format (available Version 2.30.0 or later)

* Image Format can be set to ImageFormat.NV21 with following.

```java
p.setPictureFormat(ImageFormat.NV21)
```


<a name="see_also"></a>
## See Also
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.theta360.sample.camera"
minSdkVersion 26
targetSdkVersion 29
versionCode 8
versionName "1.3.1"
versionCode 9
versionName "1.4.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand All @@ -35,7 +35,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.theta360:pluginlibrary:3.2.0'
implementation 'com.theta360:pluginlibrary:3.3.0'
//testImplementation 'junit:junit:4.+'
//androidTestImplementation 'com.android.support.test:runner:1.0.2'
//androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
26 changes: 22 additions & 4 deletions app/src/main/java/com/theta360/sample/camera/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theta360.sample.camera

import android.graphics.ImageFormat
import android.graphics.SurfaceTexture
import android.os.Bundle
import android.os.Handler
Expand Down Expand Up @@ -59,6 +60,8 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
private var isLongShutter: Boolean = false

private var isLowPowerPreview: Boolean = false
private var isNV21Available: Boolean = false
private var isJPEG: Boolean = true

private var mLcdBrightness: Int = 64
private var mLedPowerBrightness: IntArray = intArrayOf(0, 0, 0, 64) //(dummy,R,G,B)
Expand All @@ -85,6 +88,7 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
val spinner_ric_shooting_mode_video: Spinner = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_video)
val spinner_ric_proc_stitching: Spinner = findViewById<Spinner>(R.id.spinner_ric_proc_stitching)
val spinner_ric_proc_zenith_correction: Spinner = findViewById<Spinner>(R.id.spinner_ric_proc_zenith_correction)
val spinner_picture_format: Spinner = findViewById<Spinner>(R.id.spinner_picture_format)

//KeyCallback
setKeyCallback(object : KeyCallback {
Expand Down Expand Up @@ -155,6 +159,7 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
//firmware check
val version = ThetaInfo.getThetaFirmwareVersion().replace(".", "").toFloat()
isLowPowerPreview = if (version >= 1200) true else false //15fps preview available with fw1.20 or later
isNV21Available = if (version >= 2300) true else false //NV21 picture format available with fw2.30 or later

//Spinner : set Camera Parameters
setSpinner(spinner_ric_shooting_mode_preview, getResources().getStringArray(
Expand All @@ -165,6 +170,7 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
spinner_ric_shooting_mode_video.setSelection(1) //RicMovieRecording3840
spinner_ric_proc_stitching.setSelection(2) //RicDynamicStitchingAuto
spinner_ric_proc_zenith_correction.setSelection(1) //RicZenithCorrectionOnAuto
spinner_picture_format.setSelection(0) //ImageFormat.JPEG

//TextureView : show preview
val texture_view = findViewById<TextureView>(R.id.texture_view)
Expand Down Expand Up @@ -260,12 +266,13 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
return true
}

private fun getOutputMediaFile(): File? {
private fun getOutputMediaFile(isJPEG: Boolean): File? {
if (!setFolderPath()) {
return null
}
mFilepath = mPath + "PC" + SimpleDateFormat("HHmmss").format(Date()) + ".JPG"
Log.i(TAG, "JPEG file path = " + mFilepath)
mFilepath = mPath + "PC" + SimpleDateFormat("HHmmss").format(Date())
mFilepath += if(isJPEG) ".JPG" else ".NV21"
Log.i(TAG, "file path = " + mFilepath)
return File(mFilepath)
}

Expand Down Expand Up @@ -347,7 +354,7 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
},
Camera.PictureCallback{ data, _ ->
Log.i(TAG,"receive jpeg callback")
val pictureFile: File = getOutputMediaFile() ?: run {
val pictureFile: File = getOutputMediaFile(isJPEG) ?: run {
Log.e(TAG, "cannot create file")
return@PictureCallback
}
Expand Down Expand Up @@ -499,6 +506,8 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
val ric_shooting_mode_video: String = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_video).selectedItem.toString()
val ric_proc_stitching: String = findViewById<Spinner>(R.id.spinner_ric_proc_stitching).selectedItem.toString()
val ric_proc_zenith_correction: String = findViewById<Spinner>(R.id.spinner_ric_proc_zenith_correction).selectedItem.toString()
val picture_format: String = findViewById<Spinner>(R.id.spinner_picture_format).selectedItem.toString()
val picture_format_array: Array<String> = resources.getStringArray(R.array.PICTURE_FORMAT)

val p = mCamera!!.getParameters()
p.set(RIC_PROC_STITCHING, ric_proc_stitching)
Expand Down Expand Up @@ -529,6 +538,14 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
p.set(RIC_SHOOTING_MODE, ric_shooting_mode_image)
isMultiShot = if(ric_shooting_mode_image.equals("RicStillCaptureStd")) false else true
p.setPictureSize(11008, 5504) //11008*5504 or 5504*2752
if (picture_format == picture_format_array[0]) { //JPEG or NV21
p.pictureFormat = ImageFormat.JPEG
isJPEG = true
}
else {
p.pictureFormat = ImageFormat.NV21
isJPEG = false
}
}
MODE.VIDEO -> {
p.set(RIC_SHOOTING_MODE, ric_shooting_mode_video)
Expand Down Expand Up @@ -561,6 +578,7 @@ class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
findViewById<Spinner>(R.id.spinner_ric_shooting_mode_video).isEnabled = flag
findViewById<Spinner>(R.id.spinner_ric_proc_stitching).isEnabled = flag
findViewById<Spinner>(R.id.spinner_ric_proc_zenith_correction).isEnabled = flag
findViewById<Spinner>(R.id.spinner_picture_format).isEnabled = if (isNV21Available) flag else false
}

fun enableButton(button: Button, flag: Boolean) {
Expand Down
29 changes: 21 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_image"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_zenith_correction" />
app:layout_constraintTop_toBottomOf="@+id/spinner_picture_format" />

<Button
android:id="@+id/button_image"
Expand All @@ -38,7 +38,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/switch_camera"
app:layout_constraintStart_toEndOf="@+id/button_video"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_zenith_correction"
app:layout_constraintTop_toBottomOf="@+id/spinner_picture_format"
app:layout_constraintVertical_bias="0.50" />

<Button
Expand All @@ -54,14 +54,14 @@
app:layout_constraintEnd_toStartOf="@+id/button_image"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_zenith_correction" />
app:layout_constraintTop_toBottomOf="@+id/spinner_picture_format" />

<Spinner
android:id="@+id/spinner_ric_shooting_mode_preview"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
Expand All @@ -73,7 +73,7 @@
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:entries="@array/RIC_SHOOTING_MODE_IMAGE_ARRAY"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -86,7 +86,7 @@
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:entries="@array/RIC_SHOOTING_MODE_VIDEO_ARRAY"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -99,7 +99,7 @@
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:entries="@array/RIC_PROC_STITCHING_ARRAY"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -112,12 +112,25 @@
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:entries="@array/RIC_PROC_ZENITH_CORRECTION_ARRAY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_stitching" />

<Spinner
android:id="@+id/spinner_picture_format"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:entries="@array/PICTURE_FORMAT"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_zenith_correction" />

</android.support.constraint.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<item>RicZenithCorrectionOnAuto</item>
<item>RicZenithCorrectionOnManual</item>
</string-array>
<string-array name="PICTURE_FORMAT">
<item>ImageFormat.JPEG</item>
<item>ImageFormat.NV21</item>
</string-array>
<string name="start_video">START VIDEO</string>
<string name="stop_video">STOP VIDEO</string>
<string name="take_picture">TAKE PICTURE</string>
Expand Down
Binary file modified ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d58847

Please sign in to comment.