Chris Taylor / Mbed 2 deprecated RETRO-CityRally

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bitmap1bpp.cpp Source File

Bitmap1bpp.cpp

00001 #include "mbed.h"
00002 #include "Bitmap1bpp.h"
00003 
00004 Bitmap1bpp::Bitmap1bpp(uint16_t width, uint16_t height):
00005     _width(width), 
00006     _height(height),
00007     _stride((width >> 3) + ((width & 0x07) ? 1 : 0)),
00008     _pBitmapData(new uint8_t[_stride * height])
00009 {
00010     
00011 }
00012 
00013 Bitmap1bpp::~Bitmap1bpp()
00014 {
00015     if (_pBitmapData != NULL)
00016     {
00017         delete []_pBitmapData;
00018         _pBitmapData = NULL;
00019     }
00020 }
00021 
00022 void Bitmap1bpp::clear()
00023 {
00024     memset(_pBitmapData, 0, _stride * _height);
00025 }
00026 
00027 void Bitmap1bpp::setPixel(int16_t x, int16_t y, uint16_t color)
00028 {
00029     if (x < 0 || x >= _width || y < 0 || y >= _height) return;
00030     
00031     uint8_t mask = 1 << (7 - (x % 8));
00032     uint8_t *p = _pBitmapData + ((y * _stride) + (x / 8));
00033     
00034     if (color) *p |= mask; else *p &= ~mask;
00035 }