Skip to content

Commit

Permalink
write c2pa metadata to a temp file which is copied back over the orig…
Browse files Browse the repository at this point in the history
…inal
  • Loading branch information
n8fr8 committed Nov 8, 2023
1 parent af966f2 commit 9be0f73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import android.util.Log
import okhttp3.internal.ignoreIoExceptions
import java.io.File
import org.proofmode.c2pa.C2paJNI
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException


class C2paUtils {

Expand Down Expand Up @@ -49,27 +51,43 @@ class C2paUtils {
filePath = _uri!!.path
}

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

if (fileMedia.exists()) {
//TODO add c2pa capture here
var identityId = _identityName
var identityUri = _identityUri

addContentCredentials(
_context,
identityId,
identityUri,
isDirectCapture,
allowMachineLearning,
fileMedia,
fileOut
)
if (filePath?.isNotEmpty() == true) {
var fileMedia = File(filePath)
var fileOut = File(_context.cacheDir, fileMedia.name);

if (fileMedia.exists()) {
//TODO add c2pa capture here
var identityId = _identityName
var identityUri = _identityUri

addContentCredentials(
_context,
identityId,
identityUri,
isDirectCapture,
allowMachineLearning,
fileMedia,
fileOut
)

copy(fileOut, fileMedia)
fileOut.delete()
}
}

}

@Throws(IOException::class)
fun copy(src: File?, dst: File?) {
val inStream = FileInputStream(src)
val outStream = FileOutputStream(dst)
val inChannel = inStream.channel
val outChannel = outStream.channel
inChannel.transferTo(0, inChannel.size(), outChannel)
inStream.close()
outStream.close()
}

fun addContentCredentials (_context: Context, _uri: Uri?, isDirectCapture: Boolean, allowMachineLearning: Boolean, fileOutDir: File) {

var filePath: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ class CameraFragment : BaseFragment<FragmentCameraBinding>(R.layout.fragment_cam
.setTargetRotation(rotation) // set the capture rotation
.build()


checkForHdrExtensionAvailability()

// The Configuration of image analyzing
Expand Down

0 comments on commit 9be0f73

Please sign in to comment.