Skip to content

Commit 7ff6117

Browse files
committed
drm/color-mgmt: Prepare for RGB332 palettes
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
1 parent 061963c commit 7ff6117

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

drivers/gpu/drm/drm_color_mgmt.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,40 @@ void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *
817817
}
818818
EXPORT_SYMBOL(drm_crtc_load_palette_8);
819819

820+
static void fill_palette_332(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
821+
drm_crtc_set_lut_func set_palette)
822+
{
823+
unsigned int i = (r << 5) | (g << 2) | b; /* 8-bit palette index */
824+
825+
/* Expand R (3-bit) G (3-bit) and B (2-bit) values to 16-bit values */
826+
r = (r << 13) | (r << 10) | (r << 7) | (r << 4) | (r << 1) | (r >> 2);
827+
g = (g << 13) | (g << 10) | (g << 7) | (g << 4) | (g << 1) | (g >> 2);
828+
b = (b << 14) | (b << 12) | (b << 10) | (b << 8) | (b << 6) | (b << 4) | (b << 2) | b;
829+
830+
set_palette(crtc, i, r, g, b);
831+
}
832+
833+
/**
834+
* drm_crtc_fill_palette_332 - Programs a default palette for R332-like formats
835+
* @crtc: The displaying CRTC
836+
* @set_palette: Callback for programming the hardware gamma LUT
837+
*
838+
* Programs an RGB332 palette to hardware.
839+
*/
840+
void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette)
841+
{
842+
unsigned int r, g, b;
843+
844+
/* Limits of 8-8-4 are the maximum number of values for each channel. */
845+
for (r = 0; r < 8; ++r) {
846+
for (g = 0; g < 8; ++g) {
847+
for (b = 0; b < 4; ++b)
848+
fill_palette_332(crtc, r, g, b, set_palette);
849+
}
850+
}
851+
}
852+
EXPORT_SYMBOL(drm_crtc_fill_palette_332);
853+
820854
static void fill_palette_8(struct drm_crtc *crtc, unsigned int i,
821855
drm_crtc_set_lut_func set_palette)
822856
{

include/drm/drm_color_mgmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void drm_crtc_fill_gamma_555(struct drm_crtc *crtc, drm_crtc_set_lut_func set_ga
143143
void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *lut,
144144
drm_crtc_set_lut_func set_palette);
145145

146+
void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
146147
void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
147148

148149
#endif

0 commit comments

Comments
 (0)