Skip to content
/ cega Public

Rust CGA and EGA binary image file processing library

License

Notifications You must be signed in to change notification settings

knzai/cega

Repository files navigation

cega

CGA/EGA (graphics formats from 80s games) parsing with png/etc output, colored terminal preview, pre-alpha of wasm front-end

github crates.io docs.rs Crates.io GitHub Actions Workflow Status License: Unlicense

Warning

This is currently very much in an alpha state/early beta state: apis and CLI arguments may still change heavily and the apis aren't documented. This file has decent usage examples below.

Installation

Standard crate/cargo install

Features/conditional compilation and related dependencies

[features]
default = ["terminal", "png"]
png = ["dep:image"]
#terminal related features
terminal = ["dep:clap"]
#Preview window popup for the terminal
gui = ["dep:sdl2"]
#web usage may want to build with no-default-features to skip irrelevant terminal stuff
wasm = ["png", "dep:base64", "dep:gloo", "dep:js-sys", "dep:web-sys", "dep:yew"]

Including terminal or wasm produces the corresponding binary

If you use feature gui you must install the sdl2 libraries:

MacOS

brew install sdl2 sdl2_gfx sdl2_image

Linux

[sudo] apt-get install libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev

Roadmap/Upcoming

Priority

  • gif or png output (half the point of the whole library).
  • If I use image::DynamicImage there are additional encoders/decoders that will be free
  • wasm web based processing app - basic happy path with no options works
  • Zooming/scaling (for png and gui output)
  • Additional EGA planar encodings
  • Map viewing (the other half): using the tile/spritesheets as palettes for larger images in psuedo CGA/EGA form (common in 80s games)
  • Outputting to CGA/EGA encodings - useful for making non copyrighted test format files to ship

Everything else

  • Document the code beyond a simple readme
  • Palettes beyond the defaults- cga from the full 16 and ega from the full 256.
  • Breaking the features back out now that I have a better understanding of the modules
  • More tests. Adding as I go, but as I learn rust more and understand the problem space better will make sense to do more
  • Full paletting from RGB(?A alpha support maybe)
  • Better terminal support - rascii for iterm/sixel/etc or ratitui for full tui (helpful for discovering formats) and scrollbars
  • Optimize terminal output (don't repeat active codes)

Great if I get to it, but a bit of a tangent

  • Train a model to recognize format and tiling patterns for smart discovery. I don't know how many test files I can get my hands on but I guess I could generate them

Binary/Terminal Usage

This can be used as a library or executable.

The binary handles arguments (and thus help) via clap 4

Usage: cega [OPTIONS] <IMAGE>

Arguments:
  <IMAGE>  

Options:
  -a, --ascii-mode <ASCII_MODE>      images will horizontally crop to terminal
                                     [possible values: a, c, p, h]
                                     a = plain ascii
                                     c = colored ascii
                                     p = full pixels via ansi bg color
                                     h = horizontal half pixels (UGLY)
  -p, --palette [<PALETTE>]          ega palette can be used for cga, but not the inverse
                                      [possible values: cga0, cga0i, cga1, cga1i, ega]
  -i, --image-parser <IMAGE_PARSER>  [default: cga] [possible values: ega_row_planar, erp, cga]
  -c, --custom-ascii <CUSTOM_ASCII>  4 or 16 chars palette like -a " +%0"
  -w, --width <WIDTH>                [default: 320]
  -o, --output-file <OUTPUT_FILE>    format based on extension - see image crate
  -t, --tile-height <TILE_HEIGHT>    
  -s, --sdl                          
  -q, --quiet                        
  -h, --help                         Print help
  -V, --version                      Print version

cega can parse output to png, and other formats.

cega can parse tiled/spritesheet style cga and output "pixels" to the terminal

cega ../../assets/game/CGATILES.BIN -w 16 -r 16 -i cga -t p:

cega ../../assets/game/CGATILES.BIN -w 16 -r 16 -i cga -t p

cega will output some suggestions, like if it's not a CGA fullscreen image, but you don't specify tiling:

cega ../../assets/game/CGATILES.BIN -t a:

cega ../../assets/game/CGATILES.BIN -t a

cega will ouput in different preview formats, such as colored ASCII or a gui window:

cega ../../assets/game/CGATILES.BIN -w 16 -r 16 -i cga -t c -c "1234" -s:

cega ../../assets/game/CGATILES.BIN -w 16 -r 16 -i cga -t c -c 1234 -s

Acknowledgements & References

About

Rust CGA and EGA binary image file processing library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published