Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAM palette over-optimized, muddied, etc. #1

Open
BardezAnAvatar opened this issue Jan 16, 2024 · 0 comments
Open

BAM palette over-optimized, muddied, etc. #1

BardezAnAvatar opened this issue Jan 16, 2024 · 0 comments

Comments

@BardezAnAvatar
Copy link

BardezAnAvatar commented Jan 16, 2024

Using the following images:

42 (busted) 43 (works)
critical_spell-42 critical_spell-43

combined with either of these:

Arcane Priest
A P

I will get inconsistent results between my BAM results (as observed and screencapped from Near Infinity):

iteration Rolled Unrolled
42 (busted) result_42_a result_42_b
43 (works) result_43_a result_43_b

BAM files generated:
intermediate.zip

I generate the BAMs with the following PowerShell script:

<#
.SYNOPSIS
    This script will mix Infinity Engine scroll PNG files into best-compression BAM files
.DESCRIPTION
    This script will run through an input directory, joining `RolledFrame` and individual *.png files in `DirInputPng` via `Bammer`, which will be output to `DirOutputTemp`. Subsequently, all such *.BAM files will be iterated over in `DirOutputTemp` and compressed via `PsBam` executable and emitted into the `DirOutputBam` directory
.PARAMETER Bammer
    The path to the `Bammer` executable on disk.
    Acquire from: https://www.gibberlings3.net/forums/topic/34567-using-bammer-to-create-and-edit-bams/#comment-305963
.PARAMETER PsBam
    The path to the `PS BAM` executable on disk.
    Acquire from: https://github.com/Sampsca/PS-BAM
.PARAMETER RolledFrame
    The path to the PNG file on disk of a rolled-up scroll (the picked up frame in a scroll BAM)
.PARAMETER DirInputPng
    The path to the directory containing all of the PNG files to convert into BAMs
.PARAMETER DirOutputTemp
    The path to the directory where intermediate uncompressed BAMs can be stored
.PARAMETER DirOutputBam
    The path to the directory where final output should reside
.EXAMPLE
    C:\Work\BAM>'.\scroll_bam_generation.ps1'
    >>> -Bammer 'C:\bin\bammer\bammer.exe'
    >>> -PsBam 'C:\bin\psbam\psbam.exe'
    >>> -RolledFrame 'C:\Work\Bam\Input\RolledScroll.png'
    >>> -DirInputPng 'C:\Work\Bam\Input\Todo\'
    >>> -DirOutputTemp 'C:\Work\Bam\Temp\'
    >>> -DirOutputBam 'C:\Work\Bam\Output\'
    <This will open up all the *.png files in -DirInputPng, create a BAM for them using the bammer executable, then compress that BAM
    using PS BAM>
.NOTES
    Author: Bardez
    Date:   December 26, 2023
#>
param(
    [Parameter(Mandatory)]
    [string]$Bammer,

    [Parameter(Mandatory)]
    [string]$PsBam,

    [Parameter(Mandatory)]
    [string]$RolledFrame,

    [Parameter(Mandatory)]
    [string]$DirInputPng,

    [Parameter(Mandatory)]
    [string]$DirOutputTemp,

    [Parameter(Mandatory)]
    [string]$DirOutputBam
)


# this function will generate BAM-D input/output
Function GenerateBamD
{
    param(
        [Parameter(Mandatory)]
        [string]$RolledFrame,

        [Parameter(Mandatory)]
        [string]$SpellFrame,

        [Parameter(Mandatory)]
        [string]$RolledCenterX,

        [Parameter(Mandatory)]
        [string]$RolledCenterY
    )

    $bamd =@"
frame f00000 `"$RolledFrame`" $RolledCenterX $RolledCenterY
frame f00001 `"$SpellFrame`" 0 0

sequence f00000 f00001
"@

    return $bamd
}

Function GenerateBam
{
    param(
        [Parameter(Mandatory)]
        [string]$PathBammer,

        [Parameter(Mandatory)]
        [string]$DirOutput,

        [Parameter(Mandatory)]
        [string]$RolledFrame,

        [Parameter(Mandatory)]
        [string]$SpellFrame,

        [Parameter(Mandatory)]
        [string]$BamName
    )

    #Get the BAM-D content
    $bamd = GenerateBamD $RolledFrame $SpellFrame 20 15
    $bamd = $bamd.Replace("\", "/") #apparently Bammer needs this syntax?

    #Write the file
    Set-Content -Path "$DirOutput\temp.bamd" -Value $bamd

    #Invoke Bammer
    $params = @(
        "-input", "`"$DirOutput\temp.bamd`"",
        "-output", "`"$DirOutput\$BamName`""
        )
    & $PathBammer $params
}

#this function will take a file in the temp dir and compress it using PS-BAM
Function CompressBam
{
    param(
        [Parameter(Mandatory)]
        [string]$PathPsBam,

        [Parameter(Mandatory)]
        [string]$DirInput,

        [Parameter(Mandatory)]
        [string]$DirOutput,

        [Parameter(Mandatory)]
        [string]$BamName
    )

    #invoke PS-BAM
    $params = @(
        "--CompressionProfile", "`"Recommended`"",
        "--DebugLevelL", "1",
        "--DebugLevelP", "2",
        "--DebugLevelS", "1",
        "--LogFile", "`"$DirOutput\$BamName.log`"",
        "--OutPath", "`"$DirOutput`"",
        "--Save", "`"BAM`"",
        "`"$DirInput\$BamName`""
        )
    & $PathPsBam $params
}

Function Main
{
    $start = Get-Date

    Write-Host "Generating BAMs ..." -ForegroundColor red

    #iterate through all of the input DIR PNGs
    $pngFiles = Get-ChildItem $DirInputPng -Filter *.png
    foreach ($file in $pngFiles)
    {
        $bamName = "$($file.Basename).BAM"

        Write-Host "Generating $bamName from $file ..." -ForegroundColor blue
        #generate BAM
        GenerateBam -PathBammer $Bammer -DirOutput $DirOutputTemp -RolledFrame $RolledFrame -SpellFrame $file.FullName -BamName $bamName
    }

    Write-Host "Optimizing BAMs ..." -ForegroundColor red

    #iterate through all temp dir BAMs
    $bamFiles = Get-ChildItem $DirOutputTemp | Where-Object { $_.Name -like "*.BAM" -and $_.Name -notlike "*.bamd" }
    foreach($file in $bamFiles)
    {
        Write-Host "Optimizing $bamName ..." -ForegroundColor Magenta
        #compress BAM
        CompressBam -PathPsBam $PsBam -DirInput $DirOutputTemp -DirOutput $DirOutputBam -BamName $file.Name

        #this locked up my processor and OS, so... WAIT
        Start-Sleep -Milliseconds 20
    }

    $end = Get-Date

    $duration = $end - $start

    Write-Host "Script duration: $duration ..." -ForegroundColor Yellow
}

Main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant