API Documentation
Loading...
Searching...
No Matches
ConvertToIco.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/Vector.h>
3#include <iostream>
4#include <fstream>
5namespace NDEVR
6{
7#pragma pack(push, 1)
8 /**--------------------------------------------------------------------------------------------------
9 \brief Logic for handling files with the .ico extension
10 **/
11 class IcoFile
12 {
13 public:
25
33
48#pragma pack(pop)
49 static bool ConvertRGBAToIcon(const File& icon, const uint01* rgba, Vector<2, uint04> size)
50 {
51 uint04 image_size = size.product() * 4; // 4 bytes per pixel for RGBA
52 // Prepare bitmap headers
53 BitmapInfoHeader bmpInfoHeader = { 40, cast<sint04>(size[X]), cast<sint04>(size[Y]) * 2, 1, 32, 0, static_cast<uint32_t>(image_size), 0, 0, 0, 0};
54 // Prepare icon headers
55 IconDir icon_dir = { 0, 1, 1 };
56 IconDirEntry iconDirEntry = {
57 static_cast<uint01>(size[X]),
58 static_cast<uint01>(size[Y]),
59 0,
60 0,
61 1,
62 32,
63 static_cast<uint04>(sizeof(BitmapInfoHeader) + image_size),
64 static_cast<uint04>(sizeof(IconDir) + sizeof(IconDirEntry))
65 };
66 icon.getParentDirectory().create(false);//ensure parent exists
67 std::ofstream ico_file(icon.c_str(), std::ios::binary);
68 if (!ico_file.is_open())
69 return false;
70
71 // Write icon headers
72 ico_file.write(reinterpret_cast<char*>(&icon_dir), sizeof(IconDir) - sizeof(icon_dir.entries));
73 ico_file.write(reinterpret_cast<char*>(&iconDirEntry), sizeof(iconDirEntry));
74
75 // Write bitmap headers
76 ico_file.write(reinterpret_cast<char*>(&bmpInfoHeader), sizeof(bmpInfoHeader));
77
78 // Write RGBA image data
79 ico_file.write(reinterpret_cast<const char*>(rgba), image_size);
80 ico_file.close();
81 return true;
82 }
83 };
84}
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
void create(bool override_file) const
File getParentDirectory() const
Logic for handling files with the .ico extension.
Definition ConvertToIco.h:12
static bool ConvertRGBAToIcon(const File &icon, const uint01 *rgba, Vector< 2, uint04 > size)
Definition ConvertToIco.h:49
const char * c_str() const
Used to access the raw memory of this string.
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr t_type product() const
Definition Vector.hpp:488
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
Definition ConvertToIco.h:35
uint04 biCompression
Definition ConvertToIco.h:41
uint02 biBitCount
Definition ConvertToIco.h:40
uint04 biClrImportant
Definition ConvertToIco.h:46
uint04 biSizeImage
Definition ConvertToIco.h:42
uint04 biClrUsed
Definition ConvertToIco.h:45
sint04 biYPelsPerMeter
Definition ConvertToIco.h:44
sint04 biWidth
Definition ConvertToIco.h:37
uint04 biSize
Definition ConvertToIco.h:36
sint04 biHeight
Definition ConvertToIco.h:38
uint02 biPlanes
Definition ConvertToIco.h:39
sint04 biXPelsPerMeter
Definition ConvertToIco.h:43
Definition ConvertToIco.h:15
uint01 width
Definition ConvertToIco.h:16
uint01 height
Definition ConvertToIco.h:17
uint01 colorCount
Definition ConvertToIco.h:18
uint01 reserved
Definition ConvertToIco.h:19
uint04 imageOffset
Definition ConvertToIco.h:23
uint02 bitCount
Definition ConvertToIco.h:21
uint02 planes
Definition ConvertToIco.h:20
uint04 bytesInRes
Definition ConvertToIco.h:22
Definition ConvertToIco.h:27
uint02 type
Definition ConvertToIco.h:29
IconDirEntry entries[1]
Definition ConvertToIco.h:31
uint02 reserved
Definition ConvertToIco.h:28
uint02 count
Definition ConvertToIco.h:30