mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
This change adds 'pivot' option to draw_bitmap. It controls the point of the image based on which the image is positioned. For example, if a pivot is set to the center of the image horizontally and vertically, the image is positioned using pos_rel as the center of the image. This feature is necessary, for example, to place a text image in the center of the screen because each image has a different width depending on the language. This change also makes draw_bitmap accept both horizontal and vertical size. If either of them is zero, the other non-zero value is used to derive the size to keep the aspect ratio. Specifying the height is necessary to keep font sizes the same when drawing text images of different lengths. draw_bitmap_direct is a variant of draw_bitmap and it draws an image using a native coordinate and the original size (as opposed to the location and the size relative to the canvas). CL:303074 has real use cases. BUG=none BRANCH=tot TEST=Tested on Samus Change-Id: I5fde69fcb5cc9dc53e827dd9fcf001a0a32748d4 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Original-Commit-Id: 82a0a8b60808410652552ed3a888937724111584 Original-Change-Id: I0b0d9113ebecf14e8c70de7a3562b215f69f2d4c Original-Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/302855 Reviewed-on: http://review.coreboot.org/11927 Tested-by: build bot (Jenkins)
151 lines
3.9 KiB
C
151 lines
3.9 KiB
C
/*
|
|
* This file is part of the libpayload project.
|
|
*
|
|
* Copyright (C) 2015 Google, Inc.
|
|
*/
|
|
|
|
#include <libpayload.h>
|
|
#include <arch/types.h>
|
|
#include <stddef.h>
|
|
|
|
/*
|
|
* API error codes
|
|
*/
|
|
#define CBGFX_SUCCESS 0
|
|
/* unknown error */
|
|
#define CBGFX_ERROR_UNKNOWN 1
|
|
/* failed to initialize cbgfx library */
|
|
#define CBGFX_ERROR_INIT 2
|
|
/* drawing beyond screen or canvas boundary */
|
|
#define CBGFX_ERROR_BOUNDARY 3
|
|
/* invalid parameter */
|
|
#define CBGFX_ERROR_INVALID_PARAMETER 4
|
|
/* bitmap error: signature mismatch */
|
|
#define CBGFX_ERROR_BITMAP_SIGNATURE 0x10
|
|
/* bitmap error: unsupported format */
|
|
#define CBGFX_ERROR_BITMAP_FORMAT 0x11
|
|
/* bitmap error: invalid data */
|
|
#define CBGFX_ERROR_BITMAP_DATA 0x12
|
|
/* bitmap error: scaling out of range */
|
|
#define CBGFX_ERROR_SCALE_OUT_OF_RANGE 0x13
|
|
|
|
struct fraction {
|
|
int32_t nume;
|
|
int32_t deno;
|
|
};
|
|
|
|
struct scale {
|
|
struct fraction x;
|
|
struct fraction y;
|
|
};
|
|
|
|
struct vector {
|
|
union {
|
|
int32_t x;
|
|
int32_t width;
|
|
};
|
|
union {
|
|
int32_t y;
|
|
int32_t height;
|
|
};
|
|
};
|
|
|
|
struct rect {
|
|
struct vector offset;
|
|
struct vector size;
|
|
};
|
|
|
|
struct rgb_color {
|
|
uint8_t red;
|
|
uint8_t green;
|
|
uint8_t blue;
|
|
};
|
|
|
|
/*
|
|
* Resolution of scale parameters used to describe height, width, coordinate,
|
|
* etc. relative to the canvas. For example, if it's 100, scales range from 0 to
|
|
* 100%.
|
|
*/
|
|
#define CANVAS_SCALE 100
|
|
|
|
/*
|
|
* The coordinate system is expected to have (0, 0) at top left corner with
|
|
* y values increasing towards bottom of screen.
|
|
*/
|
|
|
|
/**
|
|
* Load a bitmap file from cbfs
|
|
*
|
|
* Memory is allocated automatically and it's caller's responsibility to free it
|
|
*
|
|
* name: name of the bitmap file
|
|
* size: (OUT) size of the image
|
|
*
|
|
* return: pointer to the image data in memory or NULL on error
|
|
*/
|
|
void *load_bitmap(const char *name, size_t *size);
|
|
|
|
/**
|
|
* draw a box filled with a color on screen
|
|
*
|
|
* box: .offset points the coordinate of the top left corner and .size specifies
|
|
* width and height of the box. Both are relative to the canvas size thus scale
|
|
* from 0 to CANVAS_SCALE (0 to 100%).
|
|
* rgb: RGB color of the box.
|
|
*
|
|
* return: CBGFX_* error codes
|
|
*/
|
|
int draw_box(const struct rect *box, const struct rgb_color *rgb);
|
|
|
|
/**
|
|
* Clear the canvas
|
|
*/
|
|
int clear_canvas(const struct rgb_color *rgb);
|
|
|
|
/**
|
|
* Clear the screen
|
|
*/
|
|
int clear_screen(const struct rgb_color *rgb);
|
|
|
|
/**
|
|
* Draw a bitmap image using position and size relative to the canvas
|
|
*
|
|
* @param[in] bitmap Pointer to the bitmap data, starting from file header
|
|
* @param[in] size Size of the bitmap data
|
|
* @param[in] pos_rel Coordinate of the pivot relative to the canvas
|
|
* @param[in] pivot Pivot position. Use PIVOT_H_* and PIVOT_V_* flags.
|
|
* @param[in] dim_rel Width and height of the image relative to the canvas
|
|
* width and height. They must not exceed 1 (=100%). If one
|
|
* is zero, it's derived from the other to keep the aspect
|
|
* ratio.
|
|
*
|
|
* @return CBGFX_* error codes
|
|
*
|
|
* 'Pivot' is a point of the image based on which the image is positioned.
|
|
* For example, if a pivot is set to PIVOT_H_CENTER|PIVOT_V_CENTER, the image is
|
|
* positioned so that pos_rel matches the center of the image.
|
|
*/
|
|
int draw_bitmap(const void *bitmap, size_t size,
|
|
const struct scale *pos_rel, uint8_t pivot,
|
|
const struct scale *dim_rel);
|
|
|
|
/* Pivot flags. See the draw_bitmap description. */
|
|
#define PIVOT_H_LEFT (1 << 0)
|
|
#define PIVOT_H_CENTER (1 << 1)
|
|
#define PIVOT_H_RIGHT (1 << 2)
|
|
#define PIVOT_V_TOP (1 << 3)
|
|
#define PIVOT_V_CENTER (1 << 4)
|
|
#define PIVOT_V_BOTTOM (1 << 5)
|
|
|
|
/**
|
|
* Draw a bitmap image at screen coordinate with no scaling
|
|
*
|
|
* @param[in] bitmap Pointer to the bitmap data, starting from file header
|
|
* @param[in] size Size of the bitmap data
|
|
* @param[in] pos Screen coordinate of upper left corner of the image.
|
|
*
|
|
* @return CBGFX_* error codes
|
|
*/
|
|
int draw_bitmap_direct(const void *bitmap, size_t size,
|
|
const struct vector *pos);
|
|
|