qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chad Jablonski <chad@jablonski.xyz>
To: qemu-devel@nongnu.org
Cc: balaton@eik.bme.hu, Chad Jablonski <chad@jablonski.xyz>
Subject: [PATCH v2 6/7] ati-vga: Add expand_colors() helper for monochrome color expansion
Date: Sun,  2 Nov 2025 22:36:07 -0500	[thread overview]
Message-ID: <20251103033608.120908-7-chad@jablonski.xyz> (raw)
In-Reply-To: <20251103033608.120908-1-chad@jablonski.xyz>

Convert 1bpp monochrome images to 32bpp ARGB given a foreground and
background color. This also supports most significant and least
significant bit ordering.

This is useful for host data transfers of glyphs when drawing text in X.

Signed-off-by: Chad Jablonski <chad@jablonski.xyz>
---
 hw/display/ati_2d.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index 15cf29a061..181bf634f0 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -45,6 +45,28 @@ static int ati_bpp_from_datatype(ATIVGAState *s)
 }
 
 #define DEFAULT_CNTL (s->regs.dp_gui_master_cntl & GMC_DST_PITCH_OFFSET_CNTL)
+/* Convert 1bpp monochrome data to 32bpp ARGB using color expansion */
+static void expand_colors(uint8_t *color_dst, const uint8_t *mono_src,
+                          uint32_t width, uint32_t height,
+                          uint32_t fg_color, uint32_t bg_color,
+                          bool lsb_to_msb)
+{
+    uint32_t byte, color;
+    uint8_t *pixel;
+    int i, j, bit;
+    /* Rows are 32-bit aligned */
+    int bytes_per_row = ((width + 31) / 32) * 4;
+
+    for (i = 0; i < height; i++) {
+        for (j = 0; j < width; j++) {
+            byte = mono_src[i * bytes_per_row + (j / 8)];
+            bit = lsb_to_msb ? 7 - (j % 8) : j % 8;
+            color = (byte >> bit) & 0x1 ? fg_color : bg_color;
+            pixel = &color_dst[(i * width + j) * 4];
+            memcpy(pixel, &color, sizeof(color));
+        }
+    }
+}
 
 void ati_2d_blt(ATIVGAState *s)
 {
-- 
2.51.0



  parent reply	other threads:[~2025-11-03  3:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03  3:36 [PATCH v2 0/7] ati-vga: Implement HOST_DATA transfers to enable X.org text rendering Chad Jablonski
2025-11-03  3:36 ` [PATCH v2 1/7] ati-vga: Add scissor clipping register support Chad Jablonski
2025-11-03 13:16   ` BALATON Zoltan
2025-11-04 18:22     ` Chad Jablonski
2025-11-03  3:36 ` [PATCH v2 2/7] ati-vga: Implement scissor rectangle clipping for 2D operations Chad Jablonski
2025-11-03 13:29   ` BALATON Zoltan
2025-11-05 19:29     ` Chad Jablonski
2025-11-03  3:36 ` [PATCH v2 3/7] ati-vga: Implement foreground and background color register writes Chad Jablonski
2025-11-03 13:33   ` BALATON Zoltan
2025-11-03  3:36 ` [PATCH v2 4/7] ati-vga: Fix DP_GUI_MASTER_CNTL register mask Chad Jablonski
2025-11-03 13:46   ` BALATON Zoltan
2025-11-03  3:36 ` [PATCH v2 5/7] ati-vga: Implement HOST_DATA register writes Chad Jablonski
2025-11-03 13:58   ` BALATON Zoltan
2025-11-04 11:26     ` BALATON Zoltan
2025-11-10 19:53       ` Chad Jablonski
2025-11-03  3:36 ` Chad Jablonski [this message]
2025-11-03 14:03   ` [PATCH v2 6/7] ati-vga: Add expand_colors() helper for monochrome color expansion BALATON Zoltan
2025-11-10 20:20     ` Chad Jablonski
2025-11-03  3:36 ` [PATCH v2 7/7] ati-vga: Implement HOST_DATA blit source with " Chad Jablonski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251103033608.120908-7-chad@jablonski.xyz \
    --to=chad@jablonski.xyz \
    --cc=balaton@eik.bme.hu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).