Skip to content

Commit

Permalink
update to support optional use of c2pa features
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Nov 7, 2023
1 parent b858e6b commit 5678bce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package org.witness.proofmode.camera

import android.os.Bundle
import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity
import org.witness.proofmode.camera.c2pa.C2paUtils
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.IDENTITY_NAME_KEY
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.IDENTITY_URI_KEY

class CameraActivity : AppCompatActivity(){


private val PREF_OPTION_AI = "blockAI"

private val PREF_OPTION_CREDENTIALS = "addCR"

var useCredentials = true
var useAIFlag = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.camera_main)

//set identity based on passed strings
C2paUtils.setC2PAIdentity(intent.getStringExtra(IDENTITY_NAME_KEY),intent.getStringExtra(IDENTITY_URI_KEY))
useCredentials = intent.getBooleanExtra(PREF_OPTION_CREDENTIALS, true)
useAIFlag = intent.getBooleanExtra(PREF_OPTION_AI, true)

if (useCredentials) {
//set identity based on passed strings
C2paUtils.setC2PAIdentity(
intent.getStringExtra(IDENTITY_NAME_KEY),
intent.getStringExtra(IDENTITY_URI_KEY)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class C2paUtils {
var _identityUri = "ProofMode@https://proofmode.org"
var _identityName = "ProofMode"

const val IDENTITY_URI_KEY = "ProofMode@https://proofmode.org"
const val IDENTITY_NAME_KEY = "ProofMode"
const val IDENTITY_URI_KEY = "id_uri"
const val IDENTITY_NAME_KEY = "id_name"

fun setC2PAIdentity (identityName: String?, identityUri: String?)
{
if (identityName != null) {
_identityUri = identityName
_identityName = identityName
}
if (identityUri != null) {
_identityName = identityUri
_identityUri = identityUri
}
}

Expand All @@ -50,6 +50,7 @@ class C2paUtils {
}

var fileMedia = File(filePath)
var fileOut = File(_context.filesDir, "c2pa-" + fileMedia.name);

if (fileMedia.exists()) {
//TODO add c2pa capture here
Expand All @@ -63,7 +64,7 @@ class C2paUtils {
isDirectCapture,
allowMachineLearning,
fileMedia,
fileMedia
fileOut
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import coil.transform.CircleCropTransformation
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.witness.proofmode.camera.CameraActivity
import org.witness.proofmode.camera.R
import org.witness.proofmode.camera.analyzer.LuminosityAnalyzer
import org.witness.proofmode.camera.c2pa.C2paUtils
Expand Down Expand Up @@ -640,10 +641,19 @@ class CameraFragment : BaseFragment<FragmentCameraBinding>(R.layout.fragment_cam
object : OnImageSavedCallback { // the callback, about the result of capture process
override fun onImageSaved(outputFileResults: OutputFileResults) {

var isDirectCapture = true; //this is from our camera
var allowMachineLearning = false; //by default, we flag to not allow

C2paUtils.addContentCredentials(requireContext(), outputFileResults.savedUri, isDirectCapture, allowMachineLearning)
if ((activity as CameraActivity).useCredentials) {

var isDirectCapture = true; //this is from our camera
var allowMachineLearning = (activity as CameraActivity).useAIFlag; //by default, we flag to not allow

C2paUtils.addContentCredentials(
requireContext(),
outputFileResults.savedUri,
isDirectCapture,
allowMachineLearning
)
}

// This function is called if capture is successfully completed
outputFileResults.savedUri
Expand Down

0 comments on commit 5678bce

Please sign in to comment.