Coder Social home page Coder Social logo

ansilove / libansilove Goto Github PK

View Code? Open in Web Editor NEW
58.0 58.0 12.0 636 KB

Library for converting ANSI, ASCII, and other formats to PNG

Home Page: https://www.ansilove.org

License: BSD 2-Clause "Simplified" License

CMake 0.68% C 99.32%
ansi ascii cp437 textmode

libansilove's Introduction

         _______         ___________          ___
       __\___   \_  ____/     /\   /______ ___\_/__            /\
      /    \|     \/  _ \    /--\_____    \\   /  /\          /  \
    _/      |     /    \     \      |/     /      \ \ _ _____/    \_______
    \       |_____\____/     /      /      \____  /\/                    /
     \______|      \  \_____/\______       /\   \/  \   /\NSILOVE / C   /____ _
      \     |_______\__\___ \ \    \      /  \___\__/____
       \____|        /____/\_\/\__ /     / __/___ \     /\    ____
                     \    \ \     /     /_/ __   \/    /__\__/  _/ _____ ___
                 /\   \____\/    /     //   \    /    /    /    _>/    //__/\
                /  \           _/      \   //   /    /    /     \/    / \__\/
_ _________    /    \_______ _ \___    /_______/    /   _/ \____      \  /
           \  /                 \ \___/\       \_______/\\  \  \______/\/
            \/                   \_\  \ \_______\      \ \\/ \__\     \ \
                                    \__\/        \______\/ h7/dS!\_____\/

AnsiLove/C

AnsiLove is an ANSI and ASCII art to PNG converter, allowing to convert ANSI and artscene-related file formats into PNG images, supporting ANSI (.ANS), PCBoard (.PCB), Binary (.BIN), Artworx (.ADF), iCE Draw (.IDF), Tundra (.TND) and XBin (.XB) formats.

It creates size optimized 4-bit PNG files and supports SAUCE (Standard Architecture for Universal Comment Extensions), 80x25 and 80x50 PC fonts (including all the 14 MS-DOS charsets), Amiga fonts, and iCE colors.

This is a complete rewrite of AnsiLove/PHP in the C programming language.

Experimental seccomp support is available for selected architectures and can be enabled by setting the ENABLE_SECCOMP variable to 1 when invoking CMake.

Specs

AnsiLove/C is strictly using the C99 standard to achieve high portability to all major operating systems. Supported compilers are GCC and Clang, others may work but aren't tested. We use Linux and OpenBSD for AnsiLove/C development.

Why C?

There were many reasons, most notably PHP interpreter independence and performance. A solid C foundation is just perfect for creating libraries and it can easily be embedded into applications. We already mentioned portability. What else? We wanted evolution. AnsiLove/C should not be understood as a port. It takes many different approaches (like processing binary font dumps or generating @2x Retina images), it is overall improved and introduces new features. While results tend to be the same, the codebase does not have much in common with it's ancestor.

Dependencies

AnsiLove/C uses the CMake build system and requires the libansilove library and header files.

Installing dependencies

  • OpenBSD: pkg_add -r cmake
  • NetBSD: pkgin install cmake
  • FreeBSD: pkg install cmake
  • macOS: brew install cmake
  • Alpine Linux: apk add cmake gcc make musl-dev
  • Debian / Ubuntu / Mint: apt-get install build-essential cmake
  • Fedora: dnf install cmake gcc make
  • Solus: eopkg install -c system.devel

Binary packages for libansilove are available on OpenBSD, NetBSD, FreeBSD, Debian, Ubuntu, and Solus.

On other systems, libansilove has to be installed manually.

Compiling

mkdir build
cd build
cmake ..
make

Packages

Ansilove packages are available for:

Features

The following formats are supported:

  • .ANS - ANSi (ANSI escape sequences: ANSI X3.64 standard)
  • .PCB - PCBoard Bulletin Board System (BBS) own file format
  • .BIN - Binary format (raw memory copy of text mode video memory)
  • .ADF - Artworx format, supporting custom character sets and palettes
  • .IDF - iCE Draw format, supporting custom character sets and palettes
  • .TND - TundraDraw format, supporting 24-bit color mode
  • .XB - The eXtended Binary XBin format, supporting custom character sets and palettes

