Giter Site home page Giter Site logo

pce's Introduction

Pixel Countdown Encoding


Interface

NOTE : Requires the 'pngjs' module

pce.import.png(<input>)

Input can be one of:

  • String (filepath to a PNG image)
  • object with the following keys:
    • height (number)
    • width (number)
    • pixels (array of [r,g,b,a] values)

Output is a <DecodedImage>

NOTES:

  • Each pixel must be grayscale (r=g=b & a=0) or entirely transparent (a=255)
  • Grayscale pixels are converted into one of the following colors: (based on r/g/b value)
    • Black < 48
    • Dark < 128
    • Light < 208
    • White < 256
pce.batch.encode(<input>)

Input must be an object with the following key/value pairs:

  • : <DecodedImage>

Output is an object with the following key/value pairs:

  • table : <EncodedTable>
  • images : object with the following key/value pairs
    • : <EncodedImage>
      • The matches the input
pce.batch.decode(<input>)

Input must be an object with the following key/value pairs:

  • table : <EncodedTable>
  • images : object with the following key/value pairs
    • : <EncodedImage>

Output is an object with the following key/value pairs:

  • : <DecodedImage>
    • The matches the input

Classes

Properties:

  • height
  • width
  • pixels
    • The pixels is an array of one of 'W','L','D','B','A'
  • hasAlpha
  • encode()
    • Will encode and return an <EncodedImage>

Properties:

  • data
    • The encoded value as a binary string
  • decode()
    • Will decode and return an <DecodedImage>

Properties:

  • data
    • The encoded value as a ByteArray

Encoding Formats

Sprite Encoding (.pce)

Header

  • height (8 bits)
  • width (8 bits)
  • hasAlpha (1 bit)
  • initialColor ()
  • initialCountdown
    • Remaining colors in the following format (in order of appearance)

Body

  • Sequence of s

Whenever a pixel color changes, the next in the sequence belongs to the color that just ended

If an encoded sprite is self contained, the represents the counter If the encoded sprite uses a table, the represents the index in the lookup Table (and the table contains the counter)

The counter is the number of pixels until that color appears again

Table Encoding Format (.pcet)

The table contains all referenced counter values sorted by appearance count

The counter values in the table are not encoded

The table is separated into 2 sections:

  • Single Byte section (contains all counters which fit into a single byte)
  • Double Byte section (contains all counters which don't fit into a single byte)

Header

  • Size of the 'single byte' portion of the table (8 bits)

Body

  • Single Byte section
    • Each value uses 1 byte
  • Double Byte section
    • Each section uses 2 bytes

Color Encoding Format

  • The value of an encoded color is the index of the color in the following array:
    • [White, Light, Dark, Black, Alpha]
  • Length is 3 bits if hasAlpha, otherwise 2 bits

Value Encoding Format

Value are encoded in the following way:

< Header >< 0 >< Data >

The Header is simply an array of consecutive set bits. The Header is finished when the unset bit (<0>) is encountered.

The bit length of the header indicates both the offset and the bit length of the Data.

The offset is the (summation of 2^n)-1 for n=0 to x, where x=bit lenth of the header.

The Data is a simple binary encoding of a number, with the bit length of x+1

The final value of the encoded is the sum of the offset and the data value.


Future Work:

  • Importing more image formats
  • Reading/Writing to file (both encoded and decoded)
  • Work with non-grayscale

pce's People

Contributors

pokeglitch avatar

Watchers

 avatar  avatar

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.