| 8845 | } |
| 8846 | |
| 8847 | int ParseEXRVersionFromMemory(EXRVersion *version, const unsigned char *memory, |
| 8848 | size_t size) { |
| 8849 | if (version == NULL || memory == NULL) { |
| 8850 | return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 8851 | } |
| 8852 | |
| 8853 | if (size < tinyexr::kEXRVersionSize) { |
| 8854 | return TINYEXR_ERROR_INVALID_DATA; |
| 8855 | } |
| 8856 | |
| 8857 | const unsigned char *marker = memory; |
| 8858 | |
| 8859 | // Header check. |
| 8860 | { |
| 8861 | const char header[] = {0x76, 0x2f, 0x31, 0x01}; |
| 8862 | |
| 8863 | if (memcmp(marker, header, 4) != 0) { |
| 8864 | return TINYEXR_ERROR_INVALID_MAGIC_NUMBER; |
| 8865 | } |
| 8866 | marker += 4; |
| 8867 | } |
| 8868 | |
| 8869 | version->tiled = false; |
| 8870 | version->long_name = false; |
| 8871 | version->non_image = false; |
| 8872 | version->multipart = false; |
| 8873 | |
| 8874 | // Parse version header. |
| 8875 | { |
| 8876 | // must be 2 |
| 8877 | if (marker[0] != 2) { |
| 8878 | return TINYEXR_ERROR_INVALID_EXR_VERSION; |
| 8879 | } |
| 8880 | |
| 8881 | if (version == NULL) { |
| 8882 | return TINYEXR_SUCCESS; // May OK |
| 8883 | } |
| 8884 | |
| 8885 | version->version = 2; |
| 8886 | |
| 8887 | if (marker[1] & 0x2) { // 9th bit |
| 8888 | version->tiled = true; |
| 8889 | } |
| 8890 | if (marker[1] & 0x4) { // 10th bit |
| 8891 | version->long_name = true; |
| 8892 | } |
| 8893 | if (marker[1] & 0x8) { // 11th bit |
| 8894 | version->non_image = true; // (deep image) |
| 8895 | } |
| 8896 | if (marker[1] & 0x10) { // 12th bit |
| 8897 | version->multipart = true; |
| 8898 | } |
| 8899 | } |
| 8900 | |
| 8901 | return TINYEXR_SUCCESS; |
| 8902 | } |
| 8903 | |
| 8904 | int ParseEXRVersionFromFile(EXRVersion *version, const char *filename) { |
no outgoing calls
no test coverage detected