MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / image_v2_to_string

Method image_v2_to_string

compat/image_parser_v2.cpp:73–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73String ImageParserV2::image_v2_to_string(const Variant &r_v, bool is_pcfg) {
74 Ref<Image> img = r_v;
75 String imgstr = is_pcfg ? "img(" : "Image( ";
76 if (img.is_null() || img->is_empty()) {
77 return is_pcfg ? "img()" : "Image()";
78 }
79
80 Image::Format fmt = img->get_format();
81 String fmt_id = is_pcfg ? ImageEnumCompat::get_v2_format_identifier_pcfg(ImageEnumCompat::convert_image_format_enum_v4_to_v2(fmt), img->get_data().size()) : ImageEnumCompat::get_v2_format_identifier(ImageEnumCompat::convert_image_format_enum_v4_to_v2(fmt));
82
83 if (!is_pcfg) {
84 imgstr += itos(img->get_width());
85 imgstr += ", " + itos(img->get_height());
86 imgstr += ", " + itos(img->get_mipmap_count());
87 imgstr += ", " + fmt_id;
88 } else {
89 // fmt_id, mipmaps, width, height
90 imgstr += fmt_id;
91 imgstr += ", " + itos(img->get_mipmap_count());
92 imgstr += ", " + itos(img->get_width());
93 imgstr += ", " + itos(img->get_height());
94 }
95
96 String s;
97
98 Vector<uint8_t> data = img->get_data();
99 if (!is_pcfg) {
100 int len = data.size();
101 for (int i = 0; i < len; i++) {
102 if (i > 0) {
103 s += ", ";
104 }
105 s += itos(data[i]);
106 }
107 } else {
108 int ds = data.size();
109 String data_str;
110 for (int i = 0; i < ds; i++) {
111 uint8_t byte = data[i];
112 const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
113 char bstr[3] = { hex[byte >> 4], hex[byte & 0xF], 0 };
114 s += bstr;
115 }
116 }
117
118 imgstr += ", " + s + (is_pcfg ? ")" : " )");
119 return imgstr;
120}
121
122// used in resource_format_binary
123Error ImageParserV2::write_image_v2_to_bin(Ref<FileAccess> f, const Variant &r_v, bool compress_lossless) {

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected