1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// SPDX-License-Identifier: GPL-2.0 or MIT
/*
* Copyright (c) 2023 Red Hat.
* Author: Jocelyn Falempe <jfalempe@redhat.com>
*/
#include <linux/bits.h>
#include <linux/bug.h>
#include <linux/export.h>
#include <linux/iosys-map.h>
#include <linux/types.h>
#include <drm/drm_fourcc.h>
#include "drm_draw_internal.h"
#include "drm_format_internal.h"
/**
* drm_draw_color_from_xrgb8888 - convert one pixel from xrgb8888 to the desired format
* @color: input color, in xrgb8888 format
* @format: output format
*
* Returns:
* Color in the format specified, casted to u32.
* Or 0 if the format is not supported.
*/
u32 drm_draw_color_from_xrgb8888(u32 color, u32 format)
{
switch (format) {
case DRM_FORMAT_RGB565:
return drm_pixel_xrgb8888_to_rgb565(color);
case DRM_FORMAT_RGBA5551:
return drm_pixel_xrgb8888_to_rgba5551(color);
case DRM_FORMAT_XRGB1555:
return drm_pixel_xrgb8888_to_xrgb1555(color);
case DRM_FORMAT_ARGB1555:
return drm_pixel_xrgb8888_to_argb1555(color);
case DRM_FORMAT_RGB888:
case DRM_FORMAT_XRGB8888:
return color;
case DRM_FORMAT_ARGB8888:
return drm_pixel_xrgb8888_to_argb8888(color);
case DRM_FORMAT_XBGR8888:
return drm_pixel_xrgb8888_to_xbgr8888(color);
case DRM_FORMAT_ABGR8888:
return drm_pixel_xrgb8888_to_abgr8888(color);
case DRM_FORMAT_XRGB2101010:
return drm_pixel_xrgb8888_to_xrgb2101010(color);
case DRM_FORMAT_ARGB2101010:
return drm_pixel_xrgb8888_to_argb2101010(color);
case DRM_FORMAT_ABGR2101010:
return drm_pixel_xrgb8888_to_abgr2101010(color);
default:
WARN_ONCE(1, "Can't convert to %p4cc\n", &format);
return 0;
}
}
EXPORT_SYMBOL(drm_draw_color_from_xrgb8888);
/*
* Blit functions
*/
void drm_draw_blit16(struct iosys_map *dmap, unsigned int dpitch,
const u8 *sbuf8, unsigned int spitch,
unsigned int height, unsigned int width,
unsigned int scale, u16 fg16)
{
unsigned int y, x;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
if (drm_draw_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, fg16);
}
EXPORT_SYMBOL(drm_draw_blit16);
void drm_draw_blit24(struct iosys_map *dmap, unsigned int dpitch,
const u8 *sbuf8, unsigned int spitch,
unsigned int height, unsigned int width,
unsigned int scale, u32 fg32)
{
unsigned int y, x;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
u32 off = y * dpitch + x * 3;
if (drm_draw_is_pixel_fg(sbuf8, spitch, x / scale, y / scale)) {
/* write blue-green-red to output in little endianness */
iosys_map_wr(dmap, off, u8, (fg32 & 0x000000FF) >> 0);
iosys_map_wr(dmap, off + 1, u8, (fg32 & 0x0000FF00) >> 8);
iosys_map_wr(dmap, off + 2, u8, (fg32 & 0x00FF0000) >> 16);
}
}
}
}
EXPORT_SYMBOL(drm_draw_blit24);
void drm_draw_blit32(struct iosys_map *dmap, unsigned int dpitch,
const u8 *sbuf8, unsigned int spitch,
unsigned int height, unsigned int width,
unsigned int scale, u32 fg32)
{
unsigned int y, x;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
if (drm_draw_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, fg32);
}
EXPORT_SYMBOL(drm_draw_blit32);
/*
* Fill functions
*/
void drm_draw_fill16(struct iosys_map *dmap, unsigned int dpitch,
unsigned int height, unsigned int width,
u16 color)
{
unsigned int y, x;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, color);
}
EXPORT_SYMBOL(drm_draw_fill16);
void drm_draw_fill24(struct iosys_map *dmap, unsigned int dpitch,
unsigned int height, unsigned int width,
u16 color)
{
unsigned int y, x;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
unsigned int off = y * dpitch + x * 3;
/* write blue-green-red to output in little endianness */
iosys_map_wr(dmap, off, u8, (color & 0x000000FF) >> 0);
iosys_map_wr(dmap, off + 1, u8, (color & 0x0000FF00) >> 8);
iosys_map_wr(dmap, off + 2, u8, (color & 0x00FF0000) >> 16);
}
}
}
EXPORT_SYMBOL(drm_draw_fill24);
void drm_draw_fill32(struct iosys_map *dmap, unsigned int dpitch,
unsigned int height, unsigned int width,
u32 color)
{
unsigned int y, x;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, color);
}
EXPORT_SYMBOL(drm_draw_fill32);
|