Giter Site home page Giter Site logo

fastbitmap's Introduction

FastBitmap - The Fast C# Bitmap Layer

Based on work found on Visual C# Kicks: http://www.vcskicks.com/fast-image-processing.php

Build status codecov

FastBitmap is a bitmap wrapper class that intends to provide fast bitmap read/write operations on top of a safe layer of abstraction.

It provides operations for setting/getting pixel colors, copying regions accross bitmaps, clearing whole bitmaps, and copying whole bitmaps.

Editing pixels of a bitmap is just as easy as:

    Bitmap bitmap = new Bitmap(64, 64);
    
    using(var fastBitmap = bitmap.FastLock())
    {
        // Do your changes here...
        fastBitmap.Clear(Color.White);
        fastBitmap.SetPixel(1, 1, Color.Red);
    }

Or alternatively, albeit longer:

    Bitmap bitmap = new Bitmap(64, 64);
    FastBitmap fastBitmap = new FastBitmap(bitmap);
    
    // Locking bitmap before doing operations
    fastBitmap.Lock();
    
    // Do your changes here...
    fastBitmap.Clear(Color.White);
    fastBitmap.SetPixel(1, 1, Color.Red);
    
    // Don't forget to unlock!
    fastBitmap.Unlock();

This project contains the FastBitmap class and acompanying unit test suite.
Note that to compile this class you must have the /unsafe compiler flag turned on in your project settings.

Note: This code currently only works with 32bpp bitmaps

Installation

FastBitmap is available as a Nuget package:

PM > Install-Package FastBitmapLib

Speed

The following profiling tests showcase comparisions with the native System.Drawing.Bitmap equivalent method calls

SetPixel profiling
1024 x 1024 Bitmap SetPixel: 2054ms
1024 x 1024 FastBitmap SetPixel: 398ms
1024 x 1024 FastBitmap Int SetPixel: 331ms

Results: FastBitmap 6,21x faster

GetPixel profiling
1024 x 1024 Bitmap GetPixel: 1498ms
1024 x 1024 FastBitmap GetPixel: 382ms
1024 x 1024 FastBitmap Int GetPixel: 327ms

Results: FastBitmap 4,58x faster

Bitmap copying profiling
1024 x 1024 Bitmap SetPixel: 2888ms
1024 x 1024 FastBitmap CopyPixels: 5ms

Results: FastBitmap 577,60x faster

Bitmap clearing profiling
1024 x 1024 Bitmap SetPixel: 1795ms
1024 x 1024 FastBitmap Clear: 5ms

Results: FastBitmap 359,00x faster

fastbitmap's People

Contributors

luizzak avatar ulysseswu avatar tadelsucht avatar

Watchers

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