Skip to content

Commit

Permalink
[api]: Fix PixInsight Live Stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 7, 2024
1 parent 302c7ab commit 44066a0
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ data class CameraCaptureTask(
delayAndWaitForSettleSplitTask.close()
cameraExposureTask.close()
ditherAfterExposureTask.close()
liveStacker?.close()
super.close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,45 @@ data class PixInsightLiveStacker(
stacking.set(true)

// Calibrate.
val calibratedPath = if (dark == null && flat == null && bias == null) null else {
val calibrated = if (dark == null && flat == null && bias == null) false else {
PixInsightCalibrate(slot, workingDirectory, targetPath, dark, flat, if (dark == null) bias else null).use { s ->
val outputPath = s.runSync(runner).outputImage ?: return@use null
LOG.info("live stacking calibrated. count={}, image={}", stackCount, outputPath)
val outputPath = s.runSync(runner).outputImage ?: return@use false
LOG.info("live stacking calibrated. count={}, output={}", stackCount, outputPath)
outputPath.moveTo(calibratedPath, true)
true
}
}

if (calibratedPath != null) {
if (calibrated) {
targetPath = calibratedPath
}

// TODO: Debayer, Resample?

if (stackCount > 0) {
// Align.
val alignedPath = PixInsightAlign(slot, workingDirectory, referencePath, targetPath).use { s ->
val outputPath = s.runSync(runner).outputImage ?: return@use null
LOG.info("live stacking aligned. count={}, image={}", stackCount, alignedPath)
val aligned = PixInsightAlign(slot, workingDirectory, referencePath, targetPath).use { s ->
val outputPath = s.runSync(runner).outputImage ?: return@use false
LOG.info("live stacking aligned. count={}, output={}", stackCount, outputPath)
outputPath.moveTo(alignedPath, true)
true
}

if (alignedPath != null) {
if (aligned) {
targetPath = alignedPath
}

// Stack.
val expressionRK = "({{0}} * $stackCount + {{1}}) / ${stackCount + 1}"
PixInsightPixelMath(slot, listOf(stackedPath, targetPath), stackedPath, expressionRK).use { s ->
s.runSync(runner).stackedImage?.also {
LOG.info("live stacking finished. count={}, image={}", stackCount, it)
stackCount++
// Stack.
val expressionRK = "({{0}} * $stackCount + {{1}}) / ${stackCount + 1}"
PixInsightPixelMath(slot, listOf(stackedPath, targetPath), stackedPath, expressionRK).use { s ->
s.runSync(runner).stackedImage?.also {
LOG.info("live stacking finished. count={}, output={}", stackCount++, it)
}
}
}
} else {
targetPath.copyTo(referencePath, true)
targetPath.copyTo(stackedPath, true)
LOG.info("live stacking started. target={}, reference={}, stacked={}", targetPath, referencePath, stackedPath)
stackCount = 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractPixInsightScript<T> : PixInsightScript<T>, LineReadListen
final override fun startCommandLine(commandLine: CommandLine) {
commandLine.whenComplete { exitCode, exception ->
try {
LOG.info("PixInsight script finished. done={}, exitCode={}", isDone, exitCode, exception)
LOG.info("{} script finished. done={}, exitCode={}", this::class.simpleName, isDone, exitCode, exception)

waitOnComplete()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class PixInsightAlign(

override fun processOnComplete(exitCode: Int): Output {
if (exitCode == 0) {
repeat(5) {
repeat(30) {
val text = statusPath.readText()

if (text.startsWith(START_FILE) && text.endsWith(END_FILE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class PixInsightAutomaticBackgroundExtractor(

override fun processOnComplete(exitCode: Int): Output {
if (exitCode == 0) {
repeat(5) {
repeat(30) {
val text = statusPath.readText()

if (text.startsWith(START_FILE) && text.endsWith(END_FILE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data class PixInsightCalibrate(

override fun processOnComplete(exitCode: Int): Output {
if (exitCode == 0) {
repeat(5) {
repeat(30) {
val text = statusPath.readText()

if (text.startsWith(START_FILE) && text.endsWith(END_FILE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data class PixInsightPixelMath(

override fun processOnComplete(exitCode: Int): Output? {
if (exitCode == 0) {
repeat(5) {
repeat(30) {
val text = statusPath.readText()

if (text.startsWith(START_FILE) && text.endsWith(END_FILE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class PixInsightScriptRunner(private val executablePath: Path) {
DEFAULT_ARGS.forEach(::putArg)
}

LOG.info("running PixInsight script: {}", commandLine.command)
LOG.info("running {} script: {}", script::class.simpleName, commandLine.command)

script.startCommandLine(commandLine)
}
Expand Down

0 comments on commit 44066a0

Please sign in to comment.