bmpblk_utility.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef VBOOT_REFERENCE_BMPBLK_UTILITY_H_
  5. #define VBOOT_REFERENCE_BMPBLK_UTILITY_H_
  6. #include "bmpblk_header.h"
  7. #include "bmpblk_font.h"
  8. #include "image_types.h"
  9. #include <yaml.h>
  10. #include <map>
  11. #include <string>
  12. #include <vector>
  13. using std::map;
  14. using std::string;
  15. using std::vector;
  16. namespace vboot_reference {
  17. /* Internal struct for contructing ImageInfo. */
  18. typedef struct ImageConfig {
  19. ImageInfo data;
  20. string filename;
  21. string raw_content;
  22. string compressed_content;
  23. uint32_t offset;
  24. } ImageConfig;
  25. /* Internal struct for contructing ScreenLayout. */
  26. typedef struct ScreenConfig {
  27. ScreenLayout data;
  28. string image_names[MAX_IMAGE_IN_LAYOUT];
  29. } ScreenConfig;
  30. typedef map<string, ImageConfig> StrImageConfigMap;
  31. typedef map<string, ScreenConfig> StrScreenConfigMap;
  32. /* Internal struct for contructing the whole BmpBlock. */
  33. typedef struct BmpBlockConfig {
  34. string config_filename;
  35. BmpBlockHeader header;
  36. vector<string> image_names;
  37. StrImageConfigMap images_map;
  38. StrScreenConfigMap screens_map;
  39. vector<vector<string> > localizations;
  40. string locale_names;
  41. } BmpBlockConfig;
  42. class BmpBlockUtil {
  43. public:
  44. BmpBlockUtil(bool debug);
  45. ~BmpBlockUtil();
  46. /* Load all the images and related information according to a config file. */
  47. void load_from_config(const char *filename);
  48. /* Contruct the bmpblock. */
  49. void pack_bmpblock();
  50. /* Write the bmpblock to a file */
  51. void write_to_bmpblock(const char *filename);
  52. /* What compression to use for the images */
  53. void force_compression(uint32_t compression);
  54. private:
  55. /* Elemental function called from load_from_config.
  56. * Load the config file (yaml format) and parse it. */
  57. void load_yaml_config(const char *filename);
  58. /* Elemental function called from load_from_config.
  59. * Load all image files into the internal variables. */
  60. void load_all_image_files();
  61. /* Elemental function called from load_from_config.
  62. * Contruct the BmpBlockHeader struct. */
  63. void fill_bmpblock_header();
  64. /* Helper functions for parsing a YAML config file. */
  65. void expect_event(yaml_parser_t *parser, const yaml_event_type_e type);
  66. void parse_config(yaml_parser_t *parser);
  67. void parse_first_layer(yaml_parser_t *parser);
  68. void parse_bmpblock(yaml_parser_t *parser);
  69. void parse_compression(yaml_parser_t *parser);
  70. void parse_images(yaml_parser_t *parser);
  71. void parse_layout(yaml_parser_t *parser, ScreenConfig &screen);
  72. void parse_screens(yaml_parser_t *parser);
  73. void parse_localizations(yaml_parser_t *parser);
  74. void parse_locale_index(yaml_parser_t *parser);
  75. /* Useful functions */
  76. const string read_image_file(const char *filename);
  77. /* Verbosity flags */
  78. bool debug_;
  79. /* Internal variable for string the BmpBlock version. */
  80. uint16_t major_version_;
  81. uint16_t minor_version_;
  82. /* Flags for version-specific features */
  83. bool render_hwid_;
  84. bool support_font_;
  85. bool got_font_;
  86. bool got_rtol_font_;
  87. /* Internal variable for storing the config of BmpBlock. */
  88. BmpBlockConfig config_;
  89. /* Internal variable for storing the content of BmpBlock. */
  90. string bmpblock_;
  91. /* Internal variables to determine whether or not to specify compression */
  92. bool set_compression_; // true if we force it
  93. uint32_t compression_; // what we force it to
  94. };
  95. } // namespace vboot_reference
  96. #endif // VBOOT_REFERENCE_BMPBLK_UTILITY_H_