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