<commit_before>﻿using SPICA.Formats.Common;
using SPICA.Serialization;
using SPICA.Serialization.Attributes;

using System;
using System.Collections.Generic;
using System.IO;

namespace SPICA.Formats.CtrGfx.Animation
{
    public class GfxFloatKeyFrameGroup : ICustomSerialization
    {
        private float _StartFrame;
        private float _EndFrame;

        public GfxLoopType PreRepeat;
        public GfxLoopType PostRepeat;

        private ushort Padding;

        private uint CurveFlags;
        private uint CurveCount;
        private uint CurveRelPtr;

        public float StartFrame;
        public float EndFrame;

        private uint FormatFlags;

        private int KeysCount;

        private float InvDuration;

        [Ignore] public bool IsLinear;

        [Ignore] public KeyFrameQuantization Quantization;

        [Ignore] public readonly List<KeyFrame> KeyFrames;

        public bool Exists => KeyFrames.Count > 0;

        public GfxFloatKeyFrameGroup()
        {
            KeyFrames = new List<KeyFrame>();
        }

        void ICustomSerialization.Deserialize(BinaryDeserializer Deserializer)
        {
            Quantization = (KeyFrameQuantization)(FormatFlags >> 5);

            IsLinear = (FormatFlags & 4) != 0;

            float ValueScale  = 1;
            float ValueOffset = 0;
            float FrameScale  = 1;

            if (Quantization != KeyFrameQuantization.Hermite128       &&
                Quantization != KeyFrameQuantization.UnifiedHermite96 &&
                Quantization != KeyFrameQuantization.StepLinear64)
            {
                ValueScale  = Deserializer.Reader.ReadSingle();
                ValueOffset = Deserializer.Reader.ReadSingle();
                FrameScale  = Deserializer.Reader.ReadSingle();
            }

            for (int Index = 0; Index < KeysCount; Index++)
            {
                KeyFrame KF;

                switch (Quantization)
                {
                    case KeyFrameQuantization.Hermite128:       KF = Deserializer.Reader.ReadHermite128();       break;
                    case KeyFrameQuantization.Hermite64:        KF = Deserializer.Reader.ReadHermite64();        break;
                    case KeyFrameQuantization.Hermite48:        KF = Deserializer.Reader.ReadHermite48();        break;
                    case KeyFrameQuantization.UnifiedHermite96: KF = Deserializer.Reader.ReadUnifiedHermite96(); break;
                    case KeyFrameQuantization.UnifiedHermite48: KF = Deserializer.Reader.ReadUnifiedHermite48(); break;
                    case KeyFrameQuantization.UnifiedHermite32: KF = Deserializer.Reader.ReadUnifiedHermite32(); break;
                    case KeyFrameQuantization.StepLinear64:     KF = Deserializer.Reader.ReadStepLinear64();     break;
                    case KeyFrameQuantization.StepLinear32:     KF = Deserializer.Reader.ReadStepLinear32();     break;<commit_msg>Only uses 3 bits on cgfx segment quantization - this fixes an exception but I'm not sure it is the correct fix -- maybe its reading garbage<commit_after>﻿using SPICA.Formats.Common;
using SPICA.Serialization;
using SPICA.Serialization.Attributes;

using System;
using System.Collections.Generic;
using System.IO;

namespace SPICA.Formats.CtrGfx.Animation
{
    public class GfxFloatKeyFrameGroup : ICustomSerialization
    {
        private float _StartFrame;
        private float _EndFrame;

        public GfxLoopType PreRepeat;
        public GfxLoopType PostRepeat;

        private ushort Padding;

        private uint CurveFlags;
        private uint CurveCount;
        private uint CurveRelPtr;

        public float StartFrame;
        public float EndFrame;

        private uint FormatFlags;

        private int KeysCount;

        private float InvDuration;

        [Ignore] public bool IsLinear;

        [Ignore] public KeyFrameQuantization Quantization;

        [Ignore] public readonly List<KeyFrame> KeyFrames;

        public bool Exists => KeyFrames.Count > 0;

        public GfxFloatKeyFrameGroup()
        {
            KeyFrames = new List<KeyFrame>();
        }

        void ICustomSerialization.Deserialize(BinaryDeserializer Deserializer)
        {
            Quantization = (KeyFrameQuantization)((FormatFlags >> 5) & 7);

            IsLinear = (FormatFlags & 4) != 0;

            float ValueScale  = 1;
            float ValueOffset = 0;
            float FrameScale  = 1;

            if (Quantization != KeyFrameQuantization.Hermite128       &&
                Quantization != KeyFrameQuantization.UnifiedHermite96 &&
                Quantization != KeyFrameQuantization.StepLinear64)
            {
                ValueScale  = Deserializer.Reader.ReadSingle();
                ValueOffset = Deserializer.Reader.ReadSingle();
                FrameScale  = Deserializer.Reader.ReadSingle();
            }

            for (int Index = 0; Index < KeysCount; Index++)
            {
                KeyFrame KF;

                switch (Quantization)
                {
                    case KeyFrameQuantization.Hermite128:       KF = Deserializer.Reader.ReadHermite128();       break;
                    case KeyFrameQuantization.Hermite64:        KF = Deserializer.Reader.ReadHermite64();        break;
                    case KeyFrameQuantization.Hermite48:        KF = Deserializer.Reader.ReadHermite48();        break;
                    case KeyFrameQuantization.UnifiedHermite96: KF = Deserializer.Reader.ReadUnifiedHermite96(); break;
                    case KeyFrameQuantization.UnifiedHermite48: KF = Deserializer.Reader.ReadUnifiedHermite48(); break;
                    case KeyFrameQuantization.UnifiedHermite32: KF = Deserializer.Reader.ReadUnifiedHermite32(); break;
                    case KeyFrameQuantization.StepLinear64:     KF = Deserializer.Reader.ReadStepLinear64();     break;
                    case KeyFrameQuantization.StepLinear32:     KF = Deserializer.Reader.ReadStepLinear32();     break;
{'fraction_non_alphanumeric': 0.07054703135423616, 'fraction_numerical': 0.01667778519012675, 'mean_word_length': 2.146379853095488, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935886', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1526, 'n_words': 350}