| OLD | NEW |
| (Empty) | |
| 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 |
| 5 |
| 6 #ifndef VBOOT_REFERENCE_BMPBLK_UTILITY_H_ |
| 7 #define VBOOT_REFERENCE_BMPBLK_UTILITY_H_ |
| 8 |
| 9 #include "bmpblk_header.h" |
| 10 |
| 11 #include <yaml.h> |
| 12 |
| 13 #include <map> |
| 14 #include <string> |
| 15 #include <vector> |
| 16 |
| 17 using std::map; |
| 18 using std::string; |
| 19 using std::vector; |
| 20 |
| 21 namespace vboot_reference { |
| 22 |
| 23 /* Internal struct for contructing ImageInfo. */ |
| 24 typedef struct ImageConfig { |
| 25 ImageInfo data; |
| 26 string filename; |
| 27 string raw_content; |
| 28 string compressed_content; |
| 29 uint32_t offset; |
| 30 } ImageConfig; |
| 31 |
| 32 /* Internal struct for contructing ScreenLayout. */ |
| 33 typedef struct ScreenConfig { |
| 34 ScreenLayout data; |
| 35 string image_names[MAX_IMAGE_IN_LAYOUT]; |
| 36 } ScreenConfig; |
| 37 |
| 38 typedef map<string, ImageConfig> StrImageConfigMap; |
| 39 typedef map<string, ScreenConfig> StrScreenConfigMap; |
| 40 |
| 41 /* Internal struct for contructing the whole BmpBlock. */ |
| 42 typedef struct BmpBlockConfig { |
| 43 string config_filename; |
| 44 BmpBlockHeader header; |
| 45 StrImageConfigMap images_map; |
| 46 StrScreenConfigMap screens_map; |
| 47 vector<vector<string> > localizations; |
| 48 } BmpBlockConfig; |
| 49 |
| 50 class BmpBlockUtil { |
| 51 public: |
| 52 BmpBlockUtil(); |
| 53 ~BmpBlockUtil(); |
| 54 |
| 55 /* Load all the images and related infomations according to a config file. */ |
| 56 void load_from_config(const char *filename); |
| 57 |
| 58 /* Compress all the images using a given comression method. */ |
| 59 void compress_all_images(const Compression compress); |
| 60 |
| 61 /* Contruct the bmpblock. */ |
| 62 void pack_bmpblock(); |
| 63 |
| 64 /* Write the bmpblock to a file */ |
| 65 void write_to_bmpblock(const char *filename); |
| 66 |
| 67 private: |
| 68 /* Clear all internal data. */ |
| 69 void initialize(); |
| 70 |
| 71 /* Elemental function called from load_from_config. |
| 72 * Load the config file (yaml format) and parse it. */ |
| 73 void load_yaml_config(const char *filename); |
| 74 |
| 75 /* Elemental function called from load_from_config. |
| 76 * Load all image files into the internal variables. */ |
| 77 void load_all_image_files(); |
| 78 |
| 79 /* Elemental function called from load_from_config. |
| 80 * Contruct all ImageInfo structs. */ |
| 81 void fill_all_image_infos(); |
| 82 |
| 83 /* Elemental function called from load_from_config. |
| 84 * Contruct the BmpBlockHeader struct. */ |
| 85 void fill_bmpblock_header(); |
| 86 |
| 87 /* Helper functions for parsing a YAML config file. */ |
| 88 void expect_event(yaml_parser_t *parser, const yaml_event_type_e type); |
| 89 void parse_config(yaml_parser_t *parser); |
| 90 void parse_first_layer(yaml_parser_t *parser); |
| 91 void parse_bmpblock(yaml_parser_t *parser); |
| 92 void parse_images(yaml_parser_t *parser); |
| 93 void parse_layout(yaml_parser_t *parser, ScreenConfig &screen); |
| 94 void parse_screens(yaml_parser_t *parser); |
| 95 void parse_localizations(yaml_parser_t *parser); |
| 96 |
| 97 /* Useful functions */ |
| 98 const string read_image_file(const char *filename); |
| 99 ImageFormat get_image_format(const string content); |
| 100 uint32_t get_bmp_image_width(const string content); |
| 101 uint32_t get_bmp_image_height(const string content); |
| 102 |
| 103 /* Internal variable for storing the config of BmpBlock. */ |
| 104 BmpBlockConfig config_; |
| 105 |
| 106 /* Internal variable for storing the content of BmpBlock. */ |
| 107 string bmpblock_; |
| 108 }; |
| 109 |
| 110 } // namespace vboot_reference |
| 111 |
| 112 #endif // VBOOT_REFERENCE_BMPBLK_UTILITY_H_ |
| OLD | NEW |