# HG changeset patch # User Paul Boddie # Date 1461507589 -7200 # Node ID 7c00cd887cade476059746dbd22e08cfdef4759e # Parent 126b2dfe3b5d1995cf76a7f9bb991463998bb482 Separated the pixel-setting operations from the text pixel functions. diff -r 126b2dfe3b5d -r 7c00cd887cad stage2/lcd.c --- a/stage2/lcd.c Sun Apr 24 01:29:39 2016 +0200 +++ b/stage2/lcd.c Sun Apr 24 16:19:49 2016 +0200 @@ -58,7 +58,7 @@ return (scale * num) / denom; } -static unsigned long pixel(u8 r, u8 g, u8 b, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift) +static u32 pixel(u8 r, u8 g, u8 b, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift) { return (div(r, 255, rmax) << rshift) | (div(g, 255, gmax) << gshift) | (div(b, 255, bmax) << bshift); } @@ -73,41 +73,83 @@ rgb[(pixel_type + 1) % 3] = (rgb[0] + rgb[1]) / 2; } +static void set_pixel32(unsigned short h, unsigned short v, u32 value) +{ + u32 *pix = get_pixel32(h, v); + *pix = value; +} + +static void set_pixel16_565(unsigned short h, unsigned short v, u32 value) +{ + u16 *pix = get_pixel16(h, v); + *pix = (u16) value; +} + +static void set_pixel8(unsigned short h, unsigned short v, u32 value) +{ + u8 *pix = get_pixel8(h, v); + *pix = (u8) value; +} + +static void set_pixel4(unsigned short h, unsigned short v, u32 value) +{ + u8 *pix = get_pixel4(h, v); + u8 mask = h & 1 ? 0xf0 : 0x0f; + *pix = (*pix & mask) | ((u8) value); +} + +void set_pixel(unsigned short h, unsigned short v, u32 value) +{ + switch (panel_info.vl_bpix) + { + case LCD_COLOR32: + set_pixel32(h, v, value); + break; + + case LCD_COLOR8: + set_pixel8(h, v, value); + break; + + case LCD_COLOR4: + set_pixel4(h, v, value); + break; + + case LCD_COLOR16: + default: + set_pixel16_565(h, v, value); + break; + } +} static void test_pixel32(unsigned short h, unsigned short v, unsigned short pixel_type) { - u32 *pix = get_pixel32(h, v); u8 rgb[3]; get_colour(h, v, rgb, pixel_type); - *pix = (u32) pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0); + set_pixel32(h, v, pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0)); } static void test_pixel16_565(unsigned short h, unsigned short v, unsigned short pixel_type) { - u16 *pix = get_pixel16(h, v); u8 rgb[3]; get_colour(h, v, rgb, pixel_type); - *pix = (u16) pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0); + set_pixel16_565(h, v, pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0)); } static void test_pixel8(unsigned short h, unsigned short v, unsigned short pixel_type) { - u8 *pix = get_pixel8(h, v); u8 rgb[3]; get_colour(h, v, rgb, pixel_type); - *pix = (u8) pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0); + set_pixel8(h, v, pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0)); } static void test_pixel4(unsigned short h, unsigned short v, unsigned short pixel_type) { - u8 *pix = get_pixel4(h, v); - u8 mask = h & 1 ? 0xf0 : 0x0f; u8 rgb[3]; get_colour(h, v, rgb, pixel_type); - *pix = (*pix & mask) | ((u8) pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0) << (h & 1 ? 0 : 4)); + set_pixel4(h, v, pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0)); } void test_pixel(unsigned short h, unsigned short v, unsigned short pixel_type) diff -r 126b2dfe3b5d -r 7c00cd887cad stage2/lcd.h --- a/stage2/lcd.h Sun Apr 24 01:29:39 2016 +0200 +++ b/stage2/lcd.h Sun Apr 24 16:19:49 2016 +0200 @@ -1,12 +1,15 @@ #ifndef __LCD_H__ #define __LCD_H__ +#include "xburst_types.h" + /* Initialisation functions. */ void lcd_init(void); /* Output functions. */ +void set_pixel(unsigned short h, unsigned short v, u32 value); void test_pixel(unsigned short h, unsigned short v, unsigned short pixel_type); void clear_pixel(unsigned short h, unsigned short v);