iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_bitmap.c Source File

u8g_bitmap.c

00001 /*
00002 
00003   u8g_bitmap.c
00004 
00005   Universal 8bit Graphics Library
00006   
00007   Copyright (c) 2011, olikraus@gmail.com
00008   All rights reserved.
00009 
00010   Redistribution and use in source and binary forms, with or without modification, 
00011   are permitted provided that the following conditions are met:
00012 
00013   * Redistributions of source code must retain the above copyright notice, this list 
00014     of conditions and the following disclaimer.
00015     
00016   * Redistributions in binary form must reproduce the above copyright notice, this 
00017     list of conditions and the following disclaimer in the documentation and/or other 
00018     materials provided with the distribution.
00019 
00020   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00021   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00022   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00023   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00024   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00025   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00026   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00027   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00028   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00029   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00030   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00031   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00032   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00033   
00034 
00035 */
00036 
00037 #include "u8g.h"
00038 
00039 void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap)
00040 {
00041   while( cnt > 0 )
00042   {
00043     u8g_Draw8Pixel(u8g, x, y, 0, *bitmap);
00044     bitmap++;
00045     cnt--;
00046     x+=8;
00047   }
00048 }
00049 
00050 void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap)
00051 {
00052   if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
00053     return;
00054   while( h > 0 )
00055   {
00056     u8g_DrawHBitmap(u8g, x, y, cnt, bitmap);
00057     bitmap += cnt;
00058     y++;
00059     h--;
00060   }
00061 }
00062 
00063 
00064 void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap)
00065 {
00066   while( cnt > 0 )
00067   {
00068     u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap));
00069     bitmap++;
00070     cnt--;
00071     x+=8;
00072   }
00073 }
00074 
00075 void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
00076 {
00077   if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
00078     return;
00079   while( h > 0 )
00080   {
00081     u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap);
00082     bitmap += cnt;
00083     y++;
00084     h--;
00085   }
00086 }
00087 
00088 /*=========================================================================*/
00089 
00090 static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap)
00091 {
00092   uint8_t d;
00093   x+=7;
00094   while( w >= 8 )
00095   {
00096     u8g_Draw8Pixel(u8g, x, y, 2, *bitmap);
00097     bitmap++;
00098     w-= 8;
00099     x+=8;
00100   }
00101   if ( w > 0 )
00102   {
00103     d = *bitmap;
00104     x -= 7;
00105     do
00106     {
00107       if ( d & 1 )
00108         u8g_DrawPixel(u8g, x, y);
00109       x++;
00110       w--;
00111       d >>= 1;      
00112     } while ( w > 0 );
00113   }
00114 }
00115 
00116 void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap)
00117 {
00118   u8g_uint_t b;
00119   b = w;
00120   b += 7;
00121   b >>= 3;
00122   
00123   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00124     return;
00125   
00126   while( h > 0 )
00127   {
00128     u8g_DrawHXBM(u8g, x, y, w, bitmap);
00129     bitmap += b;
00130     y++;
00131     h--;
00132   }
00133 }
00134 
00135 static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap)
00136 {
00137   uint8_t d;
00138   x+=7;
00139   while( w >= 8 )
00140   {
00141     u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap));
00142     bitmap++;
00143     w-= 8;
00144     x+=8;
00145   }
00146   if ( w > 0 )
00147   {
00148     d = u8g_pgm_read(bitmap);
00149     x -= 7;
00150     do
00151     {
00152       if ( d & 1 )
00153         u8g_DrawPixel(u8g, x, y);
00154       x++;
00155       w--;
00156       d >>= 1;      
00157     } while ( w > 0 );
00158   }
00159 }
00160 
00161 void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
00162 {
00163   u8g_uint_t b;
00164   b = w;
00165   b += 7;
00166   b >>= 3;
00167   
00168   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00169     return;
00170   while( h > 0 )
00171   {
00172     u8g_DrawHXBMP(u8g, x, y, w, bitmap);
00173     bitmap += b;
00174     y++;
00175     h--;
00176   }
00177 }
00178