libfacade 1.1
A library for manipulating PNG images with payloads.
Loading...
Searching...
No Matches
ico.hpp
Go to the documentation of this file.
1#ifndef __FACADE_ICO_HPP
2#define __FACADE_ICO_HPP
3
6
7#include <cstddef>
8#include <cstdint>
9#include <cstdlib>
10#include <string>
11#include <vector>
12#include <utility>
13
14#include <facade/platform.hpp>
15#include <facade/exception.hpp>
16#include <facade/png.hpp>
17#include <facade/utility.hpp>
18
19namespace facade
20{
21namespace ico
22{
24 struct
25 PACK(2)
27 {
28 std::uint8_t width;
29 std::uint8_t height;
30 std::uint8_t color_count;
31 std::uint8_t reserved;
32 std::uint16_t planes;
33 std::uint16_t bit_count;
34 std::uint32_t bytes;
35 std::uint32_t offset;
36 };
37 UNPACK()
38
39
40 struct
41 PACK(2)
43 {
44 std::uint16_t reserved;
45 std::uint16_t type;
46 std::uint16_t count;
47 IconDirEntry entries[1];
48 };
49 UNPACK()
50
51
52 class
53 EXPORT
54 Icon
55 {
56 public:
58 using Entry = std::pair<IconDirEntry, std::vector<std::uint8_t>>;
59
60 private:
61 std::vector<Entry> _entries;
62
63 public:
66 {
67 ENTRY_BMP = 0,
68 ENTRY_PNG
69 };
70
71 Icon() {}
72 Icon(const void *ptr, std::size_t size) { this->parse(ptr, size); }
73 Icon(const std::vector<std::uint8_t> &vec) { this->parse(vec); }
74 Icon(const std::string &filename) { this->parse(filename); }
75 Icon(const Icon &other) : _entries(other._entries) {}
76
77 Icon &operator=(const Icon &other) {
78 this->_entries = other._entries;
79
80 return *this;
81 }
83 Entry &operator[](std::size_t index) {
84 return this->get_entry(index);
85 }
87 const Entry &operator[](std::size_t index) const {
88 return this->get_entry(index);
89 }
90
92 std::size_t size(void) const;
93
99 void parse(const void *ptr, std::size_t size);
103 void parse(const std::vector<std::uint8_t> &vec);
107 void parse(const std::string &filename);
108
113 Entry &get_entry(std::size_t index);
118 const Entry &get_entry(std::size_t index) const;
122 void set_entry(std::size_t index, const Entry &data);
126 void set_entry(std::size_t index, const IconDirEntry &entry, const std::vector<std::uint8_t> &data);
127
131 EntryType entry_type(std::size_t index) const;
132
136 std::vector<std::uint8_t> to_file() const;
141 void save(const std::string &filename) const;
142
145 void resize(std::size_t size);
146
150 Entry &insert_entry(std::size_t index, const Entry &entry);
154 Entry &insert_entry(std::size_t index, const IconDirEntry &entry, const std::vector<std::uint8_t> &data);
157 Entry &append_entry(const Entry &entry);
160 Entry &append_entry(const IconDirEntry &entry, const std::vector<std::uint8_t> &data);
164 void remove_entry(std::size_t index);
165 };
166}}
167#endif
A Windows icon file.
Definition: ico.hpp:55
Icon(const std::string &filename)
Definition: ico.hpp:74
std::pair< IconDirEntry, std::vector< std::uint8_t > > Entry
A C++ representation of a bitmap entry within the icon file.
Definition: ico.hpp:58
Icon(const Icon &other)
Definition: ico.hpp:75
Icon(const std::vector< std::uint8_t > &vec)
Definition: ico.hpp:73
Icon(const void *ptr, std::size_t size)
Definition: ico.hpp:72
Entry & operator[](std::size_t index)
Syntactic sugar to get an entry within the icon file.
Definition: ico.hpp:83
Icon()
Definition: ico.hpp:71
EntryType
A simple enumeration to differentiate between PNG sections and bitmap sections.
Definition: ico.hpp:66
Icon & operator=(const Icon &other)
Definition: ico.hpp:77
const Entry & operator[](std::size_t index) const
Syntactic sugar to get a const entry within the icon file.
Definition: ico.hpp:87
A collection of exceptions thrown by the library.
Definition: exception.hpp:14
Various macros and defines that help determine the platform of the compiler.
#define PACK(alignment)
Definition: platform.hpp:53
#define EXPORT
Definition: platform.hpp:46
#define UNPACK()
Definition: platform.hpp:54
Code functionality for dealing with PNG images.
The C header for an icon bitmap entry.
Definition: ico.hpp:27
std::uint16_t planes
Definition: ico.hpp:32
std::uint8_t reserved
Definition: ico.hpp:31
std::uint16_t bit_count
Definition: ico.hpp:33
std::uint32_t bytes
Definition: ico.hpp:34
std::uint32_t offset
Definition: ico.hpp:35
std::uint8_t height
Definition: ico.hpp:29
std::uint8_t width
Definition: ico.hpp:28
std::uint8_t color_count
Definition: ico.hpp:30
The C header for an icon directory, the root of an icon file.
Definition: ico.hpp:43
std::uint16_t count
Definition: ico.hpp:46
std::uint16_t type
Definition: ico.hpp:45
std::uint16_t reserved
Definition: ico.hpp:44
Functions relating to the needs of images in the program.