Skip to content

Commit

Permalink
[api]: Fix invalid parameter encoding; Handle error on PixInsight scr…
Browse files Browse the repository at this point in the history
…ipts
  • Loading branch information
tiagohm committed Jun 7, 2024
1 parent f84e15d commit 9ec66ec
Show file tree
Hide file tree
Showing 11 changed files with 1,125 additions and 1,082 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractPixInsightScript<T> : PixInsightScript<T>, LineReadListen

if (isDone) return@whenComplete
else if (exception != null) completeExceptionally(exception)
else complete(processOnComplete(exitCode))
else complete(processOnComplete(exitCode).also { LOG.info("script processed. output={}", it) })
} finally {
commandLine.unregisterLineReadListener(this)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ abstract class AbstractPixInsightScript<T> : PixInsightScript<T>, LineReadListen
when (data) {
is Path, is CharSequence -> append("'$data'")
is Number -> append("$data")
else -> append(Hex.encodeHexString(OBJECT_MAPPER.writeValueAsBytes(data)))
else -> append(Hex.encodeHexString(OBJECT_MAPPER.writeValueAsString(data).toByteArray(Charsets.UTF_16BE)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ data class PixInsightAlign(
)

data class Output(
@JvmField val success: Boolean = false,
@JvmField val errorMessage: String? = null,
@JvmField val outputImage: Path? = null,
@JvmField val outputMaskImage: Path? = null,
@JvmField val totalPairMatches: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ data class PixInsightAutomaticBackgroundExtractor(
@JvmField val statusPath: Path,
)

data class Output(@JvmField val outputImage: Path? = null) {
data class Output(
@JvmField val success: Boolean = false,
@JvmField val errorMessage: String? = null,
@JvmField val outputImage: Path? = null,
) {

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ data class PixInsightCalibrate(
)

data class Output(
@JvmField val success: Boolean = false,
@JvmField val errorMessage: String? = null,
@JvmField val outputImage: Path? = null,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ data class PixInsightDetectStars(
)

data class Output(
@JvmField val success: Boolean = false,
@JvmField val errorMessage: String? = null,
@JvmField val stars: List<Star> = emptyList(),
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ data class PixInsightPixelMath(
)

data class Output(
@JvmField val success: Boolean = false,
@JvmField val errorMessage: String? = null,
@JvmField val stackedImage: Path? = null,
) {

Expand Down
98 changes: 54 additions & 44 deletions nebulosa-pixinsight/src/main/resources/pixinsight/ABE.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,74 @@
function decodeParams(hex) {
let decoded = ''
const buffer = new Uint8Array(hex.length / 4)

for (let i = 0; i < hex.length; i += 2) {
decoded += String.fromCharCode(parseInt(hex.substr(i, 2), 16))
for (let i = 0; i < hex.length; i += 4) {
buffer[i / 4] = parseInt(hex.substr(i, 4), 16)
}

return JSON.parse(decoded)
return JSON.parse(String.fromCharCode.apply(null, buffer))
}

function abe() {
const input = decodeParams(jsArguments[0])
const data = {
success: true,
errorMessage: null,
outputImage: null,
}

const targetPath = input.targetPath
const outputPath = input.outputPath
const statusPath = input.statusPath
try {
const input = decodeParams(jsArguments[0])

console.writeln("targetPath=" + targetPath)
console.writeln("outputPath=" + outputPath)
console.writeln("statusPath=" + statusPath)
const targetPath = input.targetPath
const outputPath = input.outputPath
const statusPath = input.statusPath

const window = ImageWindow.open(targetPath)[0]
console.writeln("targetPath=" + targetPath)
console.writeln("outputPath=" + outputPath)
console.writeln("statusPath=" + statusPath)

const P = new AutomaticBackgroundExtractor
P.tolerance = 1.000
P.deviation = 0.800
P.unbalance = 1.800
P.minBoxFraction = 0.050
P.maxBackground = 1.0000
P.minBackground = 0.0000
P.useBrightnessLimits = false
P.polyDegree = 4
P.boxSize = 5
P.boxSeparation = 5
P.modelImageSampleFormat = AutomaticBackgroundExtractor.prototype.f32
P.abeDownsample = 2.00
P.writeSampleBoxes = false
P.justTrySamples = false
P.targetCorrection = AutomaticBackgroundExtractor.prototype.Subtract
P.normalize = true
P.discardModel = true
P.replaceTarget = true
P.correctedImageId = ""
P.correctedImageSampleFormat = AutomaticBackgroundExtractor.prototype.SameAsTarget
P.verboseCoefficients = false
P.compareModel = false
P.compareFactor = 10.00
const window = ImageWindow.open(targetPath)[0]

P.executeOn(window.mainView)
const P = new AutomaticBackgroundExtractor
P.tolerance = 1.000
P.deviation = 0.800
P.unbalance = 1.800
P.minBoxFraction = 0.050
P.maxBackground = 1.0000
P.minBackground = 0.0000
P.useBrightnessLimits = false
P.polyDegree = 4
P.boxSize = 5
P.boxSeparation = 5
P.modelImageSampleFormat = AutomaticBackgroundExtractor.prototype.f32
P.abeDownsample = 2.00
P.writeSampleBoxes = false
P.justTrySamples = false
P.targetCorrection = AutomaticBackgroundExtractor.prototype.Subtract
P.normalize = true
P.discardModel = true
P.replaceTarget = true
P.correctedImageId = ""
P.correctedImageSampleFormat = AutomaticBackgroundExtractor.prototype.SameAsTarget
P.verboseCoefficients = false
P.compareModel = false
P.compareFactor = 10.00

window.saveAs(outputPath, false, false, false, false)
P.executeOn(window.mainView)

window.forceClose()
window.saveAs(outputPath, false, false, false, false)

console.writeln("abe finished")
window.forceClose()

const json = {
outputImage: outputPath,
}
data.outputImage = outputPath

File.writeTextFile(statusPath, "@" + JSON.stringify(json) + "#")
console.writeln("abe finished")
} catch (e) {
data.success = false
data.errorMessage = e.message
console.writeln(data.errorMessage)
} finally {
File.writeTextFile(statusPath, "@" + JSON.stringify(data) + "#")
}
}

abe()
Loading

0 comments on commit 9ec66ec

Please sign in to comment.