used in resource_format_binary
| 174 | |
| 175 | // used in resource_format_binary |
| 176 | Error ImageParserV2::decode_image_v2(Ref<FileAccess> f, Variant &r_v, bool convert_indexed) { |
| 177 | uint32_t encoding = f->get_32(); |
| 178 | Ref<Image> img; |
| 179 | |
| 180 | if (encoding == V2Image::IMAGE_ENCODING_EMPTY) { |
| 181 | img.instantiate(); |
| 182 | r_v = img; |
| 183 | return OK; |
| 184 | } else if (encoding == V2Image::IMAGE_ENCODING_RAW) { |
| 185 | uint32_t width = f->get_32(); |
| 186 | uint32_t height = f->get_32(); |
| 187 | uint32_t mipmaps = f->get_32(); |
| 188 | uint32_t old_format = f->get_32(); |
| 189 | if (old_format >= V2Image::Format::FORMAT_YUV_422) { |
| 190 | old_format += 2; // the image format enum for resources doesn't have YUV422 and YUV444 formats, so it's off by 2 after |
| 191 | } |
| 192 | Image::Format fmt = ImageEnumCompat::convert_image_format_enum_v2_to_v4((V2Image::Format)old_format); |
| 193 | |
| 194 | uint32_t datalen = f->get_32(); |
| 195 | |
| 196 | Vector<uint8_t> imgdata; |
| 197 | imgdata.resize(datalen); |
| 198 | uint8_t *w = imgdata.ptrw(); |
| 199 | f->get_buffer(w, datalen); |
| 200 | _advance_padding(f, datalen); |
| 201 | // This is for if we're saving the image as a png. |
| 202 | if (convert_indexed && (old_format == 5 || old_format == 6 || old_format == 1)) { |
| 203 | Error err; |
| 204 | img = ImageParserV2::convert_indexed_image(imgdata, width, height, mipmaps, (V2Image::Format)old_format, &err); |
| 205 | ERR_FAIL_COND_V_MSG(err, err, |
| 206 | "Can't convert deprecated image format " + ImageEnumCompat::get_v2_format_name((V2Image::Format)old_format) + " to new image formats!"); |
| 207 | } else { |
| 208 | // We wait until we've skipped all the data to do this |
| 209 | ERR_FAIL_COND_V_MSG( |
| 210 | fmt == Image::FORMAT_MAX && (old_format > 0 && old_format < V2Image::IMAGE_FORMAT_V2_MAX), |
| 211 | ERR_UNAVAILABLE, |
| 212 | "Converting deprecated image format " + ImageEnumCompat::get_v2_format_name((V2Image::Format)old_format) + " not implemented."); |
| 213 | ERR_FAIL_COND_V_MSG( |
| 214 | fmt == Image::FORMAT_MAX, |
| 215 | ERR_FILE_CORRUPT, |
| 216 | "Invalid format"); |
| 217 | |
| 218 | img = Image::create_from_data(width, height, mipmaps > 0, fmt, imgdata); |
| 219 | } |
| 220 | } else { |
| 221 | // compressed |
| 222 | Vector<uint8_t> data; |
| 223 | data.resize(f->get_32()); |
| 224 | uint8_t *w = data.ptrw(); |
| 225 | f->get_buffer(w, data.size()); |
| 226 | // Godot 2.0 sometimes exported empty images as "IMAGE_ENCODING_LOSSY" rather than "IMAGE_ENCODING_EMPTY", so we need to check for that. |
| 227 | if (data.size() == 0) { |
| 228 | img.instantiate(); |
| 229 | } else if (encoding == V2Image::IMAGE_ENCODING_LOSSY) { |
| 230 | img = WebPCompat::webp_unpack_v2v3(data); |
| 231 | } else if (encoding == V2Image::IMAGE_ENCODING_LOSSLESS && Image::png_unpacker) { |
| 232 | img = img->png_unpacker(data); |
| 233 | } |
nothing calls this directly
no test coverage detected