Giter VIP home page Giter VIP logo

indexedbitmap's Introduction

IndexBitmap

Android support library for use 8BPP Indexed Bitmap.

Indexed color is a technique to manage bitmap colors in a limited fashion, in order to save RAM and video memory buffer space, file storage space, telecom bandwidth. Instead of storing and managing every primary color component of every pixel, the most representative colors, are grouped into a limited size palette: an array of color elements, in which each element (a color) is indexed by its position. This way, the pixels contain not the full color components but merely their index into the palette.
This library can be used to create 8BPP(8-bits per pixel) indexed color bitmap, so it takes up storage space is a quarter of the same dimension 32-bit bitmap(like ARGB8888).

Integration

You can either add the library to your application as a library project or add the following dependency to your build.gradle:

dependencies {
    compile 'com.badpx.indexbitmap:library:1.0.1'
}

Usage

Create the indexed bitmap:

public class IndexBitmapFactory {
    public static Bitmap createBitmap(byte[] pixels, int[] colorTable, int width, int height);
    public static Bitmap createBitmap(byte[] pixels, int[] colorTable, int offset, int stride, int width, int height);

    /**
     * Create a 8-bits indexed bitmap.
     * @param pixels Array of Color Index used to initialize the pixels.This array must be at least as large as width * height.
     * @param colorTable Array of Colors (non-premultiplied 32-bit ARGB colors) used by 8-bit bitmaps,
     *                   where the bitmap bytes are interpreted as indices into the colorTable.
     * @param offset Number of values to skip before the first pixel in the array of pixels.
     * @param stride Number of pixels in the array between rows (must be >= width).
     * @param width The width of the bitmap.
     * @param height The height of the bitmap.
     * @param mutable True if the resulting bitmap should be mutable (i.e. its pixels can be modified)
     */                                 
    public static Bitmap createBitmap(byte[] pixels, int[] colorTable, int offset, int stride, int width, int height, boolean mutable);
}

Access Color Table of Bitmap

public class BitmapHelper {
    /**
     * Get color table of the bitmap.
     * @param bitmap A indexed bitmap.
     * @param output The array to receive the bitmap's color table. */
    public static int getColorTable(Bitmap bitmap, int[] output);

    /**
     * Change color table of the bitmap.
     * @param bitmap A indexed bitmap.
     * @param colorTable Array of Colors (non-premultiplied 32-bit ARGB colors) used by 8-bit bitmaps,
     *                   where the bitmap bytes are interpreted as indices into the colorTable.*/
    public static int changeColorTable(Bitmap bitmap, int[] colorTable);
}

Limitation

A Indexed Bitmap should not be used as target for a Canvas, that means the below code doesn't work:

Canvas canvas = new Canvas(indexedBitmap);
canvas.drawSomething(...);   // It can't draw anything to the indexedBitmap!

indexedbitmap's People

Contributors

badpx avatar

Watchers

James Cloos avatar  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.