Home | History | Annotate | Download | only in include
      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 #include "bmpblk_font.h"
     11 #include "image_types.h"
     12 
     13 #include <yaml.h>
     14 
     15 #include <map>
     16 #include <string>
     17 #include <vector>
     18 
     19 using std::map;
     20 using std::string;
     21 using std::vector;
     22 
     23 namespace vboot_reference {
     24 
     25 /* Internal struct for contructing ImageInfo. */
     26 typedef struct ImageConfig {
     27   ImageInfo data;
     28   string filename;
     29   string raw_content;
     30   string compressed_content;
     31   uint32_t offset;
     32 } ImageConfig;
     33 
     34 /* Internal struct for contructing ScreenLayout. */
     35 typedef struct ScreenConfig {
     36   ScreenLayout data;
     37   string image_names[MAX_IMAGE_IN_LAYOUT];
     38 } ScreenConfig;
     39 
     40 typedef map<string, ImageConfig> StrImageConfigMap;
     41 typedef map<string, ScreenConfig> StrScreenConfigMap;
     42 
     43 /* Internal struct for contructing the whole BmpBlock. */
     44 typedef struct BmpBlockConfig {
     45   string config_filename;
     46   BmpBlockHeader header;
     47   vector<string> image_names;
     48   StrImageConfigMap images_map;
     49   StrScreenConfigMap screens_map;
     50   vector<vector<string> > localizations;
     51   string locale_names;
     52 } BmpBlockConfig;
     53 
     54 class BmpBlockUtil {
     55  public:
     56   BmpBlockUtil(bool debug);
     57   ~BmpBlockUtil();
     58 
     59   /* Load all the images and related infomations according to a config file. */
     60   void load_from_config(const char *filename);
     61 
     62   /* Contruct the bmpblock. */
     63   void pack_bmpblock();
     64 
     65   /* Write the bmpblock to a file */
     66   void write_to_bmpblock(const char *filename);
     67 
     68   /* What compression to use for the images */
     69   void force_compression(uint32_t compression);
     70 
     71  private:
     72   /* Elemental function called from load_from_config.
     73    * Load the config file (yaml format) and parse it. */
     74   void load_yaml_config(const char *filename);
     75 
     76   /* Elemental function called from load_from_config.
     77    * Load all image files into the internal variables. */
     78   void load_all_image_files();
     79 
     80   /* Elemental function called from load_from_config.
     81    * Contruct the BmpBlockHeader struct. */
     82   void fill_bmpblock_header();
     83 
     84   /* Helper functions for parsing a YAML config file. */
     85   void expect_event(yaml_parser_t *parser, const yaml_event_type_e type);
     86   void parse_config(yaml_parser_t *parser);
     87   void parse_first_layer(yaml_parser_t *parser);
     88   void parse_bmpblock(yaml_parser_t *parser);
     89   void parse_compression(yaml_parser_t *parser);
     90   void parse_images(yaml_parser_t *parser);
     91   void parse_layout(yaml_parser_t *parser, ScreenConfig &screen);
     92   void parse_screens(yaml_parser_t *parser);
     93   void parse_localizations(yaml_parser_t *parser);
     94   void parse_locale_index(yaml_parser_t *parser);
     95 
     96   /* Useful functions */
     97   const string read_image_file(const char *filename);
     98 
     99   /* Verbosity flags */
    100   bool debug_;
    101 
    102   /* Internal variable for string the BmpBlock version. */
    103   uint16_t major_version_;
    104   uint16_t minor_version_;
    105 
    106   /* Flags for version-specific features */
    107   bool render_hwid_;
    108   bool support_font_;
    109   bool got_font_;
    110   bool got_rtol_font_;
    111 
    112   /* Internal variable for storing the config of BmpBlock. */
    113   BmpBlockConfig config_;
    114 
    115   /* Internal variable for storing the content of BmpBlock. */
    116   string bmpblock_;
    117 
    118   /* Internal variables to determine whether or not to specify compression */
    119   bool set_compression_;                // true if we force it
    120   uint32_t compression_;                // what we force it to
    121 };
    122 
    123 }  // namespace vboot_reference
    124 
    125 #endif  // VBOOT_REFERENCE_BMPBLK_UTILITY_H_
    126