1 module aurorafw.metadata.jpeg; 2 3 enum JPEGVersion 4 { 5 JPEG_CANON_EOS, 6 JPEG_SAMSUNG_D500, 7 Unknown 8 } 9 10 import std.stdio : File; 11 12 @safe 13 JPEGVersion getJPEGVersion(File file) 14 { 15 char[4] buf = file.rawRead(new char[4]); 16 if (buf[3] == 0xE2) 17 return JPEGVersion.JPEG_CANON_EOS; 18 else if (buf[3] == 0xE3) 19 return JPEGVersion.JPEG_SAMSUNG_D500; 20 21 return JPEGVersion.Unknown; 22 } 23 24 @safe pure 25 string toString(JPEGVersion ver) 26 { 27 final switch (ver) 28 { 29 case JPEGVersion.JPEG_CANON_EOS: 30 return "CANON EOS JPEG Format"; 31 case JPEGVersion.JPEG_SAMSUNG_D500: 32 return "Samsung D500 JPEG Format"; 33 case JPEGVersion.Unknown: 34 return "Unknown"; 35 } 36 } 37 38 @safe 39 @("JPEG: Versioning") 40 unittest 41 { 42 import std.file; 43 44 version (unittest) import aurorafw.unit.assertion; 45 import std.conv : to; 46 47 scope (exit) 48 { 49 assert(exists(deleteme)); 50 remove(deleteme); 51 } 52 53 JPEGVersion version_; 54 char[] buf = [0xFF, 0xD8, 0xFF]; 55 56 write(deleteme, buf ~ 0xE2); 57 version_ = getJPEGVersion(File(deleteme)); 58 assertEquals(JPEGVersion.JPEG_CANON_EOS, version_); 59 assertEquals("CANON EOS JPEG Format", version_.toString); 60 61 write(deleteme, buf ~ 0xE3); 62 version_ = getJPEGVersion(File(deleteme)); 63 assertEquals(JPEGVersion.JPEG_SAMSUNG_D500, version_); 64 assertEquals("Samsung D500 JPEG Format", version_.toString); 65 66 write(deleteme, buf ~ 0xFF); 67 version_ = getJPEGVersion(File(deleteme)); 68 assertEquals(JPEGVersion.Unknown, version_); 69 assertEquals("Unknown", version_.toString); 70 }