/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** GUIX Component */ /** */ /** Display Management (Display) */ /** */ /**************************************************************************/ #define GX_SOURCE_CODE /* Include necessary system files. */ #include "gx_api.h" #include "gx_display.h" #include "gx_context.h" /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_4444argb_pixelmap_alpha_write PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of uncompressed */ /* pixlemap file with alpha channel. */ /* */ /* INPUT */ /* */ /* context Drawing context */ /* xpos x-coord of top-left draw point*/ /* ypos y-coord of top-left draw point*/ /* pixelmap Pointer to GX_PIXELMAP struct */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* [gx_display_driver_pixel_blend] Basic display driver pixel */ /* blend function */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_4444argb_pixelmap_draw */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_4444argb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT skipcount; INT xval; INT yval; USHORT *getrow; GX_CONST USHORT *get; USHORT pixel; GX_UBYTE alpha; GX_UBYTE brush_alpha; VOID (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha); GX_RECTANGLE *clip = context -> gx_draw_context_clip; brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; if (!blend_func) { return; } /* calculate how many pixels to skip */ skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos); skipcount += (clip -> gx_rectangle_left - xpos); getrow = (USHORT *)(pixelmap -> gx_pixelmap_data); getrow += skipcount; for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++) { get = getrow; for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++) { pixel = *get++; alpha = (GX_UBYTE)(pixel >> 12); if (alpha) { blend_func(context, xval, yval, pixel, brush_alpha); } } getrow += pixelmap -> gx_pixelmap_width; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_4444argb_pixelmap_raw_write PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of uncompressed */ /* pixlemap file with 0xf alpha channel value. */ /* */ /* INPUT */ /* */ /* context Drawing context */ /* xpos x-coord of top-left draw point*/ /* ypos y-coord of top-left draw point*/ /* pixelmap Pointer to GX_PIXELMAP struct */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_4444argb_pixelmap_draw */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_4444argb_pixelmap_raw_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT skipcount; INT xval; INT yval; USHORT *getrow; GX_CONST USHORT *get; USHORT pixel; USHORT *put; USHORT *putrow; GX_RECTANGLE *clip = context -> gx_draw_context_clip; /* calculate how many pixels to skip */ skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos); skipcount += (clip -> gx_rectangle_left - xpos); getrow = (USHORT *)(pixelmap -> gx_pixelmap_data); getrow += skipcount; putrow = (USHORT *)context -> gx_draw_context_memory; putrow += (clip -> gx_rectangle_top) * context -> gx_draw_context_pitch; putrow += clip -> gx_rectangle_left; for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++) { get = getrow; put = putrow; for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++) { /*Or with 0xf000 to make sure it has no alpha.*/ pixel = (*get++) | 0xf000; *put++ = pixel; } getrow += pixelmap -> gx_pixelmap_width; putrow += context -> gx_draw_context_pitch; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_4444argb_pixelmap_c_a_write PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of compressed */ /* pixlemap file with alpha channel. */ /* */ /* INPUT */ /* */ /* context Drawing context */ /* xpos x-coord of top-left draw point*/ /* ypos y-coord of top-left draw point*/ /* pixelmap Pointer to GX_PIXELMAP struct */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* [gx_display_driver_pixel_blend] Basic display driver pixel */ /* blend function */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_4444argb_pixelmap_draw */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT yval; INT xval; GX_CONST USHORT *get; USHORT count; USHORT pixel; GX_UBYTE alpha; GX_UBYTE brush_alpha; VOID (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha); GX_RECTANGLE *clip = context -> gx_draw_context_clip; get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data; brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; if (blend_func == GX_NULL) { return; } /* first, skip to the starting row */ for (yval = ypos; yval < clip -> gx_rectangle_top; yval++) { xval = 0; while (xval < pixelmap -> gx_pixelmap_width) { count = *get++; if (count & 0x8000) { count = (USHORT)((count & 0x7fff) + 1); get++; /* skip repeated pixel value */ } else { count++; get += count; /* skip raw pixel values */ } xval += count; } } /* now we are on the first visible row, copy pixels until we get to the enf of the last visible row */ while (yval <= clip -> gx_rectangle_bottom) { xval = xpos; while (xval < xpos + pixelmap -> gx_pixelmap_width) { count = *get++; if (count & 0x8000) { /* repeated value */ count = (USHORT)((count & 0x7fff) + 1); pixel = *get++; alpha = (GX_UBYTE)(pixel >> 12); if (alpha) { while (count--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { blend_func(context, xval, yval, pixel, brush_alpha); } xval++; } } else { xval += count; } } else { /* string of non-repeated values */ count++; while (count--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { blend_func(context, xval, yval, *get, brush_alpha); } get++; xval++; } } } yval++; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_4444argb_pixelmap_compressed_write */ /* PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of compressed */ /* pixlemap file without alpha channel. */ /* */ /* INPUT */ /* */ /* context Drawing context */ /* xpos x-coord of top-left draw point*/ /* ypos y-coord of top-left draw point*/ /* pixelmap Pointer to GX_PIXELMAP struct */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_4444argb_pixelmap_draw */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_4444argb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT yval; INT xval; GX_CONST USHORT *get; USHORT count; USHORT pixel; USHORT *put; USHORT *putrow; GX_RECTANGLE *clip = context -> gx_draw_context_clip; get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data; /* first, skip to the starting row */ for (yval = ypos; yval < clip -> gx_rectangle_top; yval++) { xval = 0; while (xval < pixelmap -> gx_pixelmap_width) { count = *get++; if (count & 0x8000) { count = (USHORT)((count & 0x7fff) + 1); get++; /* skip repeated pixel value */ } else { count++; get += count; /* skip raw pixel values */ } xval += count; } } /* now we are on the first visible row, copy pixels until we get to the enf of the last visible row */ putrow = (USHORT *)context -> gx_draw_context_memory; putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch; putrow += clip -> gx_rectangle_left; while (yval <= clip -> gx_rectangle_bottom) { xval = xpos; put = putrow; while (xval < xpos + pixelmap -> gx_pixelmap_width) { count = *get++; if (count & 0x8000) { /* repeated value */ count = (USHORT)((count & 0x7fff) + 1); /*Or with 0xf000 to make sure it has no alpha.*/ pixel = (*get++) | 0xf000 ; while (count--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { *put++ = pixel; } xval++; } } else { /* string of non-repeated values */ count++; while (count--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { /*Or with 0xf000 to make sure it has no alpha.*/ pixel = (*get) | 0xf000; *put++ = pixel; } get++; xval++; } } } putrow += context -> gx_draw_context_pitch; yval++; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_4444argb_pixelmap_draw PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* 565rgb screen driver pixelmap drawing function that handles */ /* compressed or uncompress, with or without alpha channel. */ /* */ /* INPUT */ /* */ /* context Drawing context */ /* xpos x-coord of top-left draw point*/ /* ypos y-coord of top-left draw point*/ /* pixelmap Pointer to GX_PIXELMAP struct */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _gx_display_driver_4444argb_pixelmap_compressed_alpha_write */ /* Real display driver pixelmap */ /* draw function */ /* _gx_display_driver_4444argb_pixelmap_compressed_write */ /* Real display driver pixelmap */ /* draw function */ /* _gx_display_driver_4444argb_pixelmap_alpha_write */ /* Real display driver pixelmap */ /* draw function */ /* _gx_display_driver_4444argb_pixelmap_raw_write */ /* Real display driver pixelmap */ /* draw function */ /* _gx_display_driver_4444argb_pixelmap_blend */ /* Basic display driver pixelmap */ /* blend function */ /* */ /* CALLED BY */ /* */ /* GUIX Internal Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ VOID _gx_display_driver_4444argb_pixelmap_draw(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { GX_BOOL drawn = GX_FALSE; GX_UBYTE brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; if (brush_alpha == 0) { /* Draw nothing here. Just return. */ return; } switch (pixelmap -> gx_pixelmap_format) { case GX_COLOR_FORMAT_4444ARGB: if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED) { if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA) { _gx_display_driver_4444argb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap); drawn = GX_TRUE; } else { if (brush_alpha == 0xff) { _gx_display_driver_4444argb_pixelmap_compressed_write(context, xpos, ypos, pixelmap); drawn = GX_TRUE; } } } else { if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA) { _gx_display_driver_4444argb_pixelmap_alpha_write(context, xpos, ypos, pixelmap); drawn = GX_TRUE; } else { if (brush_alpha == 0xff) { _gx_display_driver_4444argb_pixelmap_raw_write(context, xpos, ypos, pixelmap); drawn = GX_TRUE; } } } break; default: drawn = GX_TRUE; break; } if (!drawn) { _gx_display_driver_4444argb_pixelmap_blend(context, xpos, ypos, pixelmap, brush_alpha); } return; }