Repository navigation
Home
The SLIC class exposes a few simple methods detailed below. The more challenging part of using it is when you're using a new type of media/file and/or display and need to write your own callback functions. Those are documented below the API section.
This is the entire class definition for SLIC:
class SLIC {
public:
int init_encode_ram(uint16_t iWidth, uint16_t iHeight, int iBpp, uint8_t *pPalette, uint8_t *pOut, int iOutSize);
int init_encode(const char *filename, uint16_t iWidth, uint16_t iHeight, int iBpp, uint8_t *pPalette, SLIC_OPEN_CALLBACK *pfnOpen, SLIC_WRITE_CALLBACK *pfnWrite);
int encode(uint8_t *pPixels, int iPixelCount);
int init_decode_ram(uint8_t *pData, int iDataSize, uint8_t *pPalette);
int init_decode_flash(uint8_t *pData, int iDataSize, uint8_t *pPalette);
int init_decode(const char *filename, uint8_t *pPalette, SLIC_OPEN_CALLBACK *pfnOpen, SLIC_READ_CALLBACK *pfnRead);
int decode(uint8_t *pOut, int iOutSize);
int get_width();
int get_height();
int get_bpp();
int get_colorspace();
int get_output_size();
private:
SLICSTATE _slic;
};The class is basically a C++ wrapper of C code which does all of the actual work. The SLICSTATE structure is kept private, but is passed as a pointer to the 'worker' functions. This makes it easy to lift out the C code if you want to use it in a pure C project. Here are details of each method:
int init_encode_ram(uint16_t iWidth, uint16_t iHeight, int iBpp, uint8_t *pPalette, uint8_t *pOut, int iOutSize)
There are two versions of initializing the encoder - one to write the output to a pre-allocated buffer and another to write it incrementally to a callback function. This version is passed the image size and bits per pixel along with an optional palette followed by the buffer you want the output to be written into. If the buffer you provided ends up being too small, then encoder will return a SLIC_ENCODE_OVERFLOW error during encoding. Successful initialization will return a SLIC_SUCCESS return code.
int init_encode(uint16_t iWidth, uint16_t iHeight, int iBpp, uint8_t *pPalette, SLIC_OPEN_CALLBACK *pfnOpen, SLIC_WRITE_CALLBACK *pfnWrite)
This version is passed the image size and bits per pixel along with an optional palette followed by the open and write callback functions to handle the incremental writing of compressed data. It's up to you to manage where this data is sent. Each call to the write callback will have up to FILE_BUF_SIZE bytes of compressed data. Successful initialization will return a SLIC_SUCCESS return code.
int encode(uint8_t *pPixels, int iPixelCount)
This passes any number of pixels to the encoder to compress into the output stream. One of the init_encoder functions must be called first. This is called once (if you send the whole image) or repeatedly until the image is complete. For the RGB565 and 8-bit formats, it's best to pass as many pixels as you can in each call to produce the most compact output. Some pixel ops are stored as pairs and if the last pixel of your call is the first of the pair, it will cause a less than ideal op to be used. Successful encoding of each set of pixels will return a SLIC_SUCCESS return code. When the image is complete, SLIC_DONE will be returned.
int init_decode_ram(uint8_t *pData, int iDataSize, uint8_t *pPalette)
There are three versions of initializing the decoder - this one is for working from a single buffer (usually in RAM) which contains the entire compressed image. Pass a pointer to the compressed image data, its size and an optional buffer pointer to receive palette data. Successful initialization will return a SLIC_SUCCESS return code. After successfully calling this method, you can query the size and pixel type of the image.
int init_decode_flash(uint8_t *pData, int iDataSize, uint8_t *pPalette)
Like the version of the init function above, this one is for working from a single buffer (stored in FLASH memory) which contains the entire compressed image. The reason this is needed is because certain CPU architectures (e.g. AVR/ESP8266) have a separate address space for RAM and ROM. Pass a pointer to the compressed image data, its size and an optional buffer pointer to receive palette data. Successful initialization will return a SLIC_SUCCESS return code. After successfully calling this method, you can query the size and pixel type of the image.
int init_decode(uint8_t *pData, int iDataSize, uint8_t *pPalette, SLIC_OPEN_CALLBACK *pfnOpen, SLIC_READ_CALLBACK *pfnRead)
This third version of the init method is for working with compressed data coming from a file system. The open callback will be called first and if successful, the file header and optional palette will be read by calling the read callback. Once decoding begins, period calls to the read callback function will occur to refill the internal file buffer. Successful initialization will return a SLIC_SUCCESS return code. After successfully calling this method, you can query the size and pixel type of the image.
int decode(uint8_t *pOut, int iOutSize)
Decode iOutSize (pixel count) into the provided buffer. This function can request 1 or more pixels at a time. If requesting more pixels than are available, it will provide only the amount actually available and not return an error. Note When working with 24-bpp images, allow 3 extra bytes in the output buffer since output pixels can be written 32-bits at a time even when decoding a 24-bpp image. This is to reduce CPU cycles doing extra comparisons. When the last pixel is requested, it will return SLIC_DONE otherwise SLIC_SUCCESS.
int get_width()
Returns the width of the image (after calling one of the init_decode methods).
int get_height()
Returns the height of the image (after calling one of the init_decode methods).
int get_bpp()
Returns the number of bits per pixel of the image (after calling one of the init_decode methods).
int get_colorspace()
Returns the colorspace (see slic.h for a list of possible values) of the image (after calling one of the init_decode methods).
int get_output_size()
After compressing an image and SLIC_DONE has been returned, this method can be called to query the total compressed data size (including SLIC header info).