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_line.c
00001 /* 00002 00003 u8g_line.h 00004 00005 Universal 8bit Graphics Library 00006 00007 Copyright (c) 2012, 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 #include "u8g.h" 00037 00038 void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2) 00039 { 00040 u8g_uint_t tmp; 00041 u8g_uint_t x,y; 00042 u8g_uint_t dx, dy; 00043 u8g_int_t err; 00044 u8g_int_t ystep; 00045 00046 uint8_t swapxy = 0; 00047 00048 /* no BBX intersection check at the moment, should be added... */ 00049 00050 if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1; 00051 if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1; 00052 00053 if ( dy > dx ) 00054 { 00055 swapxy = 1; 00056 tmp = dx; dx =dy; dy = tmp; 00057 tmp = x1; x1 =y1; y1 = tmp; 00058 tmp = x2; x2 =y2; y2 = tmp; 00059 } 00060 if ( x1 > x2 ) 00061 { 00062 tmp = x1; x1 =x2; x2 = tmp; 00063 tmp = y1; y1 =y2; y2 = tmp; 00064 } 00065 err = dx >> 1; 00066 if ( y2 > y1 ) ystep = 1; else ystep = -1; 00067 y = y1; 00068 for( x = x1; x <= x2; x++ ) 00069 { 00070 if ( swapxy == 0 ) 00071 u8g_DrawPixel(u8g, x, y); 00072 else 00073 u8g_DrawPixel(u8g, y, x); 00074 err -= (uint8_t)dy; 00075 if ( err < 0 ) 00076 { 00077 y += (u8g_uint_t)ystep; 00078 err += (u8g_uint_t)dx; 00079 } 00080 } 00081 } 00082
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2