NDEVR
API Documentation
ConvertToIco.h
1#pragma once
2#include <NDEVR/Vector.h>
3#include <iostream>
4#include <fstream>
5namespace NDEVR
6{
7#pragma pack(push, 1)
11 class IcoFile
12 {
13 public:
28
39
57#pragma pack(pop)
65 static bool ConvertRGBAToIcon(File icon, const uint01* rgba, Vector<2, uint04> size)
66 {
67 uint04 image_size = size.product() * 4; // 4 bytes per pixel for RGBA
68 // Prepare bitmap headers
69 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};
70 // Prepare icon headers
71 IconDir icon_dir;
72 icon_dir.reserved = 0;
73 icon_dir.type = 1;
74 icon_dir.count = 1;
75 IconDirEntry iconDirEntry = {
76 static_cast<uint01>(size[X]),
77 static_cast<uint01>(size[Y]),
78 0,
79 0,
80 1,
81 32,
82 static_cast<uint04>(sizeof(BitmapInfoHeader) + image_size),
83 static_cast<uint04>(sizeof(IconDir) + sizeof(IconDirEntry))
84 };
85 icon.getParentDirectory().create(false);//ensure parent exists
86 if (!icon.open(File::e_binary_write))
87 return false;
88
89 // Write icon headers
90 icon << StringView(reinterpret_cast<char*>(&icon_dir), sizeof(IconDir) - sizeof(icon_dir.entries));
91 icon << StringView(reinterpret_cast<char*>(&iconDirEntry), sizeof(iconDirEntry));
92
93 // Write bitmap headers
94 icon << StringView(reinterpret_cast<char*>(&bmpInfoHeader), sizeof(bmpInfoHeader));
95
96 // Write RGBA image data
98 icon.close();
99 return true;
100 }
101 };
102}
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
@ e_binary_write
Open for binary writing.
Definition File.h:61
Logic for handling files with the .ico extension.
static bool ConvertRGBAToIcon(File icon, const uint01 *rgba, Vector< 2, uint04 > size)
Converts raw RGBA pixel data into a Windows .ico file and writes it to disk.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
constexpr t_type product() const
Returns the product, or value of each dimension multiplied together.
Definition Vector.hpp:510
The primary namespace for the NDEVR SDK.
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ icon
Icon identifier for the object.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Windows BITMAPINFOHEADER structure used to describe the bitmap data within an ICO file.
sint04 biWidth
Width of the bitmap in pixels.
uint02 biBitCount
Bits per pixel (e.g., 32 for RGBA).
uint04 biSize
Size of this structure in bytes (always 40).
uint02 biPlanes
Number of color planes (must be 1).
sint04 biXPelsPerMeter
Horizontal resolution in pixels per meter.
uint04 biClrUsed
Number of colors in the color table (0 for default).
uint04 biClrImportant
Number of important colors (0 means all are important).
uint04 biCompression
Compression type (0 for uncompressed).
sint04 biHeight
Height of the bitmap in pixels (doubled for ICO to include AND mask).
sint04 biYPelsPerMeter
Vertical resolution in pixels per meter.
uint04 biSizeImage
Size of the raw bitmap data in bytes.
Represents a single entry in the ICO file directory, describing one icon image.
uint02 bitCount
Bits per pixel.
uint01 reserved
Reserved, should be 0.
uint01 colorCount
Number of colors in the color palette (0 if more than 256).
uint02 planes
Number of color planes (should be 1).
uint01 height
Height of the icon image in pixels (0 means 256).
uint04 bytesInRes
Size of the image data in bytes.
uint04 imageOffset
Offset of the image data from the beginning of the file.
uint01 width
Width of the icon image in pixels (0 means 256).
Represents the ICO file directory header, containing metadata and an array of icon entries.
IconDirEntry entries[1]
Array of icon directory entries (variable length).
uint02 reserved
Reserved, should be 0.
uint02 type
Resource type (1 for icons, 2 for cursors).
uint02 count
Number of icon images in the file.