Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 68b2627 | 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 | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 10 | #include <mapmem.h> |
Anatolij Gustschin | 410f096 | 2018-12-01 15:30:08 +0100 | [diff] [blame] | 11 | #include <splash.h> |
Simon Glass | 68b2627 | 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 | 68b2627 | 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 | 998e16a | 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 | 47b4c02 | 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 | 998e16a | 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 | 8296d14 | 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 | 998e16a | 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 | 8296d14 | 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 | 998e16a | 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 | 8296d14 | 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 | 998e16a | 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 | 8296d14 | 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 | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 85 | struct bmp_color_table_entry *palette, |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 86 | int cnt) |
| 87 | { |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 88 | u8 *fb = *fbp; |
| 89 | |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 90 | while (cnt > 0) { |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 91 | write_pix8(fb, bpix, eformat, palette, bmap++); |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 92 | fb += bpix / 8; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 93 | cnt--; |
| 94 | } |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 95 | *fbp = fb; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Janne Grunau | 8296d14 | 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 | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 99 | struct bmp_color_table_entry *palette, u8 *bmap, |
| 100 | int cnt) |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 101 | { |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 102 | u8 *fb = *fbp; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 103 | |
| 104 | while (cnt > 0) { |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 105 | write_pix8(fb, bpix, eformat, palette, bmap); |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 106 | fb += bpix / 8; |
Simon Glass | 68b2627 | 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 | 490bb99 | 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 | cb30f7d | 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 | 68b2627 | 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 | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 120 | ulong cnt, runlen; |
| 121 | int x, y; |
| 122 | int decode = 1; |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 123 | uint bytes_per_pixel = bpix / 8; |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 124 | enum video_format eformat = priv->format; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 125 | |
| 126 | debug("%s\n", __func__); |
Simon Glass | 68b2627 | 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 | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 140 | fb -= width * bytes_per_pixel + |
| 141 | priv->line_length; |
Simon Glass | 68b2627 | 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 | 490bb99 | 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 | 68b2627 | 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 | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 167 | &fb, bpix, eformat, |
Simon Glass | 490bb99 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 168 | bmap, palette, cnt); |
Simon Glass | 68b2627 | 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 | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 192 | draw_encoded_bitmap(&fb, bpix, eformat, |
| 193 | palette, &bmap[1], |
| 194 | cnt); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 195 | } |
| 196 | x += runlen; |
| 197 | } |
| 198 | bmap += 2; |
| 199 | } |
| 200 | } |
| 201 | } |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 202 | |
Simon Glass | 68b2627 | 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 | 066eace | 2019-11-20 14:11:15 +0100 | [diff] [blame] | 219 | long panel_picture_delta = panel_size - picture_size; |
| 220 | long axis_alignment; |
Simon Glass | 68b2627 | 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 | 7e14804 | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 232 | void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp, |
| 233 | uint *bpixp) |
| 234 | { |
| 235 | struct bmp_image *bmp = bmp_image; |
| 236 | |
| 237 | *widthp = get_unaligned_le32(&bmp->header.width); |
| 238 | *heightp = get_unaligned_le32(&bmp->header.height); |
| 239 | *bpixp = get_unaligned_le16(&bmp->header.bit_count); |
| 240 | } |
| 241 | |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 242 | int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, |
| 243 | bool align) |
| 244 | { |
| 245 | struct video_priv *priv = dev_get_uclass_priv(dev); |
Simon Glass | 1f47573 | 2016-01-30 15:45:16 -0700 | [diff] [blame] | 246 | int i, j; |
Simon Glass | 4761c8c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 247 | uchar *start, *fb; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 248 | struct bmp_image *bmp = map_sysmem(bmp_image, 0); |
| 249 | uchar *bmap; |
| 250 | ushort padded_width; |
| 251 | unsigned long width, height, byte_width; |
| 252 | unsigned long pwidth = priv->xsize; |
| 253 | unsigned colours, bpix, bmp_bpix; |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 254 | enum video_format eformat; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 255 | struct bmp_color_table_entry *palette; |
| 256 | int hdr_size; |
Simon Glass | 4761c8c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 257 | int ret; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 258 | |
| 259 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
| 260 | bmp->header.signature[1] == 'M')) { |
| 261 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
| 262 | |
| 263 | return -EINVAL; |
| 264 | } |
| 265 | |
Simon Glass | 7e14804 | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 266 | video_bmp_get_info(bmp, &width, &height, &bmp_bpix); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 267 | hdr_size = get_unaligned_le16(&bmp->header.size); |
| 268 | debug("hdr_size=%d, bmp_bpix=%d\n", hdr_size, bmp_bpix); |
| 269 | palette = (void *)bmp + 14 + hdr_size; |
| 270 | |
| 271 | colours = 1 << bmp_bpix; |
| 272 | |
| 273 | bpix = VNBITS(priv->bpix); |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 274 | eformat = priv->format; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 275 | |
| 276 | if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
| 277 | printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 278 | bpix, bmp_bpix); |
| 279 | |
| 280 | return -EINVAL; |
| 281 | } |
| 282 | |
| 283 | /* |
Stefan Roese | 7ee599e | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 284 | * We support displaying 8bpp and 24bpp BMPs on 16bpp LCDs |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 285 | * and displaying 24bpp BMPs on 32bpp LCDs |
Stefan Roese | 7ee599e | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 286 | */ |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 287 | if (bpix != bmp_bpix && |
| 288 | !(bmp_bpix == 8 && bpix == 16) && |
Ye Li | b5c864d | 2020-06-10 02:52:23 -0700 | [diff] [blame] | 289 | !(bmp_bpix == 8 && bpix == 24) && |
| 290 | !(bmp_bpix == 8 && bpix == 32) && |
Stefan Roese | 7ee599e | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 291 | !(bmp_bpix == 24 && bpix == 16) && |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 292 | !(bmp_bpix == 24 && bpix == 32)) { |
| 293 | printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
Simon Glass | 7e14804 | 2022-10-06 08:36:17 -0600 | [diff] [blame] | 294 | bpix, colours); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 295 | return -EPERM; |
| 296 | } |
| 297 | |
| 298 | debug("Display-bmp: %d x %d with %d colours, display %d\n", |
| 299 | (int)width, (int)height, (int)colours, 1 << bpix); |
| 300 | |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 301 | padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
| 302 | |
| 303 | if (align) { |
| 304 | video_splash_align_axis(&x, priv->xsize, width); |
| 305 | video_splash_align_axis(&y, priv->ysize, height); |
| 306 | } |
| 307 | |
| 308 | if ((x + width) > pwidth) |
| 309 | width = pwidth - x; |
| 310 | if ((y + height) > priv->ysize) |
| 311 | height = priv->ysize - y; |
| 312 | |
| 313 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
Simon Glass | 4761c8c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 314 | start = (uchar *)(priv->fb + |
| 315 | (y + height) * priv->line_length + x * bpix / 8); |
| 316 | |
| 317 | /* Move back to the final line to be drawn */ |
| 318 | fb = start - priv->line_length; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 319 | |
| 320 | switch (bmp_bpix) { |
| 321 | case 1: |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 322 | case 8: |
| 323 | if (IS_ENABLED(CONFIG_VIDEO_BMP_RLE8)) { |
| 324 | u32 compression = get_unaligned_le32( |
| 325 | &bmp->header.compression); |
| 326 | debug("compressed %d %d\n", compression, BMP_BI_RLE8); |
| 327 | if (compression == BMP_BI_RLE8) { |
| 328 | video_display_rle8_bitmap(dev, bmp, bpix, palette, fb, |
| 329 | x, y, width, height); |
| 330 | break; |
| 331 | } |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 332 | } |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 333 | |
| 334 | /* Not compressed */ |
Ye Li | b5c864d | 2020-06-10 02:52:23 -0700 | [diff] [blame] | 335 | byte_width = width * (bpix / 8); |
| 336 | if (!byte_width) |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 337 | byte_width = width; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 338 | |
| 339 | for (i = 0; i < height; ++i) { |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 340 | schedule(); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 341 | for (j = 0; j < width; j++) { |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 342 | write_pix8(fb, bpix, eformat, palette, bmap); |
Simon Glass | 998e16a | 2021-11-19 13:23:54 -0700 | [diff] [blame] | 343 | bmap++; |
| 344 | fb += bpix / 8; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 345 | } |
| 346 | bmap += (padded_width - width); |
| 347 | fb -= byte_width + priv->line_length; |
| 348 | } |
| 349 | break; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 350 | case 16: |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 351 | if (IS_ENABLED(CONFIG_BMP_16BPP)) { |
| 352 | for (i = 0; i < height; ++i) { |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 353 | schedule(); |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 354 | for (j = 0; j < width; j++) { |
| 355 | *fb++ = *bmap++; |
| 356 | *fb++ = *bmap++; |
| 357 | } |
| 358 | bmap += (padded_width - width); |
| 359 | fb -= width * 2 + priv->line_length; |
Simon Glass | aa662a6 | 2021-11-19 13:23:53 -0700 | [diff] [blame] | 360 | } |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 361 | } |
| 362 | break; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 363 | case 24: |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 364 | if (IS_ENABLED(CONFIG_BMP_24BPP)) { |
| 365 | for (i = 0; i < height; ++i) { |
| 366 | for (j = 0; j < width; j++) { |
| 367 | if (bpix == 16) { |
| 368 | /* 16bit 565RGB format */ |
| 369 | *(u16 *)fb = ((bmap[2] >> 3) |
| 370 | << 11) | |
| 371 | ((bmap[1] >> 2) << 5) | |
| 372 | (bmap[0] >> 3); |
| 373 | bmap += 3; |
| 374 | fb += 2; |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 375 | } else if (eformat == VIDEO_X2R10G10B10) { |
| 376 | u32 pix; |
| 377 | |
| 378 | pix = *bmap++ << 2U; |
| 379 | pix |= *bmap++ << 12U; |
| 380 | pix |= *bmap++ << 22U; |
| 381 | *fb++ = pix & 0xff; |
| 382 | *fb++ = (pix >> 8) & 0xff; |
| 383 | *fb++ = (pix >> 16) & 0xff; |
| 384 | *fb++ = pix >> 24; |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 385 | } else { |
| 386 | *fb++ = *bmap++; |
| 387 | *fb++ = *bmap++; |
| 388 | *fb++ = *bmap++; |
| 389 | *fb++ = 0; |
| 390 | } |
Stefan Roese | 7ee599e | 2019-01-30 08:54:12 +0100 | [diff] [blame] | 391 | } |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 392 | fb -= priv->line_length + width * (bpix / 8); |
| 393 | bmap += (padded_width - width); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 394 | } |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 395 | } |
| 396 | break; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 397 | case 32: |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 398 | if (IS_ENABLED(CONFIG_BMP_32BPP)) { |
| 399 | for (i = 0; i < height; ++i) { |
| 400 | for (j = 0; j < width; j++) { |
Janne Grunau | 8296d14 | 2022-02-09 22:16:22 +0100 | [diff] [blame] | 401 | if (eformat == VIDEO_X2R10G10B10) { |
| 402 | u32 pix; |
| 403 | |
| 404 | pix = *bmap++ << 2U; |
| 405 | pix |= *bmap++ << 12U; |
| 406 | pix |= *bmap++ << 22U; |
| 407 | pix |= (*bmap++ >> 6) << 30U; |
| 408 | *fb++ = pix & 0xff; |
| 409 | *fb++ = (pix >> 8) & 0xff; |
| 410 | *fb++ = (pix >> 16) & 0xff; |
| 411 | *fb++ = pix >> 24; |
| 412 | } else { |
| 413 | *fb++ = *bmap++; |
| 414 | *fb++ = *bmap++; |
| 415 | *fb++ = *bmap++; |
| 416 | *fb++ = *bmap++; |
| 417 | } |
Simon Glass | 6149470 | 2021-11-19 13:24:00 -0700 | [diff] [blame] | 418 | } |
| 419 | fb -= priv->line_length + width * (bpix / 8); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 420 | } |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 421 | } |
| 422 | break; |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 423 | default: |
| 424 | break; |
| 425 | }; |
| 426 | |
Simon Glass | 4761c8c | 2020-07-02 21:12:27 -0600 | [diff] [blame] | 427 | /* Find the position of the top left of the image in the framebuffer */ |
| 428 | fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8); |
| 429 | ret = video_sync_copy(dev, start, fb); |
| 430 | if (ret) |
| 431 | return log_ret(ret); |
| 432 | |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 433 | return video_sync(dev, false); |
Simon Glass | 68b2627 | 2016-01-18 19:52:22 -0700 | [diff] [blame] | 434 | } |