MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _process_icon

Method _process_icon

platform/windows/export/export_plugin.cpp:72–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70#endif
71
72Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &p_preset, const String &p_src_path, const String &p_dst_path) {
73 static const uint8_t icon_size[] = { 16, 32, 48, 64, 128, 0 /*256*/ };
74
75 struct IconData {
76 Vector<uint8_t> data;
77 uint8_t pal_colors = 0;
78 uint16_t planes = 0;
79 uint16_t bpp = 32;
80 };
81
82 HashMap<uint8_t, IconData> images;
83 Error err;
84
85 if (p_src_path.get_extension() == "ico") {
86 Ref<FileAccess> f = FileAccess::open(p_src_path, FileAccess::READ, &err);
87 if (err != OK) {
88 return err;
89 }
90
91 // Read ICONDIR.
92 f->get_16(); // Reserved.
93 uint16_t icon_type = f->get_16(); // Image type: 1 - ICO.
94 uint16_t icon_count = f->get_16(); // Number of images.
95 ERR_FAIL_COND_V(icon_type != 1, ERR_CANT_OPEN);
96
97 for (uint16_t i = 0; i < icon_count; i++) {
98 // Read ICONDIRENTRY.
99 uint16_t w = f->get_8(); // Width in pixels.
100 uint16_t h = f->get_8(); // Height in pixels.
101 uint8_t pal_colors = f->get_8(); // Number of colors in the palette (0 - no palette).
102 f->get_8(); // Reserved.
103 uint16_t planes = f->get_16(); // Number of color planes.
104 uint16_t bpp = f->get_16(); // Bits per pixel.
105 uint32_t img_size = f->get_32(); // Image data size in bytes.
106 uint32_t img_offset = f->get_32(); // Image data offset.
107 if (w != h) {
108 continue;
109 }
110
111 // Read image data.
112 uint64_t prev_offset = f->get_position();
113 images[w].pal_colors = pal_colors;
114 images[w].planes = planes;
115 images[w].bpp = bpp;
116 images[w].data.resize(img_size);
117 f->seek(img_offset);
118 f->get_buffer(images[w].data.ptrw(), img_size);
119 f->seek(prev_offset);
120 }
121 } else {
122 Ref<Image> src_image = _load_icon_or_splash_image(p_src_path, &err);
123 ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN);
124
125 for (size_t i = 0; i < std::size(icon_size); ++i) {
126 int size = (icon_size[i] == 0) ? 256 : icon_size[i];
127
128 Ref<Image> res_image = src_image->duplicate();
129 ERR_FAIL_COND_V(res_image.is_null() || res_image->is_empty(), ERR_CANT_OPEN);

Callers

nothing calls this directly

Calls 15

TTRFunction · 0.85
vformatFunction · 0.85
save_png_to_bufferMethod · 0.80
store_16Method · 0.80
store_8Method · 0.80
store_32Method · 0.80
sizeMethod · 0.65
get_extensionMethod · 0.45
get_16Method · 0.45
get_8Method · 0.45
get_32Method · 0.45
get_positionMethod · 0.45

Tested by

no test coverage detected