hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Fri Jun 10 15:20:20 2016 +0000
Revision:
0:d8f4c441e032
u8glib???????????i2c???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_clip.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 procedures for clipping
lixianyu 0:d8f4c441e032 6 taken over from procs in u8g_pb.c
lixianyu 0:d8f4c441e032 7
lixianyu 0:d8f4c441e032 8 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 9
lixianyu 0:d8f4c441e032 10 Copyright (c) 2012, olikraus@gmail.com
lixianyu 0:d8f4c441e032 11 All rights reserved.
lixianyu 0:d8f4c441e032 12
lixianyu 0:d8f4c441e032 13 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 14 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 15
lixianyu 0:d8f4c441e032 16 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 17 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 18
lixianyu 0:d8f4c441e032 19 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 20 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 21 materials provided with the distribution.
lixianyu 0:d8f4c441e032 22
lixianyu 0:d8f4c441e032 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 24 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 28 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 29 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 33 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 35 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 36
lixianyu 0:d8f4c441e032 37 Notes
lixianyu 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 This is one of the most critical parts of u8glib. It must be fast, but still reliable.
lixianyu 0:d8f4c441e032 40 Based on the intersection program (see tools folder), there is minimized version of
lixianyu 0:d8f4c441e032 41 the condition for the intersaction test:
lixianyu 0:d8f4c441e032 42 minimized version
lixianyu 0:d8f4c441e032 43 ---1----0 1 b1 <= a2 && b1 > b2
lixianyu 0:d8f4c441e032 44 -----1--0 1 b2 >= a1 && b1 > b2
lixianyu 0:d8f4c441e032 45 ---1-1--- 1 b1 <= a2 && b2 >= a1
lixianyu 0:d8f4c441e032 46 It includes the assumption, that a1 <= a2 is always true (correct, because
lixianyu 0:d8f4c441e032 47 a1, a2 are the page dimensions.
lixianyu 0:d8f4c441e032 48
lixianyu 0:d8f4c441e032 49 The direct implementation of the above result is done in:
lixianyu 0:d8f4c441e032 50 uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 51 However, this is slower than a decision tree version:
lixianyu 0:d8f4c441e032 52 static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 53 Also suprising is, that the macro implementation is slower than the inlined version.
lixianyu 0:d8f4c441e032 54
lixianyu 0:d8f4c441e032 55 The decision tree is based on the expansion of the truth table.
lixianyu 0:d8f4c441e032 56
lixianyu 0:d8f4c441e032 57 */
lixianyu 0:d8f4c441e032 58
lixianyu 0:d8f4c441e032 59 #include "u8g.h"
lixianyu 0:d8f4c441e032 60
lixianyu 0:d8f4c441e032 61 #ifdef __GNUC__
lixianyu 0:d8f4c441e032 62 #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline))
lixianyu 0:d8f4c441e032 63 #else
lixianyu 0:d8f4c441e032 64 #define U8G_ALWAYS_INLINE
lixianyu 0:d8f4c441e032 65 #endif
lixianyu 0:d8f4c441e032 66
lixianyu 0:d8f4c441e032 67 /*
lixianyu 0:d8f4c441e032 68 intersection assumptions:
lixianyu 0:d8f4c441e032 69 a1 <= a2 is always true
lixianyu 0:d8f4c441e032 70
lixianyu 0:d8f4c441e032 71 minimized version
lixianyu 0:d8f4c441e032 72 ---1----0 1 b1 <= a2 && b1 > b2
lixianyu 0:d8f4c441e032 73 -----1--0 1 b2 >= a1 && b1 > b2
lixianyu 0:d8f4c441e032 74 ---1-1--- 1 b1 <= a2 && b2 >= a1
lixianyu 0:d8f4c441e032 75 */
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77 #ifdef OLD_CODE_WHICH_IS_TOO_SLOW
lixianyu 0:d8f4c441e032 78 static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 79 {
lixianyu 0:d8f4c441e032 80 uint8_t c1, c2, c3, tmp;
lixianyu 0:d8f4c441e032 81 c1 = v0 <= a1;
lixianyu 0:d8f4c441e032 82 c2 = v1 >= a0;
lixianyu 0:d8f4c441e032 83 c3 = v0 > v1;
lixianyu 0:d8f4c441e032 84
lixianyu 0:d8f4c441e032 85 tmp = c1;
lixianyu 0:d8f4c441e032 86 c1 &= c2;
lixianyu 0:d8f4c441e032 87 c2 &= c3;
lixianyu 0:d8f4c441e032 88 c3 &= tmp;
lixianyu 0:d8f4c441e032 89 c1 |= c2;
lixianyu 0:d8f4c441e032 90 c1 |= c3;
lixianyu 0:d8f4c441e032 91 return c1 & 1;
lixianyu 0:d8f4c441e032 92 }
lixianyu 0:d8f4c441e032 93 #endif
lixianyu 0:d8f4c441e032 94
lixianyu 0:d8f4c441e032 95 #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) ))
lixianyu 0:d8f4c441e032 96
lixianyu 0:d8f4c441e032 97 //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;
lixianyu 0:d8f4c441e032 98 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)
lixianyu 0:d8f4c441e032 99 {
lixianyu 0:d8f4c441e032 100 /* surprisingly the macro leads to larger code */
lixianyu 0:d8f4c441e032 101 /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */
lixianyu 0:d8f4c441e032 102 if ( v0 <= a1 )
lixianyu 0:d8f4c441e032 103 {
lixianyu 0:d8f4c441e032 104 if ( v1 >= a0 )
lixianyu 0:d8f4c441e032 105 {
lixianyu 0:d8f4c441e032 106 return 1;
lixianyu 0:d8f4c441e032 107 }
lixianyu 0:d8f4c441e032 108 else
lixianyu 0:d8f4c441e032 109 {
lixianyu 0:d8f4c441e032 110 if ( v0 > v1 )
lixianyu 0:d8f4c441e032 111 {
lixianyu 0:d8f4c441e032 112 return 1;
lixianyu 0:d8f4c441e032 113 }
lixianyu 0:d8f4c441e032 114 else
lixianyu 0:d8f4c441e032 115 {
lixianyu 0:d8f4c441e032 116 return 0;
lixianyu 0:d8f4c441e032 117 }
lixianyu 0:d8f4c441e032 118 }
lixianyu 0:d8f4c441e032 119 }
lixianyu 0:d8f4c441e032 120 else
lixianyu 0:d8f4c441e032 121 {
lixianyu 0:d8f4c441e032 122 if ( v1 >= a0 )
lixianyu 0:d8f4c441e032 123 {
lixianyu 0:d8f4c441e032 124 if ( v0 > v1 )
lixianyu 0:d8f4c441e032 125 {
lixianyu 0:d8f4c441e032 126 return 1;
lixianyu 0:d8f4c441e032 127 }
lixianyu 0:d8f4c441e032 128 else
lixianyu 0:d8f4c441e032 129 {
lixianyu 0:d8f4c441e032 130 return 0;
lixianyu 0:d8f4c441e032 131 }
lixianyu 0:d8f4c441e032 132 }
lixianyu 0:d8f4c441e032 133 else
lixianyu 0:d8f4c441e032 134 {
lixianyu 0:d8f4c441e032 135 return 0;
lixianyu 0:d8f4c441e032 136 }
lixianyu 0:d8f4c441e032 137 }
lixianyu 0:d8f4c441e032 138 }
lixianyu 0:d8f4c441e032 139
lixianyu 0:d8f4c441e032 140
lixianyu 0:d8f4c441e032 141 uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
lixianyu 0:d8f4c441e032 142 {
lixianyu 0:d8f4c441e032 143 register u8g_uint_t tmp;
lixianyu 0:d8f4c441e032 144 tmp = y;
lixianyu 0:d8f4c441e032 145 tmp += h;
lixianyu 0:d8f4c441e032 146 tmp--;
lixianyu 0:d8f4c441e032 147 if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 )
lixianyu 0:d8f4c441e032 148 return 0;
lixianyu 0:d8f4c441e032 149
lixianyu 0:d8f4c441e032 150 tmp = x;
lixianyu 0:d8f4c441e032 151 tmp += w;
lixianyu 0:d8f4c441e032 152 tmp--;
lixianyu 0:d8f4c441e032 153 return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp);
lixianyu 0:d8f4c441e032 154 }
lixianyu 0:d8f4c441e032 155
lixianyu 0:d8f4c441e032 156
lixianyu 0:d8f4c441e032 157