Skip to content

Commit

Permalink
Added specific noise model, changed version
Browse files Browse the repository at this point in the history
  • Loading branch information
eszdman committed Sep 13, 2021
1 parent 053885c commit 57b182c
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
ndk {
abiFilters "arm64-v8a"
}
versionName '0.747'
versionName '0.8'
}

gradle.taskGraph.whenReady { taskGraph ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import com.particlesdevs.photoncamera.control.Gravity;
import com.particlesdevs.photoncamera.control.Gyro;
import com.particlesdevs.photoncamera.control.Vibration;
import com.particlesdevs.photoncamera.pro.SensorSpecifics;
import com.particlesdevs.photoncamera.pro.Specific;
import com.particlesdevs.photoncamera.pro.SpecificSetting;
import com.particlesdevs.photoncamera.pro.SupportedDevice;
import com.particlesdevs.photoncamera.processing.render.Parameters;
import com.particlesdevs.photoncamera.processing.render.PreviewParameters;
Expand Down Expand Up @@ -103,6 +105,10 @@ public static PreviewParameters getPreviewParameters() {
public static Specific getSpecific(){
return sPhotonCamera.mSupportedDevice.specific;
}
public static SensorSpecifics getSpecificSensor(){
return sPhotonCamera.mSupportedDevice.sensorSpecifics;
}


public static RenderScript getRenderScript() {
return sPhotonCamera.mRS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ public void openCamera(int width, int height) {
}

public void UpdateCameraCharacteristics(String cameraId) {
PhotonCamera.getSpecificSensor().selectSpecifics(Integer.parseInt(cameraId));
CameraCharacteristics characteristics = this.mCameraCharacteristicsMap.get(cameraId);
mCameraCharacteristics = characteristics;
//Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,89 @@

import android.os.Build;

import com.particlesdevs.photoncamera.settings.PreferenceKeys;
import com.particlesdevs.photoncamera.settings.SettingsManager;
import com.particlesdevs.photoncamera.util.HttpLoader;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;

public class SensorSpecifics {
public SpecificSettingSensor[] specificSettingSensor;
public SpecificSettingSensor selectedSensorSpecifics = null;
public SensorSpecifics(SettingsManager mSettingsManager){
int count = 1;
String device = Build.BRAND.toLowerCase() + "/" + Build.DEVICE.toLowerCase();
String fullSpec = "";
ArrayList<String> inputStr = new ArrayList<String>();
try {
BufferedReader indevice = HttpLoader.readURL("https://raw.githubusercontent.com/eszdman/PhotonCamera/dev/app/specific/sensors/" + device + ".txt");
String str;
count = 0;
while ((str = indevice.readLine()) != null) {
if(str.contains("sensor")) count++;
inputStr.add(str+"\n");
}
specificSettingSensor = new SpecificSettingSensor[count];
for (String str2 : inputStr) {
if(str2.contains("sensor")) count++;
inputStr.add(str2+"\n");
}
boolean loaded = mSettingsManager.getBoolean(PreferenceKeys.Key.DEVICES_PREFERENCE_FILE_NAME.mValue, "sensor_specific_loaded",false);
boolean exists = mSettingsManager.getBoolean(PreferenceKeys.Key.DEVICES_PREFERENCE_FILE_NAME.mValue, "sensor_specific_exists",true);

} catch (Exception ignored) {}
try {

}catch (Exception e){
if(exists) {
int count;
String device = Build.BRAND.toLowerCase() + "/" + Build.DEVICE.toLowerCase();
String fullSpec = "";
ArrayList<String> inputStr = new ArrayList<String>();
try {
exists = false;
BufferedReader indevice = HttpLoader.readURL("https://raw.githubusercontent.com/eszdman/PhotonCamera/dev/app/specific/sensors/" + device + ".txt");
String str;
count = 0;
while ((str = indevice.readLine()) != null) {
if (str.contains("sensor")) count++;
inputStr.add(str + "\n");
}
exists = true;
specificSettingSensor = new SpecificSettingSensor[count];
count = 1;
for (String str2 : inputStr) {
if (str2.contains("sensor")) {
String[] vals = str2.split("_");
specificSettingSensor[count].id = Integer.parseInt(vals[1]);
count++;
} else {
String[] valsIn = str2.split("=");
String[] istr = valsIn[1].replace("{", "").replace("}", "").split(",");
switch (valsIn[0]) {
case "NoiseModelA": {
for (int i = 0; i < 4; i++) {
specificSettingSensor[count - 1].NoiseModelerArr[0][i] = Double.parseDouble(istr[i]);
}
break;
}
case "NoiseModelB": {
for (int i = 0; i < 4; i++) {
specificSettingSensor[count - 1].NoiseModelerArr[1][i] = Double.parseDouble(istr[i]);
}
break;
}
case "NoiseModelC": {
for (int i = 0; i < 4; i++) {
specificSettingSensor[count - 1].NoiseModelerArr[2][i] = Double.parseDouble(istr[i]);
}
break;
}
case "NoiseModelD": {
for (int i = 0; i < 4; i++) {
specificSettingSensor[count - 1].NoiseModelerArr[3][i] = Double.parseDouble(istr[i]);
}
specificSettingSensor[count - 1].ModelerExists = true;
break;
}
}
loaded = true;
}
}

} catch (Exception ignored) {
}
mSettingsManager.set(PreferenceKeys.Key.DEVICES_PREFERENCE_FILE_NAME.mValue, "sensor_specific_loaded", loaded);
mSettingsManager.set(PreferenceKeys.Key.DEVICES_PREFERENCE_FILE_NAME.mValue, "sensor_specific_exists", exists);
}
}
public SpecificSettingSensor selectSpecifics(int id){
if(specificSettingSensor != null) {
for (SpecificSettingSensor specifics : specificSettingSensor) {
if (specifics.id == id) return specifics;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.particlesdevs.photoncamera.pro;

import com.particlesdevs.photoncamera.processing.render.NoiseModeler;

//Device current sensor specific
public class SpecificSettingSensor {
public int id = 0;
public boolean isRawColorCorrection = false;
public float[] blackLevel;
public float[][] CCT;
public float[][] NoiseModeler;
public double[][] NoiseModelerArr;
public boolean ModelerExists = false;
public boolean CCTExists = false;
public SpecificSettingSensor(){
NoiseModelerArr = new double[4][4];
CCT = new float[3][3];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.util.Log;
import android.util.Pair;

import com.particlesdevs.photoncamera.pro.SpecificSettingSensor;
import com.particlesdevs.photoncamera.processing.parameters.FrameNumberSelector;

public class NoiseModeler {
Expand All @@ -11,16 +12,34 @@ public class NoiseModeler {
public Pair<Double,Double>[] computeModel;
public int AnalogueISO;
public int SensivityISO;
public NoiseModeler(Pair<Double,Double>[] inModel,Integer analogISO,Integer ISO, int bayer) {
public NoiseModeler(Pair<Double,Double>[] inModel, Integer analogISO, Integer ISO, int bayer, SpecificSettingSensor specificSettingSensor) {
AnalogueISO = analogISO;
SensivityISO = ISO;
baseModel = new Pair[3];
computeModel = new Pair[3];
//inModel = null;
if (inModel == null || inModel.length == 0) {
Pair<Double, Double> Imx363sGenerator = new Pair<>(0.0000025720647, 0.000028855721);
Pair<Double, Double> Imx363oGenerator = new Pair<>(0.000000000039798506, 0.000000046578279);
Pair<Double,Double> computedModel = new Pair<>(computeNoiseModelS(ISO,Imx363sGenerator),computeNoiseModelO(ISO,Imx363oGenerator));
if (inModel == null || inModel.length == 0 || specificSettingSensor != null) {
Pair<Double, Double> CustomGeneratorS;
Pair<Double, Double> CustomGeneratorO;
if(specificSettingSensor != null) {
double[] avrdouble = new double[4];
for (double[] ind : specificSettingSensor.NoiseModelerArr) {
avrdouble[0] += ind[0];
avrdouble[1] += ind[1];
avrdouble[2] += ind[2];
avrdouble[3] += ind[3];
}
avrdouble[0] /= 4.0;
avrdouble[1] /= 4.0;
avrdouble[2] /= 4.0;
avrdouble[3] /= 4.0;
CustomGeneratorS = new Pair<>(avrdouble[0], avrdouble[1]);
CustomGeneratorO = new Pair<>(avrdouble[2], avrdouble[3]);
} else {
CustomGeneratorS = new Pair<>(0.0000025720647, 0.000028855721);
CustomGeneratorO = new Pair<>(0.000000000039798506, 0.000000046578279);
}
Pair<Double,Double> computedModel = new Pair<>(computeNoiseModelS(ISO,CustomGeneratorS),computeNoiseModelO(ISO,CustomGeneratorO));
//Test
/*
Pair<Double, Double> TestsGenerator = new Pair<>(1.0798706869238175e-06, -8.618818353621416e-06);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.particlesdevs.photoncamera.app.PhotonCamera;
import com.particlesdevs.photoncamera.control.GyroBurst;
import com.particlesdevs.photoncamera.pro.SensorSpecifics;
import com.particlesdevs.photoncamera.pro.SpecificSettingSensor;
import com.particlesdevs.photoncamera.processing.parameters.FrameNumberSelector;
import com.particlesdevs.photoncamera.settings.PreferenceKeys;
import com.particlesdevs.photoncamera.capture.CaptureController;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class Parameters {
public double YPerMm;
public double[] cameraIntrinsic = new double[9];
public double[] cameraIntrinsicRev = new double[9];
public SpecificSettingSensor sensorSpecifics;



Expand Down Expand Up @@ -123,7 +126,8 @@ public void FillConstParameters(CameraCharacteristics characteristics, Point siz
}

public void FillDynamicParameters(CaptureResult result) {
noiseModeler = new NoiseModeler( result.get(CaptureResult.SENSOR_NOISE_PROFILE),analogIso,result.get(CaptureResult.SENSOR_SENSITIVITY),cfaPattern);
sensorSpecifics = PhotonCamera.getSpecificSensor().selectedSensorSpecifics;
noiseModeler = new NoiseModeler( result.get(CaptureResult.SENSOR_NOISE_PROFILE),analogIso,result.get(CaptureResult.SENSOR_SENSITIVITY),cfaPattern,sensorSpecifics);
int[] blarr = new int[4];
BlackLevelPattern level = CaptureController.mCameraCharacteristics.get(CameraCharacteristics.SENSOR_BLACK_LEVEL_PATTERN);
if (result != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void FillParameters(CaptureResult result, CameraCharacteristics character
}
}
public void FillDynamicParameters(CaptureResult result) {
noiseModeler = new NoiseModeler( result.get(CaptureResult.SENSOR_NOISE_PROFILE),analogIso,result.get(CaptureResult.SENSOR_SENSITIVITY),cfaPattern);
noiseModeler = new NoiseModeler( result.get(CaptureResult.SENSOR_NOISE_PROFILE),analogIso,result.get(CaptureResult.SENSOR_SENSITIVITY),cfaPattern,null);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ public void onClick(View view) {
case R.id.flip_camera_button:
view.animate().rotationBy(180).setDuration(450).start();
textureView.animate().rotationBy(360).setDuration(450).start();
PreferenceKeys.setCameraID(cycler(PreferenceKeys.getCameraID()));
//PreferenceKeys.setCameraID(cycler(PreferenceKeys.getCameraID()));
setID(cycler(PreferenceKeys.getCameraID()));
this.restartCamera();
break;
case R.id.grid_toggle_button:
Expand Down Expand Up @@ -1087,11 +1088,14 @@ private void resetTimer() {
@Override
public void onAuxButtonClicked(String id) {
Log.d(TAG, "onAuxButtonClicked() called with: id = [" + id + "]");
PreferenceKeys.setCameraID(String.valueOf(id));
setID(id);
this.restartCamera();

}

private void setID(String input){
PreferenceKeys.setCameraID(String.valueOf(input));
}
@Override
public void onCameraModeChanged(CameraMode cameraMode) {
PreferenceKeys.setCameraModeOrdinal(cameraMode.ordinal());
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Sep 13 02:00:31 MSK 2021
VERSION_BUILD=12378
#Mon Sep 13 04:16:14 MSK 2021
VERSION_BUILD=12382

0 comments on commit 57b182c

Please sign in to comment.