/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** 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_blend PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles blending of uncompressed */ /* 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 */ /* alpha blending value 0 to 255 */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* [gx_display_driver_pixel_blend] Basic display driver pixel */ /* blend function */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_8bpp_pixelmap_blend */ /* */ /* 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_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha) { INT xval; INT yval; GX_UBYTE *get; GX_UBYTE *getrow; GX_UBYTE pixel; GX_RECTANGLE *clip = context -> gx_draw_context_clip; VOID (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha); blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; if (!blend_func) { return; } getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data + (INT)sizeof(GX_UBYTE) * pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos)); getrow += (clip -> gx_rectangle_left - xpos); 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++; blend_func(context, xval, yval, pixel, alpha); } getrow += pixelmap -> gx_pixelmap_width; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_alpha_blend PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Internal helper function that handles blending of uncompressed */ /* pixelmap 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 */ /* alpha blending value 0 to 255 */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* [gx_display_driver_pixel_blend] Basic display driver pixel */ /* blend function */ /* */ /* CALLED BY */ /* */ /* _gx_display_driver_8bpp_pixelmap_blend */ /* */ /* 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_alpha_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha) { INT skipcount; INT xval; INT yval; GX_UBYTE *getrow; GX_UBYTE *getrowalpha; GX_UBYTE *get; GX_UBYTE pixel; GX_UBYTE *getalpha; INT combined_alpha; GX_UBYTE internal_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; blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; if (GX_NULL == 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 = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data); getrow += skipcount; getrowalpha = (GX_UBYTE *)(pixelmap -> gx_pixelmap_aux_data); getrowalpha += skipcount; for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++) { get = getrow; getalpha = getrowalpha; for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++) { internal_alpha = *getalpha++; if (internal_alpha) { combined_alpha = internal_alpha * alpha; combined_alpha /= 255; pixel = *get; blend_func(context, xval, yval, pixel, (GX_UBYTE)combined_alpha); } get++; } getrow += pixelmap -> gx_pixelmap_width; getrowalpha += pixelmap -> gx_pixelmap_width; } } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _gx_display_driver_8bpp_pixelmap_blend PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Kenneth Maxwell, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* Driver entry point for pixelmap blending 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 */ /* alpha blending value 0 to 255 */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _gx_display_driver_8bpp_pixelmap_alpha_blend */ /* Real display driver pixelmap */ /* blend function for 8bpp */ /* _gx_display_driver_8bpp_pixelmap_raw_blend */ /* Real display driver pixelmap */ /* blend function for 8bpp */ /* */ /* 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_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha) { if ((pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT) || (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)) { /* Wrong format. */ return; } if (pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_8BIT_PACKED_PIXEL) { /* wrong color format for this driver */ return; } if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA) { /* alpha, no compression */ _gx_display_driver_8bpp_pixelmap_alpha_blend(context, xpos, ypos, pixelmap, alpha); } else { /* no compression or alpha */ _gx_display_driver_8bpp_pixelmap_raw_blend(context, xpos, ypos, pixelmap, alpha); } }