A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.
Dependents: mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth
BitmapImage.cpp
00001 /* NeatGUI Library 00002 * Copyright (c) 2013 Neil Thiessen 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "BitmapImage.h" 00018 00019 BitmapImage::BitmapImage(const char* table) : Image(table[0] * 0xFF + table[1], table[2] * 0xFF + table[3]) 00020 { 00021 m_ImageTable = table; 00022 m_FgColor = 0xFFFFFFFF; 00023 m_BgColor = 0x00000000; 00024 } 00025 00026 BitmapImage::BitmapImage(const char* table, unsigned int fg_color) : Image(table[0] * 0xFF + table[1], table[2] * 0xFF + table[3]) 00027 { 00028 m_ImageTable = table; 00029 m_FgColor = fg_color; 00030 m_BgColor = 0x00000000; 00031 } 00032 00033 BitmapImage::BitmapImage(const char* table, unsigned int fg_color, unsigned int bg_color) : Image(table[0] * 0xFF + table[1], table[2] * 0xFF + table[3]) 00034 { 00035 m_ImageTable = table; 00036 m_FgColor = fg_color; 00037 m_BgColor = bg_color; 00038 } 00039 00040 unsigned int BitmapImage::pixel(int x, int y) 00041 { 00042 int addr; 00043 int mask; 00044 int bpl; 00045 00046 //Range check the pixel request 00047 if ((x < 0) || (y < 0) || (x >= width()) || (y >= height())) return 0x000000; 00048 00049 //Get the pixel address 00050 bpl = bytesPerLine(); 00051 mask = 0x80 >> (x % 8); 00052 addr = 4 + y * bpl + (x / 8); 00053 00054 //Return the appropriate color 00055 if (m_ImageTable[addr] & mask) 00056 return m_FgColor; 00057 else 00058 return m_BgColor; 00059 } 00060 00061 unsigned int BitmapImage::foreground() 00062 { 00063 return m_FgColor; 00064 } 00065 00066 void BitmapImage::foreground(unsigned int c) 00067 { 00068 m_FgColor = c; 00069 } 00070 00071 unsigned int BitmapImage::background() 00072 { 00073 return m_BgColor; 00074 } 00075 00076 void BitmapImage::background(unsigned int c) 00077 { 00078 m_BgColor = c; 00079 } 00080 00081 int BitmapImage::bytesPerLine() 00082 { 00083 int bpl; 00084 00085 //Determine the bytes per line 00086 bpl = width() / 8; 00087 if ((width() % 8) != 0) bpl++; 00088 00089 //Return the bytes per line 00090 return bpl; 00091 }
Generated on Tue Jul 12 2022 20:26:18 by 1.7.2