]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/color-mgmt: Prepare for RGB332 palettes
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 14 Jul 2025 15:13:05 +0000 (17:13 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Tue, 26 Aug 2025 07:54:18 +0000 (09:54 +0200)
Add helper drm_crtc_fill_palette_332(), which fills palettes with
RGB332 color data. Each color in RGB332 format serves as an index
into an 8-bit palette that stores the corresponding component-based
colors.

Vesadrm will use the new helper to emulate RGB formats on top of
framebuffers in C8 format.

v2:
- add comments on bit operations (Javier)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250714151513.309475-6-tzimmermann@suse.de
drivers/gpu/drm/drm_color_mgmt.c
include/drm/drm_color_mgmt.h

index 37a3270bc3c2d7546dfe4e35ec8e7290b8324c9a..131c1c9ae92fc265bf0d56c80e3da814cce8116d 100644 (file)
@@ -817,6 +817,40 @@ void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *
 }
 EXPORT_SYMBOL(drm_crtc_load_palette_8);
 
+static void fill_palette_332(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
+                            drm_crtc_set_lut_func set_palette)
+{
+       unsigned int i = (r << 5) | (g << 2) | b; /* 8-bit palette index */
+
+       /* Expand R (3-bit) G (3-bit) and B (2-bit) values to 16-bit values */
+       r = (r << 13) | (r << 10) | (r << 7) | (r << 4) | (r << 1) | (r >> 2);
+       g = (g << 13) | (g << 10) | (g << 7) | (g << 4) | (g << 1) | (g >> 2);
+       b = (b << 14) | (b << 12) | (b << 10) | (b << 8) | (b << 6) | (b << 4) | (b << 2) | b;
+
+       set_palette(crtc, i, r, g, b);
+}
+
+/**
+ * drm_crtc_fill_palette_332 - Programs a default palette for R332-like formats
+ * @crtc: The displaying CRTC
+ * @set_palette: Callback for programming the hardware gamma LUT
+ *
+ * Programs an RGB332 palette to hardware.
+ */
+void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette)
+{
+       unsigned int r, g, b;
+
+       /* Limits of 8-8-4 are the maximum number of values for each channel. */
+       for (r = 0; r < 8; ++r) {
+               for (g = 0; g < 8; ++g) {
+                       for (b = 0; b < 4; ++b)
+                               fill_palette_332(crtc, r, g, b, set_palette);
+               }
+       }
+}
+EXPORT_SYMBOL(drm_crtc_fill_palette_332);
+
 static void fill_palette_8(struct drm_crtc *crtc, unsigned int i,
                           drm_crtc_set_lut_func set_palette)
 {
index 6cb577f6dba6ad574103bcb584a29c21df7f7217..eccb71ab335ad28014885b6b1c9c901704144fa3 100644 (file)
@@ -143,6 +143,7 @@ void drm_crtc_fill_gamma_555(struct drm_crtc *crtc, drm_crtc_set_lut_func set_ga
 void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *lut,
                             drm_crtc_set_lut_func set_palette);
 
+void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
 void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
 
 #endif