Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <bmp_layout.h> |
| 8 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 10 | #include <mapmem.h> |
Anatolij Gustschin | 96d82f6 | 2018-12-01 15:30:08 +0100 | [diff] [blame] | 11 | #include <splash.h> |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 12 | #include <video.h> |
| 13 | #include <watchdog.h> |
| 14 | #include <asm/unaligned.h> |
| 15 | |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 16 | #define BMP_RLE8_ESCAPE 0 |
| 17 | #define BMP_RLE8_EOL 0 |
| 18 | #define BMP_RLE8_EOBMP 1 |
| 19 | #define BMP_RLE8_DELTA 2 |
| 20 | |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 21 | /** |
| 22 | * get_bmp_col_16bpp() - Convert a colour-table entry into a 16bpp pixel value |
| 23 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 24 | * Return: value to write to the 16bpp frame buffer for this palette entry |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 25 | */ |
| 26 | static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte) |
| 27 | { |
| 28 | return ((cte.red << 8) & 0xf800) | |
| 29 | ((cte.green << 3) & 0x07e0) | |
| 30 | ((cte.blue >> 3) & 0x001f); |
| 31 | } |
| 32 | |
| 33 | /** |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 34 | * get_bmp_col_x2r10g10b10() - Convert a colour-table entry into a x2r10g10b10 pixel value |
| 35 | * |
| 36 | * Return: value to write to the x2r10g10b10 frame buffer for this palette entry |
| 37 | */ |
| 38 | static u32 get_bmp_col_x2r10g10b10(struct bmp_color_table_entry *cte) |
| 39 | { |
| 40 | return ((cte->red << 22U) | |
| 41 | (cte->green << 12U) | |
| 42 | (cte->blue << 2U)); |
| 43 | } |
| 44 | |
| 45 | /** |
Michal Simek | f6de01d | 2023-05-17 10:42:08 +0200 | [diff] [blame] | 46 | * get_bmp_col_rgba8888() - Convert a colour-table entry into a rgba8888 pixel value |
| 47 | * |
| 48 | * Return: value to write to the rgba8888 frame buffer for this palette entry |
| 49 | */ |
| 50 | static u32 get_bmp_col_rgba8888(struct bmp_color_table_entry *cte) |
| 51 | { |
| 52 | return ((cte->red) | |
| 53 | (cte->green << 8U) | |
| 54 | (cte->blue << 16U) | 0xff << 24U); |
| 55 | } |
| 56 | |
| 57 | /** |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 58 | * write_pix8() - Write a pixel from a BMP image into the framebuffer |
| 59 | * |
| 60 | * This handles frame buffers with 8, 16, 24 or 32 bits per pixel |
| 61 | * |
| 62 | * @fb: Place in frame buffer to update |
| 63 | * @bpix: Frame buffer bits-per-pixel, which controls how many bytes are written |
| 64 | * @palette: BMP palette table |
| 65 | * @bmap: Pointer to BMP bitmap position to write. This contains a single byte |
| 66 | * which is either written directly (bpix == 8) or used to look up the |
| 67 | * palette to get a colour to write |
| 68 | */ |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 69 | static void write_pix8(u8 *fb, uint bpix, enum video_format eformat, |
| 70 | struct bmp_color_table_entry *palette, u8 *bmap) |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 71 | { |
| 72 | if (bpix == 8) { |
| 73 | *fb++ = *bmap; |
| 74 | } else if (bpix == 16) { |
| 75 | *(u16 *)fb = get_bmp_col_16bpp(palette[*bmap]); |
| 76 | } else { |
| 77 | /* Only support big endian */ |
| 78 | struct bmp_color_table_entry *cte = &palette[*bmap]; |
| 79 | |
| 80 | if (bpix == 24) { |
| 81 | *fb++ = cte->red; |
| 82 | *fb++ = cte->green; |
| 83 | *fb++ = cte->blue; |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 84 | } else if (eformat == VIDEO_X2R10G10B10) { |
| 85 | *(u32 *)fb = get_bmp_col_x2r10g10b10(cte); |
Michal Simek | f6de01d | 2023-05-17 10:42:08 +0200 | [diff] [blame] | 86 | } else if (eformat == VIDEO_RGBA8888) { |
| 87 | *(u32 *)fb = get_bmp_col_rgba8888(cte); |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 88 | } else { |
| 89 | *fb++ = cte->blue; |
| 90 | *fb++ = cte->green; |
| 91 | *fb++ = cte->red; |
| 92 | *fb++ = 0; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 97 | static void draw_unencoded_bitmap(u8 **fbp, uint bpix, |
| 98 | enum video_format eformat, uchar *bmap, |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 99 | struct bmp_color_table_entry *palette, |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 100 | int cnt) |
| 101 | { |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 102 | u8 *fb = *fbp; |
| 103 | |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 104 | while (cnt > 0) { |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 105 | write_pix8(fb, bpix, eformat, palette, bmap++); |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 106 | fb += bpix / 8; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 107 | cnt--; |
| 108 | } |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 109 | *fbp = fb; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 112 | static void draw_encoded_bitmap(u8 **fbp, uint bpix, enum video_format eformat, |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 113 | struct bmp_color_table_entry *palette, u8 *bmap, |
| 114 | int cnt) |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 115 | { |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 116 | u8 *fb = *fbp; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 117 | |
| 118 | while (cnt > 0) { |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 119 | write_pix8(fb, bpix, eformat, palette, bmap); |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 120 | fb += bpix / 8; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 121 | cnt--; |
| 122 | } |
| 123 | *fbp = fb; |
| 124 | } |
| 125 | |
| 126 | static void video_display_rle8_bitmap(struct udevice *dev, |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 127 | struct bmp_image *bmp, uint bpix, |
| 128 | struct bmp_color_table_entry *palette, |
Patrice Chotard | ca2c694 | 2019-11-20 14:11:16 +0100 | [diff] [blame] | 129 | uchar *fb, int x_off, int y_off, |
| 130 | ulong width, ulong height) |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 131 | { |
| 132 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 133 | uchar *bmap; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 134 | ulong cnt, runlen; |
| 135 | int x, y; |
| 136 | int decode = 1; |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 137 | uint bytes_per_pixel = bpix / 8; |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 138 | enum video_format eformat = priv->format; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 139 | |
| 140 | debug("%s\n", __func__); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 141 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
| 142 | |
| 143 | x = 0; |
| 144 | y = height - 1; |
| 145 | |
| 146 | while (decode) { |
| 147 | if (bmap[0] == BMP_RLE8_ESCAPE) { |
| 148 | switch (bmap[1]) { |
| 149 | case BMP_RLE8_EOL: |
| 150 | /* end of line */ |
| 151 | bmap += 2; |
| 152 | x = 0; |
| 153 | y--; |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 154 | fb -= width * bytes_per_pixel + |
| 155 | priv->line_length; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 156 | break; |
| 157 | case BMP_RLE8_EOBMP: |
| 158 | /* end of bitmap */ |
| 159 | decode = 0; |
| 160 | break; |
| 161 | case BMP_RLE8_DELTA: |
| 162 | /* delta run */ |
| 163 | x += bmap[2]; |
| 164 | y -= bmap[3]; |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 165 | fb = (uchar *)(priv->fb + |
| 166 | (y + y_off - 1) * priv->line_length + |
| 167 | (x + x_off) * bytes_per_pixel); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 168 | bmap += 4; |
| 169 | break; |
| 170 | default: |
| 171 | /* unencoded run */ |
| 172 | runlen = bmap[1]; |
| 173 | bmap += 2; |
| 174 | if (y < height) { |
| 175 | if (x < width) { |
| 176 | if (x + runlen > width) |
| 177 | cnt = width - x; |
| 178 | else |
| 179 | cnt = runlen; |
| 180 | draw_unencoded_bitmap( |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 181 | &fb, bpix, eformat, |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 182 | bmap, palette, cnt); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 183 | } |
| 184 | x += runlen; |
| 185 | } |
| 186 | bmap += runlen; |
| 187 | if (runlen & 1) |
| 188 | bmap++; |
| 189 | } |
| 190 | } else { |
| 191 | /* encoded run */ |
| 192 | if (y < height) { |
| 193 | runlen = bmap[0]; |
| 194 | if (x < width) { |
| 195 | /* aggregate the same code */ |
| 196 | while (bmap[0] == 0xff && |
| 197 | bmap[2] != BMP_RLE8_ESCAPE && |
| 198 | bmap[1] == bmap[3]) { |
| 199 | runlen += bmap[2]; |
| 200 | bmap += 2; |
| 201 | } |
| 202 | if (x + runlen > width) |
| 203 | cnt = width - x; |
| 204 | else |
| 205 | cnt = runlen; |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 206 | draw_encoded_bitmap(&fb, bpix, eformat, |
| 207 | palette, &bmap[1], |
| 208 | cnt); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 209 | } |
| 210 | x += runlen; |
| 211 | } |
| 212 | bmap += 2; |
| 213 | } |
| 214 | } |
| 215 | } |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 216 | |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 217 | /** |
| 218 | * video_splash_align_axis() - Align a single coordinate |
| 219 | * |
| 220 | *- if a coordinate is 0x7fff then the image will be centred in |
| 221 | * that direction |
| 222 | *- if a coordinate is -ve then it will be offset to the |
| 223 | * left/top of the centre by that many pixels |
| 224 | *- if a coordinate is positive it will be used unchnaged. |
| 225 | * |
| 226 | * @axis: Input and output coordinate |
| 227 | * @panel_size: Size of panel in pixels for that axis |
| 228 | * @picture_size: Size of bitmap in pixels for that axis |
| 229 | */ |
| 230 | static void video_splash_align_axis(int *axis, unsigned long panel_size, |
| 231 | unsigned long picture_size) |
| 232 | { |
Patrice Chotard | 1ebf285 | 2019-11-20 14:11:15 +0100 | [diff] [blame] | 233 | long panel_picture_delta = panel_size - picture_size; |
| 234 | long axis_alignment; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 235 | |
| 236 | if (*axis == BMP_ALIGN_CENTER) |
| 237 | axis_alignment = panel_picture_delta / 2; |
| 238 | else if (*axis < 0) |
| 239 | axis_alignment = panel_picture_delta + *axis + 1; |
| 240 | else |
| 241 | return; |
| 242 | |
| 243 | *axis = max(0, (int)axis_alignment); |
| 244 | } |
| 245 | |
Simon Glass | e90322f | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 246 | void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp, |
| 247 | uint *bpixp) |
| 248 | { |
| 249 | struct bmp_image *bmp = bmp_image; |
| 250 | |
| 251 | *widthp = get_unaligned_le32(&bmp->header.width); |
| 252 | *heightp = get_unaligned_le32(&bmp->header.height); |
| 253 | *bpixp = get_unaligned_le16(&bmp->header.bit_count); |
| 254 | } |
| 255 | |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 256 | int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, |
| 257 | bool align) |
| 258 | { |
| 259 | struct video_priv *priv = dev_get_uclass_priv(dev); |
Simon Glass | 2b80b4e | 2016-01-30 15:45:16 -0700 | [diff] [blame] | 260 | int i, j; |
Simon Glass | 2b1412c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 261 | uchar *start, *fb; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 262 | struct bmp_image *bmp = map_sysmem(bmp_image, 0); |
| 263 | uchar *bmap; |
| 264 | ushort padded_width; |
| 265 | unsigned long width, height, byte_width; |
| 266 | unsigned long pwidth = priv->xsize; |
| 267 | unsigned colours, bpix, bmp_bpix; |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 268 | enum video_format eformat; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 269 | struct bmp_color_table_entry *palette; |
| 270 | int hdr_size; |
Simon Glass | 2b1412c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 271 | int ret; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 272 | |
| 273 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
| 274 | bmp->header.signature[1] == 'M')) { |
| 275 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
| 276 | |
| 277 | return -EINVAL; |
| 278 | } |
| 279 | |
Simon Glass | e90322f | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 280 | video_bmp_get_info(bmp, &width, &height, &bmp_bpix); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 281 | hdr_size = get_unaligned_le16(&bmp->header.size); |
| 282 | debug("hdr_size=%d, bmp_bpix=%d\n", hdr_size, bmp_bpix); |
| 283 | palette = (void *)bmp + 14 + hdr_size; |
| 284 | |
| 285 | colours = 1 << bmp_bpix; |
| 286 | |
| 287 | bpix = VNBITS(priv->bpix); |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 288 | eformat = priv->format; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 289 | |
| 290 | if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
| 291 | printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 292 | bpix, bmp_bpix); |
| 293 | |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
| 297 | /* |
Stefan Roese | e257103 | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 298 | * We support displaying 8bpp and 24bpp BMPs on 16bpp LCDs |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 299 | * and displaying 24bpp BMPs on 32bpp LCDs |
Stefan Roese | e257103 | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 300 | */ |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 301 | if (bpix != bmp_bpix && |
| 302 | !(bmp_bpix == 8 && bpix == 16) && |
Ye Li | bab68b2 | 2020-06-10 02:52:23 -0700 | [diff] [blame] | 303 | !(bmp_bpix == 8 && bpix == 24) && |
| 304 | !(bmp_bpix == 8 && bpix == 32) && |
Stefan Roese | e257103 | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 305 | !(bmp_bpix == 24 && bpix == 16) && |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 306 | !(bmp_bpix == 24 && bpix == 32)) { |
| 307 | printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
Simon Glass | e90322f | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 308 | bpix, colours); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 309 | return -EPERM; |
| 310 | } |
| 311 | |
| 312 | debug("Display-bmp: %d x %d with %d colours, display %d\n", |
| 313 | (int)width, (int)height, (int)colours, 1 << bpix); |
| 314 | |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 315 | padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
| 316 | |
| 317 | if (align) { |
| 318 | video_splash_align_axis(&x, priv->xsize, width); |
| 319 | video_splash_align_axis(&y, priv->ysize, height); |
| 320 | } |
| 321 | |
| 322 | if ((x + width) > pwidth) |
| 323 | width = pwidth - x; |
| 324 | if ((y + height) > priv->ysize) |
| 325 | height = priv->ysize - y; |
| 326 | |
| 327 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
Simon Glass | 2b1412c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 328 | start = (uchar *)(priv->fb + |
| 329 | (y + height) * priv->line_length + x * bpix / 8); |
| 330 | |
| 331 | /* Move back to the final line to be drawn */ |
| 332 | fb = start - priv->line_length; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 333 | |
| 334 | switch (bmp_bpix) { |
| 335 | case 1: |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 336 | case 8: |
Nikhil M Jain | 86fbee6 | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 337 | if (CONFIG_IS_ENABLED(VIDEO_BMP_RLE8)) { |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 338 | u32 compression = get_unaligned_le32( |
| 339 | &bmp->header.compression); |
| 340 | debug("compressed %d %d\n", compression, BMP_BI_RLE8); |
| 341 | if (compression == BMP_BI_RLE8) { |
| 342 | video_display_rle8_bitmap(dev, bmp, bpix, palette, fb, |
| 343 | x, y, width, height); |
| 344 | break; |
| 345 | } |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 346 | } |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 347 | |
| 348 | /* Not compressed */ |
Ye Li | bab68b2 | 2020-06-10 02:52:23 -0700 | [diff] [blame] | 349 | byte_width = width * (bpix / 8); |
| 350 | if (!byte_width) |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 351 | byte_width = width; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 352 | |
| 353 | for (i = 0; i < height; ++i) { |
Stefan Roese | 29caf93 | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 354 | schedule(); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 355 | for (j = 0; j < width; j++) { |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 356 | write_pix8(fb, bpix, eformat, palette, bmap); |
Simon Glass | 51f92c1 | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 357 | bmap++; |
| 358 | fb += bpix / 8; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 359 | } |
| 360 | bmap += (padded_width - width); |
| 361 | fb -= byte_width + priv->line_length; |
| 362 | } |
| 363 | break; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 364 | case 16: |
Nikhil M Jain | 86fbee6 | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 365 | if (CONFIG_IS_ENABLED(BMP_16BPP)) { |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 366 | for (i = 0; i < height; ++i) { |
Stefan Roese | 29caf93 | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 367 | schedule(); |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 368 | for (j = 0; j < width; j++) { |
Simon Glass | f5aa93e | 2021-11-19 13:23:57 -0700 | [diff] [blame] | 369 | *fb++ = *bmap++; |
| 370 | *fb++ = *bmap++; |
Stefan Roese | e257103 | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 371 | } |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 372 | bmap += (padded_width - width); |
| 373 | fb -= width * 2 + priv->line_length; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 374 | } |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 375 | } |
| 376 | break; |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 377 | case 24: |
Nikhil M Jain | 86fbee6 | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 378 | if (CONFIG_IS_ENABLED(BMP_24BPP)) { |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 379 | for (i = 0; i < height; ++i) { |
| 380 | for (j = 0; j < width; j++) { |
| 381 | if (bpix == 16) { |
| 382 | /* 16bit 565RGB format */ |
| 383 | *(u16 *)fb = ((bmap[2] >> 3) |
| 384 | << 11) | |
| 385 | ((bmap[1] >> 2) << 5) | |
| 386 | (bmap[0] >> 3); |
| 387 | bmap += 3; |
| 388 | fb += 2; |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 389 | } else if (eformat == VIDEO_X2R10G10B10) { |
| 390 | u32 pix; |
| 391 | |
| 392 | pix = *bmap++ << 2U; |
| 393 | pix |= *bmap++ << 12U; |
| 394 | pix |= *bmap++ << 22U; |
| 395 | *fb++ = pix & 0xff; |
| 396 | *fb++ = (pix >> 8) & 0xff; |
| 397 | *fb++ = (pix >> 16) & 0xff; |
| 398 | *fb++ = pix >> 24; |
Michal Simek | f6de01d | 2023-05-17 10:42:08 +0200 | [diff] [blame] | 399 | } else if (eformat == VIDEO_RGBA8888) { |
| 400 | u32 pix; |
| 401 | |
| 402 | pix = *bmap++ << 8U; /* blue */ |
| 403 | pix |= *bmap++ << 16U; /* green */ |
| 404 | pix |= *bmap++ << 24U; /* red */ |
| 405 | |
| 406 | *fb++ = (pix >> 24) & 0xff; |
| 407 | *fb++ = (pix >> 16) & 0xff; |
| 408 | *fb++ = (pix >> 8) & 0xff; |
| 409 | *fb++ = 0xff; |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 410 | } else { |
| 411 | *fb++ = *bmap++; |
| 412 | *fb++ = *bmap++; |
| 413 | *fb++ = *bmap++; |
| 414 | *fb++ = 0; |
| 415 | } |
| 416 | } |
| 417 | fb -= priv->line_length + width * (bpix / 8); |
| 418 | bmap += (padded_width - width); |
| 419 | } |
| 420 | } |
| 421 | break; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 422 | case 32: |
Nikhil M Jain | 86fbee6 | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 423 | if (CONFIG_IS_ENABLED(BMP_32BPP)) { |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 424 | for (i = 0; i < height; ++i) { |
| 425 | for (j = 0; j < width; j++) { |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 426 | if (eformat == VIDEO_X2R10G10B10) { |
| 427 | u32 pix; |
| 428 | |
| 429 | pix = *bmap++ << 2U; |
| 430 | pix |= *bmap++ << 12U; |
| 431 | pix |= *bmap++ << 22U; |
| 432 | pix |= (*bmap++ >> 6) << 30U; |
| 433 | *fb++ = pix & 0xff; |
| 434 | *fb++ = (pix >> 8) & 0xff; |
| 435 | *fb++ = (pix >> 16) & 0xff; |
| 436 | *fb++ = pix >> 24; |
Michal Simek | f6de01d | 2023-05-17 10:42:08 +0200 | [diff] [blame] | 437 | } else if (eformat == VIDEO_RGBA8888) { |
| 438 | u32 pix; |
| 439 | |
| 440 | pix = *bmap++ << 8U; /* blue */ |
| 441 | pix |= *bmap++ << 16U; /* green */ |
| 442 | pix |= *bmap++ << 24U; /* red */ |
| 443 | bmap++; |
| 444 | *fb++ = (pix >> 24) & 0xff; |
| 445 | *fb++ = (pix >> 16) & 0xff; |
| 446 | *fb++ = (pix >> 8) & 0xff; |
| 447 | *fb++ = 0xff; /* opacity */ |
Janne Grunau | 515a2f7 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 448 | } else { |
| 449 | *fb++ = *bmap++; |
| 450 | *fb++ = *bmap++; |
| 451 | *fb++ = *bmap++; |
| 452 | *fb++ = *bmap++; |
| 453 | } |
Simon Glass | cd4fb0f | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 454 | } |
| 455 | fb -= priv->line_length + width * (bpix / 8); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 456 | } |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 457 | } |
| 458 | break; |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 459 | default: |
| 460 | break; |
| 461 | }; |
| 462 | |
Simon Glass | 2b1412c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 463 | /* Find the position of the top left of the image in the framebuffer */ |
| 464 | fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8); |
| 465 | ret = video_sync_copy(dev, start, fb); |
| 466 | if (ret) |
| 467 | return log_ret(ret); |
| 468 | |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 469 | return video_sync(dev, false); |
Simon Glass | b01c792 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 470 | } |