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