mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibGfx/TIFF: Add support for Float and Double types
We previously were considering Float and Doubles as non-supported types.
But this was done in a sneaky way, by letting them hit the default case
in the `read_type` method. So, when I ported this function to the
generator we started to make this types flow into the system without a
proper support there. Since 3124c161
, we would have crashes on images
containing tags with a floating point value.
This commit is contained in:
parent
5d9fa2b9a9
commit
5dfa660a94
2 changed files with 11 additions and 3 deletions
|
@ -523,9 +523,12 @@ private:
|
||||||
return read_every_values.template operator()<Rational<u32>>();
|
return read_every_values.template operator()<Rational<u32>>();
|
||||||
case Type::SignedLong:
|
case Type::SignedLong:
|
||||||
return read_every_values.template operator()<i32>();
|
return read_every_values.template operator()<i32>();
|
||||||
;
|
|
||||||
case Type::SignedRational:
|
case Type::SignedRational:
|
||||||
return read_every_values.template operator()<Rational<i32>>();
|
return read_every_values.template operator()<Rational<i32>>();
|
||||||
|
case Type::Float:
|
||||||
|
return read_every_values.template operator()<float>();
|
||||||
|
case Type::Double:
|
||||||
|
return read_every_values.template operator()<double>();
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,6 +214,8 @@ def export_tag_related_enums(tags: List[Tag]) -> str:
|
||||||
def promote_type(t: TIFFType) -> TIFFType:
|
def promote_type(t: TIFFType) -> TIFFType:
|
||||||
if t == TIFFType.UnsignedShort:
|
if t == TIFFType.UnsignedShort:
|
||||||
return TIFFType.UnsignedLong
|
return TIFFType.UnsignedLong
|
||||||
|
if t == TIFFType.Float:
|
||||||
|
return TIFFType.Double
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
@ -232,6 +234,10 @@ def tiff_type_to_cpp(t: TIFFType, with_promotion: bool = True) -> str:
|
||||||
return 'u32'
|
return 'u32'
|
||||||
if t == TIFFType.UnsignedRational:
|
if t == TIFFType.UnsignedRational:
|
||||||
return 'TIFF::Rational<u32>'
|
return 'TIFF::Rational<u32>'
|
||||||
|
if t == TIFFType.Float:
|
||||||
|
return 'float'
|
||||||
|
if t == TIFFType.Double:
|
||||||
|
return 'double'
|
||||||
raise RuntimeError(f'Type "{t}" not recognized, please update tiff_type_to_read_only_cpp()')
|
raise RuntimeError(f'Type "{t}" not recognized, please update tiff_type_to_read_only_cpp()')
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,7 +403,7 @@ struct Rational {{
|
||||||
{export_promoter()}
|
{export_promoter()}
|
||||||
|
|
||||||
// Note that u16 is not include on purpose
|
// Note that u16 is not include on purpose
|
||||||
using Value = Variant<ByteBuffer, String, u32, Rational<u32>, i32, Rational<i32>>;
|
using Value = Variant<ByteBuffer, String, u32, Rational<u32>, i32, Rational<i32>, double>;
|
||||||
|
|
||||||
{export_tag_related_enums(known_tags)}
|
{export_tag_related_enums(known_tags)}
|
||||||
|
|
||||||
|
@ -487,7 +493,6 @@ def generate_tag_handler(tag: Tag) -> str:
|
||||||
|
|
||||||
|
|
||||||
def generate_tag_handler_file(tags: List[Tag]) -> str:
|
def generate_tag_handler_file(tags: List[Tag]) -> str:
|
||||||
|
|
||||||
formatter_for_tag_with_enum = '\n'.join([fR""" case {tag.id}:
|
formatter_for_tag_with_enum = '\n'.join([fR""" case {tag.id}:
|
||||||
return MUST(String::from_utf8(
|
return MUST(String::from_utf8(
|
||||||
name_for_enum_tag_value(static_cast<{tag.associated_enum.export_name()}>(v.get<u32>()))));"""
|
name_for_enum_tag_value(static_cast<{tag.associated_enum.export_name()}>(v.get<u32>()))));"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue