[coreboot-gerrit] New patch to review for coreboot: cbgfx: add get_image_dimension

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Fri Oct 16 16:46:32 CEST 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11929

-gerrit

commit aaa2535a40cc7d0e3e1ce32e1e8d45f00b453720
Author: Daisuke Nojiri <dnojiri at chromium.org>
Date:   Thu Oct 1 15:56:28 2015 -0700

    cbgfx: add get_image_dimension
    
    get_image_dimension returns the width or height of the image projected on
    canvas.
    
    This is necessary for example when two images of different lengths have to
    be placed side by side in the center of the canvas and the widths of the
    images must be adjusted according to the height.
    
    BUG=chromium:502066
    BRANCH=tot
    TEST=Tested on Samus
    
    Change-Id: I119c83891f48046e888b6b526e63348e74f8b77c
    Signed-off-by: Patrick Georgi <pgeorgi at google.com>
    Original-Commit-Id: d1a97f0492eb02f906feb5b879b7b43518dfa4d7
    Original-Change-Id: Ie13f7994d639ea1556f73690b6b6b413ae64223c
    Original-Signed-off-by: Daisuke Nojiri <dnojiri at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/304113
    Original-Reviewed-by: Aaron Durbin <adurbin at chromium.org>
---
 payloads/libpayload/drivers/video/graphics.c | 31 ++++++++++++++++++++++++++++
 payloads/libpayload/include/cbgfx.h          | 19 +++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c
index b4cdcde..52c0035 100644
--- a/payloads/libpayload/drivers/video/graphics.c
+++ b/payloads/libpayload/drivers/video/graphics.c
@@ -611,3 +611,34 @@ int draw_bitmap_direct(const void *bitmap, size_t size,
 	return draw_bitmap_v3(top_left, &scale, &dim, &dim,
 			      &header, palette, pixel_array);
 }
+
+int get_bitmap_dimension(const void *bitmap, size_t sz, struct scale *dim_rel)
+{
+	struct bitmap_header_v3 header;
+	const struct bitmap_palette_element_v3 *palette;
+	const uint8_t *pixel_array;
+	struct vector dim, dim_org;
+	int rv;
+
+	if (cbgfx_init())
+		return CBGFX_ERROR_INIT;
+
+	/* Only v3 is supported now */
+	rv = parse_bitmap_header_v3(bitmap, sz,
+				    &header, &palette, &pixel_array, &dim_org);
+	if (rv)
+		return rv;
+
+	/* Calculate height and width of the image */
+	rv = calculate_dimension(&dim_org, dim_rel, &dim);
+	if (rv)
+		return rv;
+
+	/* Calculate size relative to the canvas */
+	dim_rel->x.n = dim.width;
+	dim_rel->x.d = canvas.size.width;
+	dim_rel->y.n = dim.height;
+	dim_rel->y.d = canvas.size.height;
+
+	return CBGFX_SUCCESS;
+}
diff --git a/payloads/libpayload/include/cbgfx.h b/payloads/libpayload/include/cbgfx.h
index 54d3953..4ab4943 100644
--- a/payloads/libpayload/include/cbgfx.h
+++ b/payloads/libpayload/include/cbgfx.h
@@ -148,3 +148,22 @@ int draw_bitmap(const void *bitmap, size_t size,
  */
 int draw_bitmap_direct(const void *bitmap, size_t size,
 		       const struct vector *top_left);
+
+/**
+ * Get width and height of projected image
+ *
+ * @param[in] bitmap	Pointer to the bitmap data, starting from file header
+ * @param[in] sz	Size of the bitmap data
+ * @param[i/o] dim_rel	Width and height of the image relative to the canvas
+ *                      width and height. They must not exceed 1 (=100%).
+ *                      On return, it contains automatically calculated width
+ *                      and/or height.
+ *
+ * @return CBGFX_* error codes
+ *
+ * It returns the width and height of the projected image. If the input height
+ * is zero, it's derived from the input width to keep the aspect ratio, and vice
+ * versa. If both are zero, the width and the height which can project the image
+ * in the original size are returned.
+ */
+int get_bitmap_dimension(const void *bitmap, size_t sz, struct scale *dim_rel);



More information about the coreboot-gerrit mailing list