Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
u8g_clip.c
00001 /* 00002 00003 u8g_clip.c 00004 00005 procedures for clipping 00006 taken over from procs in u8g_pb.c 00007 00008 Universal 8bit Graphics Library 00009 00010 Copyright (c) 2012, olikraus@gmail.com 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without modification, 00014 are permitted provided that the following conditions are met: 00015 00016 * Redistributions of source code must retain the above copyright notice, this list 00017 of conditions and the following disclaimer. 00018 00019 * Redistributions in binary form must reproduce the above copyright notice, this 00020 list of conditions and the following disclaimer in the documentation and/or other 00021 materials provided with the distribution. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00024 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00025 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00028 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00029 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00030 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00033 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00034 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00035 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 00037 Notes 00038 00039 This is one of the most critical parts of u8glib. It must be fast, but still reliable. 00040 Based on the intersection program (see tools folder), there is minimized version of 00041 the condition for the intersaction test: 00042 minimized version 00043 ---1----0 1 b1 <= a2 && b1 > b2 00044 -----1--0 1 b2 >= a1 && b1 > b2 00045 ---1-1--- 1 b1 <= a2 && b2 >= a1 00046 It includes the assumption, that a1 <= a2 is always true (correct, because 00047 a1, a2 are the page dimensions. 00048 00049 The direct implementation of the above result is done in: 00050 uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 00051 However, this is slower than a decision tree version: 00052 static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 00053 Also suprising is, that the macro implementation is slower than the inlined version. 00054 00055 The decision tree is based on the expansion of the truth table. 00056 00057 */ 00058 00059 #include "u8g.h" 00060 00061 #ifdef __GNUC__ 00062 #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline)) 00063 #else 00064 #define U8G_ALWAYS_INLINE 00065 #endif 00066 00067 /* 00068 intersection assumptions: 00069 a1 <= a2 is always true 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 #ifdef OLD_CODE_WHICH_IS_TOO_SLOW 00078 static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 00079 { 00080 uint8_t c1, c2, c3, tmp; 00081 c1 = v0 <= a1; 00082 c2 = v1 >= a0; 00083 c3 = v0 > v1; 00084 00085 tmp = c1; 00086 c1 &= c2; 00087 c2 &= c3; 00088 c3 &= tmp; 00089 c1 |= c2; 00090 c1 |= c3; 00091 return c1 & 1; 00092 } 00093 #endif 00094 00095 #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) )) 00096 00097 //static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE; 00098 static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 00099 { 00100 /* surprisingly the macro leads to larger code */ 00101 /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */ 00102 if ( v0 <= a1 ) 00103 { 00104 if ( v1 >= a0 ) 00105 { 00106 return 1; 00107 } 00108 else 00109 { 00110 if ( v0 > v1 ) 00111 { 00112 return 1; 00113 } 00114 else 00115 { 00116 return 0; 00117 } 00118 } 00119 } 00120 else 00121 { 00122 if ( v1 >= a0 ) 00123 { 00124 if ( v0 > v1 ) 00125 { 00126 return 1; 00127 } 00128 else 00129 { 00130 return 0; 00131 } 00132 } 00133 else 00134 { 00135 return 0; 00136 } 00137 } 00138 } 00139 00140 00141 uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) 00142 { 00143 register u8g_uint_t tmp; 00144 tmp = y; 00145 tmp += h; 00146 tmp--; 00147 if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 ) 00148 return 0; 00149 00150 tmp = x; 00151 tmp += w; 00152 tmp--; 00153 return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp); 00154 } 00155 00156 00157
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2