mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-16 19:42:24 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/5dfa660a94 Pull-request: https://github.com/SerenityOS/serenity/pull/22787 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 11 additions and 3 deletions
|
@ -523,9 +523,12 @@ private:
|
|||
return read_every_values.template operator()<Rational<u32>>();
|
||||
case Type::SignedLong:
|
||||
return read_every_values.template operator()<i32>();
|
||||
;
|
||||
case Type::SignedRational:
|
||||
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:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -214,6 +214,8 @@ def export_tag_related_enums(tags: List[Tag]) -> str:
|
|||
def promote_type(t: TIFFType) -> TIFFType:
|
||||
if t == TIFFType.UnsignedShort:
|
||||
return TIFFType.UnsignedLong
|
||||
if t == TIFFType.Float:
|
||||
return TIFFType.Double
|
||||
return t
|
||||
|
||||
|
||||
|
@ -232,6 +234,10 @@ def tiff_type_to_cpp(t: TIFFType, with_promotion: bool = True) -> str:
|
|||
return 'u32'
|
||||
if t == TIFFType.UnsignedRational:
|
||||
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()')
|
||||
|
||||
|
||||
|
@ -397,7 +403,7 @@ struct Rational {{
|
|||
{export_promoter()}
|
||||
|
||||
// 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)}
|
||||
|
||||
|
@ -487,7 +493,6 @@ def generate_tag_handler(tag: Tag) -> str:
|
|||
|
||||
|
||||
def generate_tag_handler_file(tags: List[Tag]) -> str:
|
||||
|
||||
formatter_for_tag_with_enum = '\n'.join([fR""" case {tag.id}:
|
||||
return MUST(String::from_utf8(
|
||||
name_for_enum_tag_value(static_cast<{tag.associated_enum.export_name()}>(v.get<u32>()))));"""
|
||||
|
|
Loading…
Reference in a new issue