iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_pb.c Source File

u8g_pb.c

00001 /*
00002 
00003   u8g_pb.c
00004   
00005   common procedures for the page buffer
00006 
00007   Universal 8bit Graphics Library
00008   
00009   Copyright (c) 2011, olikraus@gmail.com
00010   All rights reserved.
00011 
00012   Redistribution and use in source and binary forms, with or without modification, 
00013   are permitted provided that the following conditions are met:
00014 
00015   * Redistributions of source code must retain the above copyright notice, this list 
00016     of conditions and the following disclaimer.
00017     
00018   * Redistributions in binary form must reproduce the above copyright notice, this 
00019     list of conditions and the following disclaimer in the documentation and/or other 
00020     materials provided with the distribution.
00021 
00022   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00023   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00024   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00025   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00027   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00028   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00029   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00030   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00031   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00032   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00033   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00034   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00035   
00036   
00037 */
00038 
00039 #include "u8g.h"
00040 
00041 void u8g_pb_Clear(u8g_pb_t *b)
00042 {
00043   uint8_t *ptr = (uint8_t *)b->buf;
00044   uint8_t *end_ptr = ptr;
00045   end_ptr += b->width;
00046   do
00047   {
00048     *ptr++ = 0;
00049   } while( ptr != end_ptr );
00050 }
00051 
00052 /* the following procedure does not work. why? Can be checked with descpic */
00053 /*
00054 void u8g_pb_Clear(u8g_pb_t *b)
00055 {
00056   uint8_t *ptr = (uint8_t *)b->buf;
00057   uint8_t cnt = b->width;
00058   do
00059   {
00060     *ptr++ = 0;
00061     cnt--;
00062   } while( cnt != 0 );
00063 }
00064 */
00065 
00066 /*
00067   intersection assumptions:
00068     a1 <= a2 is always true    
00069 */
00070   /*
00071     minimized version
00072     ---1----0 1             b1 <= a2 && b1 > b2
00073     -----1--0 1             b2 >= a1 && b1 > b2
00074     ---1-1--- 1             b1 <= a2 && b2 >= a1
00075   */
00076 /*
00077 uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
00078 {
00079   uint8_t c0, c1, c;
00080   c0 = v0 <= b->p.page_y1;
00081   c1 = v1 >= b->p.page_y0;
00082   c = v0 > v1;
00083   if ( c0 && c1 ) return 1;
00084   if ( c0 && c ) return 1;
00085   if ( c1 && c ) return 1;
00086   return 0;
00087 }
00088 */
00089 
00090 uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1)
00091 {
00092   uint8_t c1, c2, c3, tmp;
00093   c1 = v0 <= pb->p.page_y1;
00094   c2 = v1 >= pb->p.page_y0;
00095   c3 = v0 > v1;
00096   /*
00097   if ( c1 && c2 )
00098     return 1;
00099   if ( c1 && c3 )
00100     return 1;
00101   if ( c2 && c3 )
00102     return 1;
00103   return 0;
00104   */
00105   
00106   tmp = c1;
00107   c1 &= c2;
00108   c2 &= c3;
00109   c3 &= tmp;
00110   c1 |= c2;
00111   c1 |= c3;
00112   return c1 & 1;
00113 }
00114 
00115 
00116 uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
00117 {
00118   uint8_t /*c0, c1, */ c2, c3;
00119   /*
00120     conditions: b->p.page_y0 < b->p.page_y1
00121     there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed
00122   */
00123   /*
00124   c0 = v0 < 0;
00125   c1 = v1 < 0;
00126   */
00127   c2 = v0 > b->width;
00128   c3 = v1 > b->width;
00129   /*if ( c0 && c1 ) return 0;*/
00130   if ( c2 && c3 ) return 0;
00131   /*if ( c1 && c2 ) return 0;*/
00132   return 1;
00133 }
00134 
00135 uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx)
00136 {
00137   u8g_uint_t tmp;
00138 
00139   tmp = bbx->y;
00140   tmp += bbx->h;
00141   tmp--;
00142   
00143   if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 )
00144     return 0;
00145   
00146   /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
00147   tmp = bbx->x;
00148   tmp += bbx->w;
00149   tmp--;
00150     
00151   return u8g_pb_IsXIntersection(pb, bbx->x, tmp);
00152 }
00153 
00154 void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box)
00155 {
00156   box->x0 = 0;
00157   box->y0 = pb->p.page_y0;
00158   box->x1 = pb->width;
00159   box->x1--;
00160   box->y1 = pb->p.page_y1;
00161 }
00162 
00163 
00164 uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
00165 {
00166   u8g_uint_t v0, v1;
00167   v0 = arg_pixel->y;
00168   v1 = v0;
00169   switch( arg_pixel->dir )
00170   {
00171     case 0:
00172       break;
00173     case 1:  
00174       v1 += 8;          /* this is independent from the page height */
00175       break;
00176     case 2:  
00177       break;
00178     case 3: 
00179       v0 -= 8;
00180       break;
00181   }
00182   return u8g_pb_IsYIntersection(b, v0, v1);
00183 }
00184 
00185 
00186 
00187 uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev)
00188 {
00189   return u8g_WriteSequence(u8g, dev, b->width, b->buf);  
00190 }
00191 
00192