Files with custom suffix default to the ANSi renderer (e.g. ICE or CIA).

AnsiLove/C is capable of processing:

  • SAUCE records
  • DOS and Amiga fonts (embedded binary dump)
  • iCE colors

Even more:

  • Small output file size (4-bit PNG).
  • Optionally generates proper Retina @2x (and up to @8x) PNG.
  • You can use custom options for adjusting output results.
  • Built-in support for rendering Amiga ASCII.

Documentation

Synopsis

     ansilove [-dhiqrsv] [-b bits] [-c columns] [-f font] [-m mode] [-o file]
              [-R factor] [-t type] file

Options

     -b bits     Set to 9 to render 9th column of block characters (default:
                 8).

     -c columns  Adjust number of columns for ANSI, BIN, and TND files.

     -d          Enable DOS aspect ratio.

     -f font     Select font for supported formats.

     -h          Show help.

     -i          Enable iCE colors.

     -m mode     Set rendering mode for ANS files. Valid options are:

                 ced     Black on gray, with 78 columns.

                 transparent
                         Render with transparent background.

                 workbench
                         Use Amiga Workbench palette.

     -o file     Specify output filename/path.

     -q          Suppress output messages (quiet).

     -r          Create Retina @2x output file.

     -R factor   Create Retina output file with custom scale factor.

     -t type     Specify input file type.

     -s          Show SAUCE record without generating output.

     -S          If available, use SAUCE info for render options (ex: width).

     -v          Show version information.

There are certain cases where you need to set options for proper rendering. However, this is occasionally. Results turn out well with the built-in defaults.

Fonts

We dumped many fonts as binary data right into AnsiLove/C, so the most popular typefaces for rendering ANSi / ASCII art are available at your fingertips.

PC fonts can be (all case-sensitive):

  • 80x25 Default (Code page 437)
  • 80x50 80x50 mode (Code page 437)
  • cp737 Greek (Code page 737)
  • cp775 Baltic (Code page 775)
  • cp850 Latin-1 (Code page 850)
  • cp852 Latin-2 (Code page 852)
  • cp855 Cyrillic (Code page 855)
  • cp857 Turkish (Code page 857)
  • cp860 Portuguese (Code page 860)
  • cp861 Icelandic (Code page 861)
  • cp862 Hebrew (Code page 862)
  • cp863 French Canadian (Code page 863)
  • cp865 Nordic (Code page 865)
  • cp866 Russian (Code page 866)
  • cp869 Greek (Code page 869)
  • terminus Terminus (Modern font, code page 437)

