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