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_pb8h1f.c
00001 /* 00002 00003 u8g_pb8h1f.c 00004 00005 8bit height monochrom (1 bit) page buffer 00006 byte has horizontal orientation, same as u8g_pb8h1, but byte is flipped 00007 00008 Universal 8bit Graphics Library 00009 00010 Copyright (c) 2011, 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 00038 total buffer size is limited to 256 bytes because of the calculation inside the set pixel procedure 00039 00040 00041 */ 00042 00043 #include "u8g.h" 00044 #include <string.h> 00045 00046 00047 void u8g_pb8h1f_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; 00048 void u8g_pb8h1f_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 00049 void u8g_pb8h1f_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; 00050 void u8g_pb8h1f_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; 00051 uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 00052 00053 00054 void u8g_pb8h1f_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 00055 { 00056 b->buf = buf; 00057 b->width = width; 00058 u8g_pb_Clear(b); 00059 } 00060 00061 /* limitation: total buffer must not exceed 256 bytes, 20 nov 2012: extended to >256 bytes */ 00062 void u8g_pb8h1f_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 00063 { 00064 /*register uint8_t mask, tmp;*/ 00065 register uint8_t mask; 00066 register u8g_uint_t tmp; 00067 uint8_t *ptr = b->buf; 00068 00069 y -= b->p.page_y0; 00070 tmp = b->width >> 3; 00071 tmp *= (uint8_t)y; 00072 ptr += tmp; 00073 00074 mask = 1; 00075 mask <<= x & 7; 00076 x >>= 3; 00077 ptr += x; 00078 if ( color_index ) 00079 { 00080 *ptr |= mask; 00081 } 00082 else 00083 { 00084 mask ^=0xff; 00085 *ptr &= mask; 00086 } 00087 } 00088 00089 00090 void u8g_pb8h1f_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 00091 { 00092 if ( arg_pixel->y < b->p.page_y0 ) 00093 return; 00094 if ( arg_pixel->y > b->p.page_y1 ) 00095 return; 00096 if ( arg_pixel->x >= b->width ) 00097 return; 00098 u8g_pb8h1f_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 00099 } 00100 00101 void u8g_pb8h1f_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00102 { 00103 register uint8_t pixel = arg_pixel->pixel; 00104 do 00105 { 00106 if ( pixel & 128 ) 00107 { 00108 u8g_pb8h1f_SetPixel(b, arg_pixel); 00109 } 00110 switch( arg_pixel->dir ) 00111 { 00112 case 0: arg_pixel->x++; break; 00113 case 1: arg_pixel->y++; break; 00114 case 2: arg_pixel->x--; break; 00115 case 3: arg_pixel->y--; break; 00116 } 00117 pixel <<= 1; 00118 } while( pixel != 0 ); 00119 } 00120 00121 void u8g_pb8h1f_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00122 { 00123 register uint8_t pixel = arg_pixel->pixel; 00124 u8g_uint_t dx = 0; 00125 u8g_uint_t dy = 0; 00126 00127 switch( arg_pixel->dir ) 00128 { 00129 case 0: dx++; break; 00130 case 1: dy++; break; 00131 case 2: dx--; break; 00132 case 3: dy--; break; 00133 } 00134 00135 do 00136 { 00137 if ( pixel & 128 ) 00138 u8g_pb8h1f_SetPixel(b, arg_pixel); 00139 arg_pixel->x += dx; 00140 arg_pixel->y += dy; 00141 pixel <<= 1; 00142 } while( pixel != 0 ); 00143 } 00144 00145 00146 uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00147 { 00148 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00149 switch(msg) 00150 { 00151 case U8G_DEV_MSG_SET_8PIXEL: 00152 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 00153 u8g_pb8h1f_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 00154 break; 00155 case U8G_DEV_MSG_SET_PIXEL: 00156 u8g_pb8h1f_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 00157 break; 00158 case U8G_DEV_MSG_INIT: 00159 break; 00160 case U8G_DEV_MSG_STOP: 00161 break; 00162 case U8G_DEV_MSG_PAGE_FIRST: 00163 u8g_pb_Clear(pb); 00164 u8g_page_First(&(pb->p)); 00165 break; 00166 case U8G_DEV_MSG_PAGE_NEXT: 00167 if ( u8g_page_Next(&(pb->p)) == 0 ) 00168 return 0; 00169 u8g_pb_Clear(pb); 00170 break; 00171 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 00172 case U8G_DEV_MSG_IS_BBX_INTERSECTION: 00173 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 00174 #endif 00175 case U8G_DEV_MSG_GET_PAGE_BOX: 00176 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 00177 break; 00178 case U8G_DEV_MSG_GET_WIDTH: 00179 *((u8g_uint_t *)arg) = pb->width; 00180 break; 00181 case U8G_DEV_MSG_GET_HEIGHT: 00182 *((u8g_uint_t *)arg) = pb->p.total_height; 00183 break; 00184 case U8G_DEV_MSG_SET_COLOR_ENTRY: 00185 break; 00186 case U8G_DEV_MSG_SET_XY_CB: 00187 break; 00188 case U8G_DEV_MSG_GET_MODE: 00189 return U8G_MODE_BW; 00190 } 00191 return 1; 00192 } 00193 00194 00195
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2