Code Monkey home page Code Monkey logo

libhebitmap's Introduction

HEBitmap logo

LibHEBitmap

This is just a slight modification of the original HEBitmap build process that will produce static library (libhebitmap.a) files instead of a full game. If you are programming in C, you might also just include the original C files in your project. If you are programming in another language such as Nim (see below), this lib might help.

Building libhebitmap.a

For device (make sure you have the arm toolchain installed)

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$PLAYDATE_SDK_PATH/C_API/buildsupport/arm.cmake -DCMAKE_BUILD_TYPE=Release ..
make

For simulator

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

Usage in Nim

When using Nim, you can use the bindings in the nim folder to use the lib from your project

Note that this is in the Proof of Concept stage. It is usable, but I haven't tested it for memory leaks. Pull requests are welcome.

Make sure to call the initializer once at the start of your program

import playdate/api
import hebitmap

proc handler(event: PDSystemEvent, keycode: uint) {.raises: [].} =
  if event == kEventInit:
    heBitmapSetPlaydateAPI(playdate)
    # ... other setup code

Then

import playdate/api
import hebitmap

# from file
let heCoinImage = gfx.newHeBitmap("images/coin")
heCoinImage.draw(100, 100)

# custom image
let customImage = gfx.newBitmap(20, 20, kColorBlack)

## manipulate customImage however you want
gfx.pushContext(customImage)
# gfx.fillRectangle etc
gfx.popContext()

# this copies the image data, further changes to customImage won't be reflected
let heCustomImage = newHeBitmap(customImage) 
heCustomImage.draw(50,50)
    

HEBitmap (Playdate)

HEBitmap (High Efficiency Bitmap) is a custom implementation of the drawBitmap function (Playdate SDK).

This implementation is up to 4x faster than the SDK drawBitmap function, but native features (clipRect, flip, stencil) are not supported.

Benchmark

Bitmap info: 48x22 (masked)

N Bitmaps HEBitmap drawBitmap Faster
2000 30 ms 120 ms 4x
1000 20 ms 63 ms 3x
500 19 ms 33 ms 1.7x

Example

#include "hebitmap.h"

// Set Playdate API pointer
HEBitmapSetPlaydateAPI(pd);

// Load a LCDBitmap
LCDBitmap *lcd_bitmap = playdate->graphics->loadBitmap("test", NULL);

// New HEBitmap from LCDBitmap
HEBitmap *he_bitmap = HEBitmapNew(lcd_bitmap);

// Draw
HEBitmapDraw(he_bitmap, 0, 0);

// Free
HEBitmapFree(he_bitmap);

// Free original LCDBitmap
playdate->graphics->freeBitmap(lcd_bitmap);

Demo

You can get the compiled PDX demo here. Press A to switch between custom / SDK implementation.

libhebitmap's People

Contributors

ninovanhooff avatar risolvipro avatar boozook 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.