Skip to content

Commit

Permalink
Prefer immutable IndexedSeq over mutable Array
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsacha committed Sep 24, 2023
1 parent 412e7f5 commit fa9fdc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Image/J Plugins
* Copyright (C) 2002-2022 Jarek Sacha
* Copyright (C) 2002-2023 Jarek Sacha
* Author's email: jpsacha at gmail dot com
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -116,7 +116,7 @@ object CalibrateTask {

private def showScatterChart(x: IndexedSeq[IndexedSeq[Double]],
y: IndexedSeq[IndexedSeq[Double]],
seriesLabels: Array[String],
seriesLabels: IndexedSeq[String],
chartTitle: String
): Unit = {

Expand Down Expand Up @@ -213,7 +213,7 @@ class CalibrateTask(
correctionOutputLR.foreach { co =>
val titlePrefix = s"${image.getTitle} - ${colorCalibrator.referenceColorSpace}+${colorCalibrator.mappingMethod}"
val chips: Seq[ColorChip] = chart.referenceChipsEnabled
val bands: Array[String] = recipe.referenceColorSpace.bandsNames
val bands: IndexedSeq[String] = recipe.referenceColorSpace.bandsNames

co.correctedInSRGB.foreach { imp =>
imp.setTitle(s"$titlePrefix - sRGB")
Expand Down Expand Up @@ -242,13 +242,13 @@ class CalibrateTask(
showColorErrorChart(
fit.reference,
fit.corrected,
chips.map(_.name).toArray,
chips.map(_.name),
referenceColorSpace().bandsNames,
titlePrefix
)

if (outputConfig.tableExpectedVsCorrected)
showExpectedVsCorrected(chips: Seq[ColorChip], bands: Array[String], fit, titlePrefix)
showExpectedVsCorrected(chips: Seq[ColorChip], bands, fit, titlePrefix)

if (outputConfig.tableRegressionResults)
showTableWithRegressionResults(bands, fit, s"$titlePrefix - Regression Coefficients")
Expand All @@ -275,7 +275,7 @@ class CalibrateTask(

private def showExpectedVsCorrected(
chips: Seq[ColorChip],
bands: Array[String],
bands: IndexedSeq[String],
fit: ColorCalibrator.CalibrationFit,
titlePrefix: String
): Unit = {
Expand Down Expand Up @@ -304,7 +304,7 @@ class CalibrateTask(
}

private def showTableWithRegressionResults(
bands: Array[String],
bands: IndexedSeq[String],
fit: ColorCalibrator.CalibrationFit,
title: String
): Unit = {
Expand Down Expand Up @@ -432,8 +432,8 @@ class CalibrateTask(

private def showColorErrorChart(x: IndexedSeq[IndexedSeq[Double]],
y: IndexedSeq[IndexedSeq[Double]],
columnNames: Array[String],
seriesLabels: Array[String],
columnNames: Seq[String],
seriesLabels: IndexedSeq[String],
titlePrefix: String
): Unit = {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Image/J Plugins
* Copyright (C) 2002-2022 Jarek Sacha
* Copyright (C) 2002-2023 Jarek Sacha
* Author's email: jpsacha at gmail dot com
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -36,17 +36,16 @@ object ReferenceColorSpace extends WithNameCompanion[ReferenceColorSpace]
* Note that for proper correction to L*a*b* you need to keep track of the reference white (illuminant) of the reference
* color values.
*/
enum ReferenceColorSpace(val name: String, bands: Array[String]) extends WithName {
enum ReferenceColorSpace(val name: String, val bands: IndexedSeq[String]) extends WithName {

/** CIE XYZ color space */
case XYZ extends ReferenceColorSpace("XYZ", Array("X", "Y", "Z"))
case XYZ extends ReferenceColorSpace("XYZ", IndexedSeq("X", "Y", "Z"))

/** sRGB color space */
case sRGB extends ReferenceColorSpace("sRGB", Array("Red", "Green", "Blue"))
case sRGB extends ReferenceColorSpace("sRGB", IndexedSeq("Red", "Green", "Blue"))

private val _bands: Array[String] = bands.clone()

def bandsNames: Array[String] = _bands.clone()
def bandsNames: IndexedSeq[String] = bands

/**
* Convert color value from the current color space to CIE L*a*b*
Expand Down

0 comments on commit fa9fdc4

Please sign in to comment.