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_pb32h1.c
00001 /* 00002 00003 u8g_pb32h1.c 00004 00005 2x 8bit height monochrom (1 bit) page buffer 00006 byte has horizontal orientation 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 00038 total buffer size is limited to 2*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_pb32h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; 00048 void u8g_pb32h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 00049 void u8g_pb32h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; 00050 void u8g_pb32h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; 00051 uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 00052 00053 void u8g_pb32h1_Clear(u8g_pb_t *b) 00054 { 00055 uint8_t *ptr = (uint8_t *)b->buf; 00056 uint8_t *end_ptr = ptr; 00057 end_ptr += b->width*4; 00058 do 00059 { 00060 *ptr++ = 0; 00061 } while( ptr != end_ptr ); 00062 } 00063 00064 00065 00066 void u8g_pb32h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 00067 { 00068 b->buf = buf; 00069 b->width = width; 00070 u8g_pb32h1_Clear(b); 00071 } 00072 00073 00074 /* limitation: total buffer must not exceed 2*256 bytes */ 00075 void u8g_pb32h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 00076 { 00077 register uint8_t mask; 00078 uint16_t tmp; 00079 uint8_t *ptr = b->buf; 00080 00081 y -= b->p.page_y0; 00082 tmp = b->width; 00083 tmp >>= 3; 00084 tmp *= y; 00085 ptr += tmp; 00086 00087 mask = 0x080; 00088 mask >>= x & 7; 00089 x >>= 3; 00090 ptr += x; 00091 if ( color_index ) 00092 { 00093 *ptr |= mask; 00094 } 00095 else 00096 { 00097 mask ^=0xff; 00098 *ptr &= mask; 00099 } 00100 00101 } 00102 00103 00104 void u8g_pb32h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 00105 { 00106 if ( arg_pixel->y < b->p.page_y0 ) 00107 return; 00108 if ( arg_pixel->y > b->p.page_y1 ) 00109 return; 00110 if ( arg_pixel->x >= b->width ) 00111 return; 00112 u8g_pb32h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 00113 } 00114 00115 void u8g_pb32h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00116 { 00117 register uint8_t pixel = arg_pixel->pixel; 00118 do 00119 { 00120 if ( pixel & 128 ) 00121 { 00122 u8g_pb32h1_SetPixel(b, arg_pixel); 00123 } 00124 switch( arg_pixel->dir ) 00125 { 00126 case 0: arg_pixel->x++; break; 00127 case 1: arg_pixel->y++; break; 00128 case 2: arg_pixel->x--; break; 00129 case 3: arg_pixel->y--; break; 00130 } 00131 pixel <<= 1; 00132 } while( pixel != 0 ); 00133 } 00134 00135 void u8g_pb32h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00136 { 00137 register uint8_t pixel = arg_pixel->pixel; 00138 u8g_uint_t dx = 0; 00139 u8g_uint_t dy = 0; 00140 00141 switch( arg_pixel->dir ) 00142 { 00143 case 0: dx++; break; 00144 case 1: dy++; break; 00145 case 2: dx--; break; 00146 case 3: dy--; break; 00147 } 00148 00149 do 00150 { 00151 if ( pixel & 128 ) 00152 u8g_pb32h1_SetPixel(b, arg_pixel); 00153 arg_pixel->x += dx; 00154 arg_pixel->y += dy; 00155 pixel <<= 1; 00156 } while( pixel != 0 ); 00157 } 00158 00159 00160 uint8_t u8g_dev_pb32h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00161 { 00162 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00163 switch(msg) 00164 { 00165 case U8G_DEV_MSG_SET_8PIXEL: 00166 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 00167 u8g_pb32h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 00168 break; 00169 case U8G_DEV_MSG_SET_PIXEL: 00170 u8g_pb32h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 00171 break; 00172 case U8G_DEV_MSG_INIT: 00173 break; 00174 case U8G_DEV_MSG_STOP: 00175 break; 00176 case U8G_DEV_MSG_PAGE_FIRST: 00177 u8g_pb32h1_Clear(pb); 00178 u8g_page_First(&(pb->p)); 00179 break; 00180 case U8G_DEV_MSG_PAGE_NEXT: 00181 if ( u8g_page_Next(&(pb->p)) == 0 ) 00182 return 0; 00183 u8g_pb32h1_Clear(pb); 00184 break; 00185 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 00186 case U8G_DEV_MSG_IS_BBX_INTERSECTION: 00187 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 00188 #endif 00189 case U8G_DEV_MSG_GET_PAGE_BOX: 00190 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 00191 break; 00192 case U8G_DEV_MSG_GET_WIDTH: 00193 *((u8g_uint_t *)arg) = pb->width; 00194 break; 00195 case U8G_DEV_MSG_GET_HEIGHT: 00196 *((u8g_uint_t *)arg) = pb->p.total_height; 00197 break; 00198 case U8G_DEV_MSG_SET_COLOR_ENTRY: 00199 break; 00200 case U8G_DEV_MSG_SET_XY_CB: 00201 break; 00202 case U8G_DEV_MSG_GET_MODE: 00203 return U8G_MODE_BW; 00204 } 00205 return 1; 00206 } 00207 00208 00209
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2