From 858616690659c86ee28e3e97bef39a904baa62a2 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Wed, 18 Apr 2018 15:26:54 -0700 Subject: [PATCH] Pack GifGraphicControlExtension value directly --- .../Sections/GifGraphicControlExtension.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs index b7b5b090c7..7ec5f20309 100644 --- a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs +++ b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs @@ -79,14 +79,28 @@ namespace SixLabors.ImageSharp.Formats.Gif public static byte GetPackedValue(DisposalMethod disposalMethod, bool userInputFlag = false, bool transparencyFlag = false) { - PackedField field = default; + /* + Reserved | 3 Bits + Disposal Method | 3 Bits + User Input Flag | 1 Bit + Transparent Color Flag | 1 Bit + */ - // --------------------------------------- // Reserved | 3 bits - field.SetBits(3, 3, (int)disposalMethod); // Disposal Method | 3 bits - field.SetBit(6, userInputFlag); // User Input Flag | 1 bit - field.SetBit(7, transparencyFlag); // Transparent Color Flag | 1 bit + byte value = 0; - return field.Byte; + value |= (byte)((int)disposalMethod << 2); + + if (userInputFlag) + { + value |= 1 << 1; + } + + if (transparencyFlag) + { + value |= 1; + } + + return value; } } } \ No newline at end of file