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_pb8h2.c
00001 /* 00002 00003 u8g_pb8h2.c 00004 00005 8bit height 2 bit per pixel page buffer 00006 byte has horizontal orientation 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 */ 00039 00040 #include "u8g.h" 00041 #include <string.h> 00042 00043 void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 00044 { 00045 b->buf = buf; 00046 b->width = width; 00047 u8g_pb_Clear(b); 00048 } 00049 00050 static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 00051 static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 00052 { 00053 register uint8_t mask; 00054 register uint16_t tmp; 00055 00056 uint8_t *ptr = b->buf; 00057 00058 y -= b->p.page_y0; 00059 00060 tmp = b->width; 00061 tmp >>= 2; 00062 tmp *= (uint8_t)y; 00063 ptr += tmp; 00064 00065 tmp = x; 00066 tmp >>= 2; 00067 ptr += tmp; 00068 00069 tmp = x; 00070 tmp &= 3; 00071 tmp <<= 1; 00072 mask = 3; 00073 mask <<= tmp; 00074 mask = ~mask; 00075 color_index &= 3; 00076 color_index <<= tmp; 00077 00078 *ptr &= mask; 00079 *ptr |= color_index; 00080 } 00081 00082 00083 void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 00084 { 00085 if ( arg_pixel->y < b->p.page_y0 ) 00086 return; 00087 if ( arg_pixel->y > b->p.page_y1 ) 00088 return; 00089 if ( arg_pixel->x >= b->width ) 00090 return; 00091 u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 00092 } 00093 00094 00095 void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00096 { 00097 register uint8_t pixel = arg_pixel->pixel; 00098 do 00099 { 00100 if ( pixel & 128 ) 00101 { 00102 u8g_pb8h2_SetPixel(b, arg_pixel); 00103 } 00104 switch( arg_pixel->dir ) 00105 { 00106 case 0: arg_pixel->x++; break; 00107 case 1: arg_pixel->y++; break; 00108 case 2: arg_pixel->x--; break; 00109 case 3: arg_pixel->y--; break; 00110 } 00111 pixel <<= 1; 00112 } while( pixel != 0 ); 00113 } 00114 00115 00116 00117 uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00118 { 00119 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00120 switch(msg) 00121 { 00122 case U8G_DEV_MSG_SET_8PIXEL: 00123 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 00124 { 00125 u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 00126 } 00127 break; 00128 case U8G_DEV_MSG_SET_PIXEL: 00129 u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 00130 break; 00131 case U8G_DEV_MSG_INIT: 00132 break; 00133 case U8G_DEV_MSG_STOP: 00134 break; 00135 case U8G_DEV_MSG_PAGE_FIRST: 00136 u8g_pb_Clear(pb); 00137 u8g_page_First(&(pb->p)); 00138 break; 00139 case U8G_DEV_MSG_PAGE_NEXT: 00140 if ( u8g_page_Next(&(pb->p)) == 0 ) 00141 return 0; 00142 u8g_pb_Clear(pb); 00143 break; 00144 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 00145 case U8G_DEV_MSG_IS_BBX_INTERSECTION: 00146 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 00147 #endif 00148 case U8G_DEV_MSG_GET_PAGE_BOX: 00149 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 00150 break; 00151 case U8G_DEV_MSG_GET_WIDTH: 00152 *((u8g_uint_t *)arg) = pb->width; 00153 break; 00154 case U8G_DEV_MSG_GET_HEIGHT: 00155 *((u8g_uint_t *)arg) = pb->p.total_height; 00156 break; 00157 case U8G_DEV_MSG_SET_COLOR_ENTRY: 00158 break; 00159 case U8G_DEV_MSG_SET_XY_CB: 00160 break; 00161 case U8G_DEV_MSG_GET_MODE: 00162 return U8G_MODE_GRAY2BIT; 00163 } 00164 return 1; 00165 } 00166 00167 00168
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2