/**************************************************************************/ /* */ /* 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_8bpp_pixelmap_raw_write PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of uncompressed */ /* 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 */ /* */ /* 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 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_8bpp_pixelmap_raw_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT xval; INT yval; INT width; GX_UBYTE *putrow; GX_UBYTE *getrow; GX_UBYTE *put; GX_CONST GX_UBYTE *get; GX_RECTANGLE *clip = context -> gx_draw_context_clip; putrow = (GX_UBYTE *)context -> gx_draw_context_memory; putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch; putrow += clip -> gx_rectangle_left; getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data); getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos); getrow += (clip -> gx_rectangle_left - xpos); width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1; for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++) { put = putrow; get = getrow; for (xval = 0; xval < width; xval++) { *put++ = *get++; } putrow += context -> gx_draw_context_pitch; getrow += pixelmap -> gx_pixelmap_width; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_compressed_write PORTABLE C */ /* 6.1.7 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles writing of compressed */ /* pixlemap file. */ /* */ /* 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 */ /* */ /* 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 */ /* 06-02-2021 Kenneth Maxwell Modified comment(s), */ /* removed unused variable */ /* assignment, */ /* resulting in version 6.1.7 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_8bpp_pixelmap_compressed_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT yval; INT xval; GX_CONST GX_UBYTE *get; GX_UBYTE *put; GX_UBYTE *putrow; GX_UBYTE count; INT length; INT repeat; INT width; GX_UBYTE pixel = 0; GX_RECTANGLE *clip = context -> gx_draw_context_clip; get = (GX_CONST GX_UBYTE *)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 & 0x80) { count = (GX_UBYTE)((count & 0x7f) + 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 = (GX_UBYTE *)context -> gx_draw_context_memory; putrow += yval * context -> gx_draw_context_pitch; putrow += xpos; while (yval <= clip -> gx_rectangle_bottom) { put = putrow; xval = xpos; width = pixelmap -> gx_pixelmap_width; while (xval < (xpos + pixelmap -> gx_pixelmap_width)) { count = *get++; if (count & 0x80) { /* repeated value */ count = (GX_UBYTE)((count & 0x7f) + 1); pixel = *get++; repeat = GX_TRUE; } else { /* string of non-repeated values */ count++; repeat = GX_FALSE; } if (repeat == GX_TRUE) { if (count < width) { length = count; } else { length = width; } width -= length; while (length--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { *put = pixel; } put++; xval++; } } else { if (count < pixelmap -> gx_pixelmap_width) { length = count; } else { length = pixelmap -> gx_pixelmap_width; } width -= length; while (length--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { *put = *get; } put++; get++; xval++; } } } putrow += context -> gx_draw_context_pitch; yval++; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_transparent_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 */ /* */ /* None */ /* */ /* 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 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_8bpp_pixelmap_transparent_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT xval; INT yval; INT width; GX_UBYTE *putrow; GX_UBYTE *getrow; GX_UBYTE *put; GX_UBYTE inval; GX_CONST GX_UBYTE *get; GX_RECTANGLE *clip = context -> gx_draw_context_clip; putrow = (GX_UBYTE *)context -> gx_draw_context_memory; putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch; putrow += clip -> gx_rectangle_left; getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data); getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos); getrow += (clip -> gx_rectangle_left - xpos); width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1; for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++) { put = putrow; get = getrow; for (xval = 0; xval < width; xval++) { inval = *get++; if (inval == pixelmap -> gx_pixelmap_transparent_color) { put++; } else { *put++ = inval; } } putrow += context -> gx_draw_context_pitch; getrow += pixelmap -> gx_pixelmap_width; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_compressed_transparent_write */ /* PORTABLE C */ /* 6.1.7 */ /* 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 */ /* */ /* None */ /* */ /* 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 */ /* 06-02-2021 Kenneth Maxwell Modified comment(s), */ /* removed unused variable */ /* assignment, */ /* resulting in version 6.1.7 */ /* */ /**************************************************************************/ static VOID _gx_display_driver_8bpp_pixelmap_compressed_transparent_write(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { INT yval; INT xval; GX_CONST GX_UBYTE *get; GX_UBYTE *put; GX_UBYTE *putrow; GX_UBYTE count; INT length; INT repeat; INT width; GX_UBYTE pixel = 0; GX_RECTANGLE *clip = context -> gx_draw_context_clip; get = (GX_CONST GX_UBYTE *)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 & 0x80) { count = (GX_UBYTE)((count & 0x7f) + 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 = (GX_UBYTE *)context -> gx_draw_context_memory; putrow += yval * context -> gx_draw_context_pitch; putrow += xpos; while (yval <= clip -> gx_rectangle_bottom) { put = putrow; xval = xpos; width = pixelmap -> gx_pixelmap_width; while (xval < (xpos + pixelmap -> gx_pixelmap_width)) { count = *get++; if (count & 0x80) { /* repeated value */ count = (GX_UBYTE)((count & 0x7f) + 1); pixel = *get++; repeat = GX_TRUE; } else { /* string of non-repeated values */ count++; repeat = GX_FALSE; } if (repeat == GX_TRUE) { if (count < width) { length = count; } else { length = width; } width -= length; if (pixel == pixelmap -> gx_pixelmap_transparent_color) { put += length; xval += length; } else { while (length--) { if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right) { *put = pixel; } put++; xval++; } } } else { if (count < pixelmap -> gx_pixelmap_width) { length = count; } else { length = pixelmap -> gx_pixelmap_width; } width -= length; while (length--) { pixel = *get++; if (xval >= clip -> gx_rectangle_left && xval <= clip -> gx_rectangle_right && pixel != pixelmap -> gx_pixelmap_transparent_color) { *put = pixel; } put++; xval++; } } } putrow += context -> gx_draw_context_pitch; yval++; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_draw PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* 8bit 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_8bit_pixelmap_compressed_write */ /* _gx_display_driver_8bit_pixelmap_compressed_transparent_write */ /* _gx_display_driver_8bit_pixelmap_transparent_write */ /* _gx_display_driver_8bit_pixelmap_raw_write */ /* */ /* 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_8bpp_pixelmap_draw(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap) { if (pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_8BIT_PALETTE || (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)) { /* wrong color format for this driver */ return; } if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT) { if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED) { /* has both compression and transparent */ _gx_display_driver_8bpp_pixelmap_compressed_transparent_write(context, xpos, ypos, pixelmap); } else { /* transparent, no compression */ _gx_display_driver_8bpp_pixelmap_transparent_write(context, xpos, ypos, pixelmap); } } else { if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED) { /* compressed with no transparency */ _gx_display_driver_8bpp_pixelmap_compressed_write(context, xpos, ypos, pixelmap); } else { /* no compression or transaprency */ _gx_display_driver_8bpp_pixelmap_raw_write(context, xpos, ypos, pixelmap); } } }