| 248 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_COMMA, "Expected comma in Image variant") |
| 249 | |
| 250 | Error ImageParserV2::parse_image_construct_v2(VariantParser::Stream *p_stream, Variant &r_v, bool convert_indexed, int &line, String &p_err_str, bool is_pcfg) { |
| 251 | String r_err_str; |
| 252 | VariantParser::Token token; |
| 253 | uint32_t width; |
| 254 | uint32_t height; |
| 255 | uint32_t mipmaps; |
| 256 | V2Image::Format old_format; |
| 257 | Image::Format fmt = Image::FORMAT_MAX; |
| 258 | Vector<uint8_t> data; |
| 259 | Ref<Image> img; |
| 260 | |
| 261 | // The "Image" identifier has already been parsed, start with parantheses |
| 262 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 263 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_PARENTHESIS_OPEN, "Expected '(' in constructor"); |
| 264 | |
| 265 | // w, h, mipmap count, format string, data... |
| 266 | // width |
| 267 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 268 | if (token.type == VariantParser::TK_PARENTHESIS_CLOSE) { // empty image |
| 269 | img.instantiate(); |
| 270 | r_v = img; |
| 271 | return OK; |
| 272 | } |
| 273 | if (!is_pcfg) { // w, h, mipmap count, format string, data... |
| 274 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_NUMBER, "Expected width in Image variant"); |
| 275 | width = token.value; |
| 276 | EXPECT_COMMA(); |
| 277 | |
| 278 | // height |
| 279 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 280 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_NUMBER, "Expected height in Image variant"); |
| 281 | height = token.value; |
| 282 | EXPECT_COMMA(); |
| 283 | |
| 284 | // mipmaps |
| 285 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 286 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_NUMBER, "Expected mipmap count in Image variant"); |
| 287 | mipmaps = token.value; |
| 288 | EXPECT_COMMA(); |
| 289 | |
| 290 | // format string |
| 291 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 292 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_IDENTIFIER, "Expected format string in Image variant"); |
| 293 | old_format = ImageEnumCompat::get_v2_format_from_string(token.value); |
| 294 | fmt = ImageEnumCompat::convert_image_format_enum_v2_to_v4(old_format); |
| 295 | EXPECT_COMMA(); |
| 296 | } else { // pcfg format; fmt, mipmaps, width, height, data... |
| 297 | // format string |
| 298 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_IDENTIFIER, "Expected format string in Image variant"); |
| 299 | old_format = ImageEnumCompat::get_v2_format_from_string(token.value); |
| 300 | fmt = ImageEnumCompat::convert_image_format_enum_v2_to_v4(old_format); |
| 301 | EXPECT_COMMA(); |
| 302 | // mipmaps |
| 303 | VariantParser::get_token(p_stream, token, line, r_err_str); |
| 304 | ERR_PARSE_V2IMAGE_FAIL(VariantParser::TK_NUMBER, "Expected mipmap count in Image variant"); |
| 305 | mipmaps = token.value; |
| 306 | EXPECT_COMMA(); |
| 307 | // width |