In short, I'm passing an argument to a method, assigning the output of the method to a different variable, and later reference the original argument, only to find that it's value has changed!
Here I have the relevant portion of the main fragment which creates the original variable. It's logtag is QF:
Log.d("QF",""+ roiRGB[0]);
double[] lab = MathUtils.rgbTOlab(roiRGB, refRGB);
Log.d("QF",""+ roiRGB[0]);
Within MathUtils, rgbTOlab looks like this:
public static double[] rgbTOlab(double[] roi, double[] ref){
double[] newroi = roi;
Log.d("rgbTOlab", roi[0] + " vs " + newroi[0]);
newroi = rgbTOxyz(newroi);
Log.d("rgbTOlab", roi[0] + " vs " + newroi[0]);
...
And rgbTOxyz looks like this:
public static double[] rgbTOxyz(double[] rgb)
{ // RGB input values must be normalized to 0..1
Log.d("rgbTOxyz",rgb[0]+"");
double[] newrgb = rgb;
Log.d("rgbTOxyz",rgb[0]+ " vs " + newrgb[0]);
// Convert RGB values to sRGB ("standard" RGB)
for (int i=0;i<3;i++) {
if (rgb[i] <= 0.04045) {
rgb[i] = rgb[i] / 12.92;
} else {
rgb[i] = Math.pow((rgb[i] + 0.055) / 1.055, 2.4);
}
rgb[i] = rgb[i] * 100;
}
Log.d("rgbTOxyz",rgb[0]+" vs " + newrgb[0]);
...
And here's the logcat:
05-28 19:42:29.961 D/QF﹕ 0.16626617647060205
05-28 19:42:29.962 D/rgbTOlab﹕ 0.16626617647060205 vs 0.16626617647060205
05-28 19:42:29.962 D/rgbTOxyz﹕ 0.16626617647060205
05-28 19:42:29.962 D/rgbTOxyz﹕ 0.16626617647060205 vs 0.16626617647060205
05-28 19:42:29.962 D/rgbTOxyz﹕ 2.354995989041693 vs 2.354995989041693
05-28 19:42:29.962 D/rgbTOlab﹕ 2.354995989041693 vs 2.036417989802886
05-28 19:42:29.962 D/QF﹕ 2.354995989041693
The value of rgb[0] should never change, I need it to be the same before and after that method call. Yet clearly the original argument is getting altered even though I'm never manipulating it or returning it. Any ideas on why this is happening, and how I can fix it? I'm at a total loss, any help is very much appreciated.