AMIGA fonts can be (all case-sensitive):

  • amiga (alias to Topaz)
  • microknight (Original MicroKnight version)
  • microknight+ (Modified MicroKnight version)
  • mosoul (Original mO'sOul font)
  • pot-noodle (Original P0T-NOoDLE font)
  • topaz (Original Topaz Kickstart 2.x version)
  • topaz+ (Modified Topaz Kickstart 2.x+ version)
  • topaz500 (Original Topaz Kickstart 1.x version)
  • topaz500+ (Modified Topaz Kickstart 1.x version)

Bits

bits can be:

  • 8 (8-bit)
  • 9 (9-bit)

Setting the bits to 9 will render the 9th column of block characters, so the output will look like it is displayed in real textmode.

See the "Memory Map" section of the Monochrome Display Adapter notes for more information.

Rendering Mode

mode can be (all case-sensitive):

  • ced
  • transparent
  • workbench

Setting the mode to ced will cause the input file to be rendered in black on gray, and limit the output to 78 columns (only available for ANS files). Used together with an Amiga font, the output will look like it is displayed on Amiga.

Setting the mode to workbench will cause the input file to be rendered using Amiga Workbench colors (only available for ANS files).

Settings the mode to transparent will produce output files with transparent background (only available for ANS files).

iCE Colors

iCE colors are disabled by default, and can be enabled by specifying the -i option.

When an ANSi source was created using iCE colors, it was done with a special mode where the blinking was disabled, and you had 16 background colors available. Basically, you had the same choice for background colors as for foreground colors, that's iCE colors.

Columns

columns is only relevant for .ANS, .BIN, .PCB, and .TND files, and is optional. In most cases conversion will work fine if you don't set this flag, the default value is 160 for .BIN files and 80 otherwise.

SAUCE records

It's fine to use AnsiLove/C as SAUCE reader without generating any output, just set option -s for this purpose.

Projects using Ansilove

  • 16colo.rs - ANSI/ASCII art archive
  • Durdraw - ASCII, Unicode and ANSI art editor for UNIX-like systems
  • emacs-ansilove - Display buffers as PNG images using ansilove inside GNU Emacs

License

AnsiLove/C is released under the BSD 2-Clause license. See the LICENSE file for details.

Authors

AnsiLove/C is developed by Stefan Vogt (@ByteProject), Brian Cassidy (@bricas) and Frederic Cambus (@fcambus).

Resources

Project homepage: https://www.ansilove.org

GitHub: https://github.com/ansilove/ansilove

libansilove's People

Contributors

andyherbert avatar bricas avatar ddeka2910 avatar fcambus avatar jan2642 avatar kirkman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

libansilove's Issues

A Segmentation fault

just as pic show

the pic

when the libansilove parser crafted file, it will cause a OOB if the seqTok assignned wrong

as the valgrind detect, there is a "Invalid read"

root@Starry:~/fuzz/ansilove# valgrind ./ansilove -i poc.ans
==30030== Memcheck, a memory error detector
==30030== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==30030== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==30030== Command: ./ansilove -i poc.ans
==30030==
AnsiLove/C 3.0.9 - ANSI / ASCII art to PNG converter
Copyright (c) 2011-2018 Stefan Vogt, Brian Cassidy, and Frederic Cambus.
==30030== Invalid read of size 1
==30030== at 0x50F9570: __strcmp_sse2_unaligned (strcmp-sse2-unaligned.S:24)
==30030== by 0x4023C0: main (main.c:238)
==30030== Address 0x81a82b0 is 0 bytes inside a block of size 144 free'd
==30030== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30030== by 0x4051E6: sauceReadFile (sauce.c:34)
==30030== by 0x4051E6: sauceReadFileName (sauce.c:22)
==30030== by 0x40236F: main (main.c:230)
==30030== Block was alloc'd at
==30030== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30030== by 0x405198: sauceReadFile (sauce.c:31)
==30030== by 0x405198: sauceReadFileName (sauce.c:22)
==30030== by 0x40236F: main (main.c:230)
==30030==

Input File: poc.ans
Output File: poc.ans.png
==30030== Conditional jump or move depends on uninitialised value(s)
==30030== at 0x4E3D5B4: ansilove_ansi (in /usr/local/lib/libansilove.so.1.0.0)
==30030== by 0x4038A2: main (main.c:304)
==30030==
==30030== Invalid read of size 1
==30030== at 0x5095454: ____strtol_l_internal (strtol_l.c:293)
==30030== by 0x405D0F: strtonum (strtonum.c:50)
==30030== by 0x4E3D481: ansilove_ansi (in /usr/local/lib/libansilove.so.1.0.0)
==30030== by 0x4038A2: main (main.c:304)
==30030== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==30030==
==30030==
==30030== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==30030== Access not within mapped region at address 0x0
==30030== at 0x5095454: ____strtol_l_internal (strtol_l.c:293)
==30030== by 0x405D0F: strtonum (strtonum.c:50)
==30030== by 0x4E3D481: ansilove_ansi (in /usr/local/lib/libansilove.so.1.0.0)
==30030== by 0x4038A2: main (main.c:304)
==30030== If you believe this happened as a result of a stack
==30030== overflow in your program's main thread (unlikely but
==30030== possible), you can try to increase the size of the
==30030== main thread stack using the --main-stacksize= flag.
==30030== The main thread stack size used in this run was 8388608.
==30030==
==30030== HEAP SUMMARY:
==30030== in use at exit: 3,361 bytes in 4 blocks
==30030== total heap usage: 232 allocs, 228 frees, 285,685 bytes allocated
==30030==
==30030== LEAK SUMMARY:
==30030== definitely lost: 0 bytes in 0 blocks
==30030== indirectly lost: 0 bytes in 0 blocks
==30030== possibly lost: 0 bytes in 0 blocks
==30030== still reachable: 3,361 bytes in 4 blocks
==30030== suppressed: 0 bytes in 0 blocks
==30030== Rerun with --leak-check=full to see details of leaked memory
==30030==
==30030== For counts of detected and suppressed errors, rerun with: -v
==30030== Use --track-origins=yes to see where uninitialised values come from
==30030== ERROR SUMMARY: 169 errors from 3 contexts (suppressed: 0 from 0)
Segmentation fault

