浏览代码

LibGfx/TIFF: Automatically export all enums associated with tags

Lucas CHOLLET 1 年之前
父节点
当前提交
4280f4d2c7
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      Userland/Libraries/LibGfx/TIFFGenerator.py

+ 11 - 6
Userland/Libraries/LibGfx/TIFFGenerator.py

@@ -79,10 +79,19 @@ def export_enum_to_cpp(e: Type[Enum], special_name: Optional[str] = None) -> str
     for entry in e:
         output += f'    {entry.name} = {entry.value},\n'
 
-    output += "};"
+    output += "};\n"
     return output
 
 
+def export_tag_related_enums(tags: List[Tag]) -> str:
+    exported_enums = []
+    for tag in tags:
+        if tag.associated_enum:
+            exported_enums.append(export_enum_to_cpp(tag.associated_enum))
+
+    return '\n'.join(exported_enums)
+
+
 def promote_type(t: TIFFType) -> TIFFType:
     if t == TIFFType.UnsignedShort:
         return TIFFType.UnsignedLong
@@ -224,11 +233,7 @@ struct Rational {{
 // Note that u16 is not include on purpose
 using Value = Variant<u8, String, u32, Rational<u32>, i32, Rational<i32>>;
 
-// This enum is progressively defined across sections but summarized in:
-// Appendix A: TIFF Tags Sorted by Number
-{export_enum_to_cpp(Compression)}
-
-{export_enum_to_cpp(Predictor)}
+{export_tag_related_enums(known_tags)}
 
 {HANDLE_TAG_SIGNATURE};