Examples

Convert KoalaPainter image to FacePainter format:

import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.Format.FacePainter
import org.c64.attitude.Afterimage.Mode.MultiColour

val picture = File.load("images/image.kla")

FacePainter(picture.asInstanceOf[MultiColour]).save("images/image.fcp")

Preview Art Studio image:

import org.c64.attitude.Afterimage.Colour.Palette
import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.View.Image

val picture = File.load("images/image.aas")
val palette = Palette("default")
val image = Image(picture, palette)

image.show()

Save Advanced Art Studio image to PNG file:

import org.c64.attitude.Afterimage.Colour.Palette
import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.File.Type.PNG
import org.c64.attitude.Afterimage.View.Image

val picture = File.load("images/image.ocp")
val palette = Palette("default")
val image = Image(picture, palette)

PNG(image).save("images/image.png")

Serialize first data row of a HiRes Bitmap image to a sequence of byte values:

import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.Mode.HiRes

val picture = File.load("images/image.hpi").asInstanceOf[HiRes]
val values = picture.rows(0).serialize()

Deserialize the sequence of byte values into row data of a HiRes Bitmap image:

import org.c64.attitude.Afterimage.Mode.Data.Row.HiResRow

val row = HiResRow.inflate(values)

Generate dreamass-compatible source code string with HiRes image row data:

val sourceCode = row.toCode("image_row_data_01")

Import 320×200 pixels PNG file and convert image data directly to HiRes mode:

import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.File.Import.HiRes

val picture = File.convert(
  "images/image.png",
  HiRes()
)

Import 320×200 pixels JPEG file and convert image data directly to MultiColour mode:

import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.File.Import.MultiColour

val picture = File.convert(
  "images/image.jpg",
  MultiColour(backgroundColour = 0x00)
)

Using Afterimage as a standalone library is possible, given that all required dependencies are provided on a classpath. In the following example three PNG pictures named image-0.png, image-1.png and image-2.png are converted into three FacePainter images named 0.fcp, 1.fcp and 2.fcp using a simple Scala script:

import org.c64.attitude.Afterimage.Colour.Palette
import org.c64.attitude.Afterimage.File.File
import org.c64.attitude.Afterimage.File.Import
import org.c64.attitude.Afterimage.Format.FacePainter
import org.c64.attitude.Afterimage.Mode

val palette = Palette("default")

List("0", "1", "2").foreach { num => {
  val importMode = Import.MultiColour(backgroundColour = 0x01, palette)
  val picture = File.convert("image-" + num + ".png", importMode)
  FacePainter(picture.asInstanceOf[Mode.MultiColour]).save(num + ".fcp")
} }

Assuming an above script has been saved into a convert.scala file, it can be executed using the following command(s):

$ export AFTERIMAGE=/home/pkrol/.ivy2/cache/org.c64.attitude/afterimage/jars/afterimage-0.04.jar 
$ export IMAGEJ=/home/pkrol/.ivy2/cache/gov.nih.imagej/imagej/jars/imagej-1.47.jar 
$ export JSON_4S=/home/pkrol/.ivy2/cache/org.json4s/json4s-ast_2.12/jars/json4s-ast_2.12-3.5.0.jar:/home/pkrol/.ivy2/cache/org.json4s/json4s-core_2.12/jars/json4s-core_2.12-3.5.0.jar:/home/pkrol/.ivy2/cache/org.json4s/json4s-native_2.12/jars/json4s-native_2.12-3.5.0.jar 
$ scala -classpath $AFTERIMAGE:$IMAGEJ:$JSON_4S convert.scala

Applying a customized color palette is accomplished by specifying a JSON configuration file name as a Pallete parameter instead of a predefined template name:

import org.c64.attitude.Afterimage.Colour.Palette

val palette = Palette("custom-palette.json")

Color palette is expected to be a text file defined in a JSON format along the following lines:

{
    "palette": [
        { "red": 0,   "green": 0,   "blue": 0,   "name": "black"       },
        { "red": 255, "green": 255, "blue": 255, "name": "white"       },
        { "red": 104, "green": 55,  "blue": 43,  "name": "red"         },
        { "red": 112, "green": 164, "blue": 178, "name": "cyan"        },
        { "red": 111, "green": 61,  "blue": 134, "name": "purple"      },
        { "red": 88,  "green": 141, "blue": 67,  "name": "green"       },
        { "red": 53,  "green": 40,  "blue": 121, "name": "blue"        },
        { "red": 184, "green": 199, "blue": 111, "name": "yellow"      },
        { "red": 111, "green": 79,  "blue": 37,  "name": "orange"      },
        { "red": 67,  "green": 57,  "blue": 0,   "name": "brown"       },
        { "red": 154, "green": 103, "blue": 89,  "name": "light red"   },
        { "red": 68,  "green": 68,  "blue": 68,  "name": "dark grey"   },
        { "red": 108, "green": 108, "blue": 108, "name": "grey"        },
        { "red": 154, "green": 210, "blue": 132, "name": "light green" },
        { "red": 108, "green": 94,  "blue": 181, "name": "light blue"  },
        { "red": 149, "green": 149, "blue": 149, "name": "light grey"  }
    ]
}