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 class IcoFile
9 {
10 public:
22
30
45#pragma pack(pop)
46 static bool ConvertRGBAToIcon(const File& icon, const uint01* rgba, Vector<2, uint04> size)
47 {
48 uint04 image_size = size.product() * 4; // 4 bytes per pixel for RGBA
49 // Prepare bitmap headers
50 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};
51 // Prepare icon headers
52 IconDir icon_dir = { 0, 1, 1 };
53 IconDirEntry iconDirEntry = {
54 static_cast<uint01>(size[X]),
55 static_cast<uint01>(size[Y]),
56 0,
57 0,
58 1,
59 32,
60 static_cast<uint04>(sizeof(BitmapInfoHeader) + image_size),
61 static_cast<uint04>(sizeof(IconDir) + sizeof(IconDirEntry))
62 };
63 icon.getParentDirectory().create(false);//ensure parent exists
64 std::ofstream ico_file(icon.c_str(), std::ios::binary);
65 if (!ico_file.is_open())
66 return false;
67
68 // Write icon headers
69 ico_file.write(reinterpret_cast<char*>(&icon_dir), sizeof(IconDir) - sizeof(icon_dir.entries));
70 ico_file.write(reinterpret_cast<char*>(&iconDirEntry), sizeof(iconDirEntry));
71
72 // Write bitmap headers
73 ico_file.write(reinterpret_cast<char*>(&bmpInfoHeader), sizeof(bmpInfoHeader));
74
75 // Write RGBA image data
76 ico_file.write(reinterpret_cast<const char*>(rgba), image_size);
77 ico_file.close();
78 return true;
79 }
80 };
81}
Definition File.h:47
NDEVR_BASE_API void create(bool override_file) const
Definition File.cpp:1744
NDEVR_BASE_API File getParentDirectory() const
Definition File.cpp:1692
Definition ConvertToIco.h:9
static bool ConvertRGBAToIcon(const File &icon, const uint01 *rgba, Vector< 2, uint04 > size)
Definition ConvertToIco.h:46
NDEVR_BASE_API const char * c_str() const
Definition String.cpp:490
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_type product() const
Definition Vector.hpp:526
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:76
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
Definition ConvertToIco.h:32
uint04 biCompression
Definition ConvertToIco.h:38
uint02 biBitCount
Definition ConvertToIco.h:37
uint04 biClrImportant
Definition ConvertToIco.h:43
uint04 biSizeImage
Definition ConvertToIco.h:39
uint04 biClrUsed
Definition ConvertToIco.h:42
sint04 biYPelsPerMeter
Definition ConvertToIco.h:41
sint04 biWidth
Definition ConvertToIco.h:34
uint04 biSize
Definition ConvertToIco.h:33
sint04 biHeight
Definition ConvertToIco.h:35
uint02 biPlanes
Definition ConvertToIco.h:36
sint04 biXPelsPerMeter
Definition ConvertToIco.h:40
Definition ConvertToIco.h:12
uint01 width
Definition ConvertToIco.h:13
uint01 height
Definition ConvertToIco.h:14
uint01 colorCount
Definition ConvertToIco.h:15
uint01 reserved
Definition ConvertToIco.h:16
uint04 imageOffset
Definition ConvertToIco.h:20
uint02 bitCount
Definition ConvertToIco.h:18
uint02 planes
Definition ConvertToIco.h:17
uint04 bytesInRes
Definition ConvertToIco.h:19
Definition ConvertToIco.h:24
uint02 type
Definition ConvertToIco.h:26
IconDirEntry entries[1]
Definition ConvertToIco.h:28
uint02 reserved
Definition ConvertToIco.h:25
uint02 count
Definition ConvertToIco.h:27