Browse Source

Add handler parsing

pull/2633/head
Ynse Hoornenborg 3 years ago
parent
commit
5f9db61a50
  1. 5
      src/ImageSharp/Formats/Heic/Heic4CharCode.cs
  2. 1
      src/ImageSharp/Formats/Heic/Heic4CharCode.tt
  3. 25
      src/ImageSharp/Formats/Heic/HeicDecoderCore.cs

5
src/ImageSharp/Formats/Heic/Heic4CharCode.cs

@ -198,4 +198,9 @@ public enum Heic4CharCode : uint
/// </summary>
uri = 0x75726920U,
/// <summary>
/// Picture handler type.
/// </summary>
pict = 0x70696374U,
}

1
src/ImageSharp/Formats/Heic/Heic4CharCode.tt

@ -44,6 +44,7 @@
"cdsc", "Content Description",
"mime", "MIME type",
"uri ", "URI",
"pict", "Picture handler type",
};
#>

25
src/ImageSharp/Formats/Heic/HeicDecoderCore.cs

@ -192,21 +192,17 @@ internal sealed class HeicDecoderCore : IImageDecoderInternals
case Heic4CharCode.pitm:
this.ParsePrimaryItem(stream, length);
break;
case Heic4CharCode.dinf:
SkipBox(stream, length);
break;
case Heic4CharCode.hdlr:
SkipBox(stream, length);
break;
case Heic4CharCode.idat:
SkipBox(stream, length);
this.ParseHandler(stream, length);
break;
case Heic4CharCode.iloc:
this.ParseItemLocation(stream, length);
break;
case Heic4CharCode.dinf:
case Heic4CharCode.idat:
case Heic4CharCode.grpl:
case Heic4CharCode.ipro:
// TODO: Implement
// Silently skip these boxes.
SkipBox(stream, length);
break;
default:
@ -215,6 +211,19 @@ internal sealed class HeicDecoderCore : IImageDecoderInternals
}
}
private void ParseHandler(BufferedReadStream stream, long boxLength)
{
Span<byte> buffer = this.ReadIntoBuffer(stream, boxLength);
// Only read the handler type, to check if this is not a movie file.
int bytesRead = 8;
Heic4CharCode handlerType = (Heic4CharCode)BinaryPrimitives.ReadUInt32BigEndian(buffer[bytesRead..]);
if (handlerType != Heic4CharCode.pict)
{
throw new ImageFormatException("Not a picture file.");
}
}
private void ParseItemInfo(BufferedReadStream stream, long boxLength)
{
Span<byte> buffer = this.ReadIntoBuffer(stream, boxLength);

Loading…
Cancel
Save