poc

Port to Python

Hello,

I have ported your project to Python.

I would like to take this opportunity to thank you for the project. It is fantastic in image creation and remains absolutely faithful to the original.

The port aims to be as faithful as possible to your code. However, the GD library has been replaced with Pillow, and although the speed will never match that of C, it is acceptable.

https://github.com/BakasuraRCE/pyansilove

Regards.

How to compile the static library libansilove.a

I have libgd and all of its dependencies statically built and are correctly found and used by cmake when building the default shared library libansilove.so

How can i build the static library libansilove.a in order to build a static standalone ansilove binary?

Support for blinking ANSI art

The recent Fire pack contained a piece by ResetSurvivor which took advantage of blinking text. Libansilove doesn't support blinking text however PNGs support animation, see attached image
348497555-52cbdb00-f5e9-4c0e-86a9-a6cb44bcb9e1

libansilove ported to PS3

Hello! thanks for your work on libansilove !

not really an issue, but I wanted to let you know that I've forked libansilove and built a wrapper to create ARGB textures (instead of .png files) to use them directly on the PlayStation 3.

Based on the generated ansi textures, I built an ANSi Viewer for the PS3: https://github.com/bucanero/ansiview-ps3

The app supports browsing and viewing local files, and also browse the complete archive from 16colo.rs πŸ˜„

cheers!

Mac error: 'ansilove.h' file not found with <angled> include

Trying to build this on a Mac resulted in error output full of this message repeated:

In file included from /Users/kirkman/Sites/libansilove/src/output.h:15:
In file included from /Users/kirkman/Sites/libansilove/src/ansilove.h:16:
/Users/kirkman/Sites/libansilove/src/output.h:15:10: error: 'ansilove.h' file not found with <angled> include; use "quotes" instead
#include <ansilove.h>
         ^~~~~~~~~~~~
         "ansilove.h"

Changing #include <ansilove.h> to #include "../include/ansilove.h" in both output.h and output.c seems to have made it compile successfully. I have no idea why that worked.

Anyway, just wanted to point out that the project is not building on my Mac as it exists in the repo right now.

xterm-256color support

It would be nice for libansilove to support these escape codes for the xterm-256color palette.

Examples of ANSI editors that export ANSI to this format include Durdraw, which also does Ansilove exporting. This would allow Durdraw to export PNG and GIF files in 256 color, instead of just 16 color. This would also allow sites like 16colo.rs to view these files correctly.

I am looking at the source code... I think the trick would be something like:

1: In config.h: Add the xterm-256color palette as 8-bit hex values
2: In ansi.c: Add interpreters for the 256 color escape codes, the palette generator, and any other logic to deal with color values larger than 16.
3: ???
4: profit!

If I get some time I will give it a try, or if someone else wants to. This can probably be considered a duplicate of issue ansilove/ansilove#43.

Thanks!

Inferring font height for XBins with no font data

Quick question regarding your interpretation on parsing XBins with no font data, should not he font height byte be set to 16 or 0?

This is sort of an academic point, because I believe that PD saves font data for all XBins, but I’d thought I’d ask because ansilove fails when it’s 0, but PD loads it successfully because it infers the 8x16 CP437 font.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.