예제 #1
0
        public LimgState()
        {
            _limg = new Limg();

            EncodingDefinition = LimgSupport.LimgPaletteFormats.ToPaletteDefinition();
            EncodingDefinition.AddIndexEncodings(LimgSupport.LimgFormats);
        }
예제 #2
0
        public GxtState()
        {
            _gxt = new GXT();

            EncodingDefinition = GxtSupport.GxtFormats.ToColorDefinition();
            EncodingDefinition.AddIndexEncodings(GxtSupport.GxtIndexFormats);
        }
예제 #3
0
        /// <summary>
        /// Defines the encoding method to use for the server.
        /// </summary>
        /// <param name="encoding"></param>
        public void SetEncodingMode(EncodingDefinition encoding)
        {
            m_encodingMode = Library.CreateStreamEncoding <TKey, TValue>(encoding);
            m_stream.Write((byte)ServerCommand.SetEncodingMethod);
            encoding.Save(m_stream);
            m_stream.Flush();

            var command = (ServerResponse)m_stream.ReadUInt8();

            switch (command)
            {
            case ServerResponse.UnhandledException:
                string exception = m_stream.ReadString();
                throw new Exception("Server UnhandledExcetion: \n" + exception);

            case ServerResponse.UnknownEncodingMethod:
                throw new Exception("Server does not recgonize encoding method");

            case ServerResponse.EncodingMethodAccepted:
                break;

            default:
                throw new Exception("Unknown server response: " + command.ToString());
            }
        }
예제 #4
0
        private Bitmap DecodeImage(IProgressContext progress = null)
        {
            if (_decodedImage != null)
            {
                return(_decodedImage);
            }

            Func <Bitmap> decodeImageAction;

            if (IsIndexed)
            {
                var transcoder = CreateImageConfiguration(ImageFormat, PaletteFormat)
                                 .Transcode.With(EncodingDefinition.GetIndexEncoding(ImageFormat).IndexEncoding)
                                 .TranscodePalette.With(EncodingDefinition.GetPaletteEncoding(PaletteFormat))
                                 .Build();

                decodeImageAction = () => transcoder.Decode(ImageInfo.ImageData, ImageInfo.PaletteData, ImageInfo.ImageSize, progress);
            }
            else
            {
                var transcoder = CreateImageConfiguration(ImageFormat, PaletteFormat)
                                 .Transcode.With(EncodingDefinition.GetColorEncoding(ImageFormat))
                                 .Build();

                decodeImageAction = () => transcoder.Decode(ImageInfo.ImageData, ImageInfo.ImageSize, progress);
            }

            ExecuteActionWithProgress(() => _decodedImage = decodeImageAction(), progress);

            _bestImage ??= _decodedImage;

            return(_decodedImage);
        }
예제 #5
0
        public override void Load(Stream stream)
        {
            TestForEditable();
            byte version = stream.ReadNextByte();

            switch (version)
            {
            case 1:
                m_directoryMethod       = (ArchiveDirectoryMethod)stream.ReadInt32();
                m_prefix                = stream.ReadString();
                m_pendingExtension      = stream.ReadString();
                m_finalExtension        = stream.ReadString();
                m_desiredRemainingSpace = stream.ReadInt64();
                m_encodingMethod        = new EncodingDefinition(stream);
                int cnt = stream.ReadInt32();
                m_writePath.Clear();
                while (cnt > 0)
                {
                    cnt--;
                    m_writePath.Add(stream.ReadString());
                }
                cnt = stream.ReadInt32();
                m_flags.Clear();
                while (cnt > 0)
                {
                    cnt--;
                    m_flags.Add(stream.ReadGuid());
                }
                break;

            default:
                throw new VersionNotFoundException("Unknown Version Code: " + version);
            }
        }
예제 #6
0
        public static EncodingDefinition GetEncodingDefinition(MtTexPlatform platform)
        {
            var definition = new EncodingDefinition();

            switch (platform)
            {
            case MtTexPlatform.N3DS:
                definition.AddColorEncodings(CtrFormats);
                break;

            case MtTexPlatform.Switch:
                definition.AddColorEncodings(SwitchFormats);
                break;

            case MtTexPlatform.PS3:
                definition.AddColorEncodings(Ps3Formats);
                definition.AddColorShaders(Shaders);
                break;

            case MtTexPlatform.Mobile:
                definition.AddColorEncodings(MobileFormats);
                break;

            case MtTexPlatform.Wii:
                throw new InvalidOperationException("Cannot obtain encoding definition for Wii MT Tex.");
            }

            return(definition);
        }
예제 #7
0
        private void CreateArchiveFile <TKey, TValue>(SubFileName fileName, EncodingDefinition storageMethod, int maxSortedTreeBlockSize)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            if (maxSortedTreeBlockSize < 1024)
            {
                throw new ArgumentOutOfRangeException(nameof(maxSortedTreeBlockSize), "Must be greater than 1024");
            }
            if ((object)storageMethod == null)
            {
                throw new ArgumentNullException("storageMethod");
            }

            using (TransactionalEdit trans = m_fileStructure.BeginEdit())
            {
                using (SubFileStream fs = trans.CreateFile(fileName))
                    using (BinaryStream bs = new BinaryStream(fs))
                    {
                        int blockSize = m_fileStructure.Snapshot.Header.DataBlockSize;

                        while (blockSize > maxSortedTreeBlockSize)
                        {
                            blockSize >>= 2;
                        }

                        SortedTree <TKey, TValue> tree = SortedTree <TKey, TValue> .Create(bs, blockSize, storageMethod);

                        tree.Flush();
                    }
                trans.ArchiveType = FileType;
                trans.CommitAndDispose();
            }
        }
예제 #8
0
        /// <summary>
        /// Loads a <see cref="DatabaseInfo"/> from stream.
        /// </summary>
        /// <param name="stream"></param>
        public DatabaseInfo(BinaryStreamBase stream)
        {
            byte version = stream.ReadUInt8();

            switch (version)
            {
            case 1:
                DatabaseName = stream.ReadString();
                KeyTypeID    = stream.ReadGuid();
                ValueTypeID  = stream.ReadGuid();
                int count = stream.ReadInt32();
                EncodingDefinition[] definitions = new EncodingDefinition[count];
                for (int x = 0; x < count; x++)
                {
                    definitions[x] = new EncodingDefinition(stream);
                }
                SupportedStreamingModes = new ReadOnlyCollection <EncodingDefinition>(definitions);
                KeyType   = Library.GetSortedTreeType(KeyTypeID);
                ValueType = Library.GetSortedTreeType(ValueTypeID);
                break;

            default:
                throw new VersionNotFoundException("Unknown version code.");
            }
        }
예제 #9
0
        public GcBnrState()
        {
            _bnr = new GcBnr();

            EncodingDefinition = new EncodingDefinition();
            EncodingDefinition.AddColorEncoding(0, new Rgba(5, 5, 5, 1, "ABGR", ByteOrder.BigEndian));
        }
예제 #10
0
        internal void InitializeCreate(EncodingDefinition treeNodeType, int blockSize)
        {
            if (m_isInitialized)
            {
                throw new Exception("Duplicate calls to Initialize");
            }
            if ((object)treeNodeType == null)
            {
                throw new ArgumentNullException("treeNodeType");
            }


            m_isInitialized = true;

            m_header.TreeNodeType = treeNodeType;
            m_header.BlockSize    = blockSize;

            m_header.RootNodeLevel        = 0;
            m_header.RootNodeIndexAddress = 1;
            m_header.LastAllocatedBlock   = 1;

            Initialize();

            LeafStorage.CreateEmptyNode(m_header.RootNodeIndexAddress);
            m_header.IsDirty = true;
            m_header.SaveHeader(Stream);
        }
예제 #11
0
 private void AssertPaletteFormatExists(int paletteFormat)
 {
     if (EncodingDefinition.GetPaletteEncoding(paletteFormat) == null)
     {
         throw new InvalidOperationException($"The palette format '{paletteFormat}' is not supported by the plugin.");
     }
 }
예제 #12
0
        public void TestArchiveWriter()
        {
            Random r = new Random(3);

            _ = new EncodingDefinition(EncodingDefinition.FixedSizeIndividualGuid, EncodingDefinition.FixedSizeIndividualGuid);
            AdvancedServerDatabaseConfig <AmiKey, AmiKey> config = new AdvancedServerDatabaseConfig <AmiKey, AmiKey>("KV2CPQ", "C:\\Temp\\AMI", true);

            using (SnapServer server = new SnapServer(config))
            {
                using (SnapClient client = SnapClient.Connect(server))
                    using (ClientDatabaseBase <AmiKey, AmiKey> db = client.GetDatabase <AmiKey, AmiKey>("KV2CPQ"))
                    {
                        int       count = 10000000;
                        Stopwatch sw    = new Stopwatch();
                        sw.Start();
                        AmiKey key   = new AmiKey();
                        AmiKey value = new AmiKey();

                        for (int x = count; x >= 0; x--)
                        {
                            key.Timestamp = (ulong)r.Next();
                            key.TableId   = r.Next();
                            db.Write(key, value);
                        }

                        sw.Stop();

                        Console.WriteLine(count / sw.Elapsed.TotalSeconds / 1000000);

                        Console.WriteLine(count);
                    }
            }
        }
예제 #13
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddColorEncodings(CitraFormats);

            return(definition);
        }
예제 #14
0
        public static EncodingDefinition GetCafeDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddColorEncodings(Nw4cImageFormats.CafeFormats);

            return(definition);
        }
 /// <summary>
 /// Creates a <see cref="ArchiveInitializer{TKey,TValue}"/> that will reside in memory.
 /// </summary>
 /// <param name="encodingMethod">the encoding method to use for the archive file.</param>
 /// <param name="flags">flags to include in the archive that is created.</param>
 /// <returns></returns>
 public void ConfigureInMemory(EncodingDefinition encodingMethod, params Guid[] flags)
 {
     TestForEditable();
     Initialize();
     IsMemoryArchive = true;
     Flags.AddRange(flags);
     EncodingMethod = encodingMethod;
 }
예제 #16
0
        public BnrState()
        {
            _bnr = new Bnr();

            EncodingDefinition = new EncodingDefinition();
            EncodingDefinition.AddPaletteEncoding(0, ImageFormats.Rgb555());
            EncodingDefinition.AddIndexEncoding(0, ImageFormats.I4(BitOrder.LeastSignificantBitFirst), new[] { 0 });
        }
예제 #17
0
 private void AssertImageFormatExists(int imageFormat)
 {
     if (EncodingDefinition.GetColorEncoding(imageFormat) == null &&
         EncodingDefinition.GetIndexEncoding(imageFormat) == null)
     {
         throw new InvalidOperationException($"The image format '{imageFormat}' is not supported by the plugin.");
     }
 }
예제 #18
0
        /// <summary>
        /// Decode given palette data without buffering.
        /// </summary>
        /// <param name="paletteData">Palette data to decode.</param>
        /// <param name="context"></param>
        /// <returns>Decoded palette.</returns>
        private IList <Color> DecodePalette(byte[] paletteData, IProgressContext context = null)
        {
            var paletteEncoding = EncodingDefinition.GetPaletteEncoding(PaletteFormat);

            return(paletteEncoding
                   .Load(paletteData, new EncodingLoadContext(new Size(1, paletteData.Length * 8 / paletteEncoding.BitsPerValue), TaskCount))
                   .ToArray());
        }
예제 #19
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddColorEncodings(Formats.ToDictionary(x => (int)x.Key, y => y.Value));

            return(definition);
        }
예제 #20
0
        public BtxState()
        {
            _btx = new BTX();

            EncodingDefinition = BtxSupport.Encodings.ToColorDefinition();
            EncodingDefinition.AddPaletteEncodings(BtxSupport.PaletteEncodings);
            EncodingDefinition.AddIndexEncodings(BtxSupport.IndexEncodings);
        }
예제 #21
0
        public ECDPNcgrState()
        {
            _ncgr = new ECDPNcgr();

            EncodingDefinition = new EncodingDefinition();
            EncodingDefinition.AddPaletteEncoding(0, new Rgba(5, 5, 5, "BGR"));
            EncodingDefinition.AddIndexEncoding(3, new Index(4), new[] { 0 });
            EncodingDefinition.AddIndexEncoding(4, new Index(8), new[] { 0 });
        }
예제 #22
0
        public NcgrState()
        {
            _ncgr = new Ncgr();

            EncodingDefinition = new EncodingDefinition();
            EncodingDefinition.AddPaletteEncoding(0, new Rgba(5, 5, 5, "BGR"));
            EncodingDefinition.AddIndexEncoding(3, ImageFormats.I4(BitOrder.LeastSignificantBitFirst), new[] { 0 });
            EncodingDefinition.AddIndexEncoding(4, ImageFormats.I8(), new[] { 0 });
        }
예제 #23
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddPaletteEncodings(PaletteFormats);
            definition.AddIndexEncodings(IndexFormats.Select(x => (x.Key, new IndexEncodingDefinition(x.Value, new[] { 0 }))).ToArray());

            return(definition);
        }
예제 #24
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddColorEncodings(ColorFormats);
            definition.AddPaletteEncodings(PaletteFormats);
            definition.AddIndexEncodings(IndexFormats);

            return(definition);
        }
예제 #25
0
        /// <summary>
        /// Writes the supplied stream to the binary stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="blockSize"></param>
        /// <param name="treeNodeType"></param>
        /// <param name="treeStream"></param>
        public static void Create(BinaryStreamPointerBase stream, int blockSize, EncodingDefinition treeNodeType, TreeStream <TKey, TValue> treeStream)
        {
            if (stream is null)
            {
                throw new ArgumentNullException("stream");
            }
            if (treeStream is null)
            {
                throw new ArgumentNullException("stream");
            }
            if (treeNodeType is null)
            {
                throw new ArgumentNullException("treeNodeType");
            }
            if (!(treeStream.IsAlwaysSequential && treeStream.NeverContainsDuplicates))
            {
                throw new ArgumentException("Stream must gaurentee sequential reads and that it never will contain a duplicate", "treeStream");
            }

            SortedTreeHeader header = new SortedTreeHeader();

            header.TreeNodeType         = treeNodeType;
            header.BlockSize            = blockSize;
            header.RootNodeLevel        = 0;
            header.RootNodeIndexAddress = 1;
            header.LastAllocatedBlock   = 1;

            Func <uint> getNextNewNodeIndex = () =>
            {
                header.LastAllocatedBlock++;
                return(header.LastAllocatedBlock);
            };

            SparseIndexWriter <TKey> indexer = new SparseIndexWriter <TKey>();

            NodeWriter <TKey, TValue> .Create(treeNodeType, stream, header.BlockSize, header.RootNodeLevel, header.RootNodeIndexAddress, getNextNewNodeIndex, indexer, treeStream);

            while (indexer.Count > 0)
            {
                indexer.SwitchToReading();
                header.RootNodeLevel++;
                header.RootNodeIndexAddress = getNextNewNodeIndex();

                SparseIndexWriter <TKey> indexer2 = new SparseIndexWriter <TKey>();
                NodeWriter <TKey, SnapUInt32> .Create(EncodingDefinition.FixedSizeCombinedEncoding, stream, header.BlockSize, header.RootNodeLevel, header.RootNodeIndexAddress, getNextNewNodeIndex, indexer2, indexer);

                indexer.Dispose();
                indexer = indexer2;
            }

            indexer.Dispose();

            header.IsDirty = true;
            header.SaveHeader(stream);
        }
예제 #26
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddColorEncodings(ColorFormats.Select(x => ((int)x.Key, x.Value)).ToArray());

            definition.AddPaletteEncodings(PaletteFormats.Select(x => ((int)x.Key, x.Value)).ToArray());
            definition.AddIndexEncodings(IndexFormats.Select(x => ((int)x.Key, new IndexEncodingDefinition(x.Value, PaletteFormats.Keys.Select(x => (int)x).ToArray()))).ToArray());

            return(definition);
        }
예제 #27
0
        public BitmapKanvasImage(Bitmap image)
        {
            var encoding = GetImageEncoding(image);

            EncodingDefinition = new EncodingDefinition();
            EncodingDefinition.AddColorEncoding(0, encoding);

            BitDepth = encoding.BitDepth;

            _image = image;
        }
예제 #28
0
        public static EncodingDefinition GetEncodingDefinition()
        {
            var definition = new EncodingDefinition();

            definition.AddPaletteEncodings(PaletteEncodings);
            definition.AddIndexEncodings(IndexFormats.Select(x => (x.Key, new IndexEncodingDefinition(x.Value, new[] { 0x6C09, 0x6409 }))).ToArray());

            definition.AddPaletteShader(0x6C09, new HtexColorShader());

            return(definition);
        }
예제 #29
0
        /// <summary>
        /// Creates a new instance of <see cref="KanvasImage"/>.
        /// </summary>
        /// <param name="encodingDefinition">The encoding definition for the image info.</param>
        /// <param name="imageInfo">The image info to represent.</param>
        public KanvasImage(EncodingDefinition encodingDefinition, ImageInfo imageInfo)
        {
            ContractAssertions.IsNotNull(encodingDefinition, nameof(encodingDefinition));
            ContractAssertions.IsNotNull(imageInfo, nameof(imageInfo));

            if (!encodingDefinition.Supports(imageInfo))
            {
                throw new InvalidOperationException("The encoding definition can not support the image info.");
            }

            _encodingDefinition = encodingDefinition;
            ImageInfo           = imageInfo;
        }
예제 #30
0
        /// <summary>
        /// Opens the default table for this TKey and TValue. If it does not exists,
        /// it will be created with the provided compression method.
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="storageMethod">The method of compression to utilize in this table.</param>
        /// <param name="maxSortedTreeBlockSize">the maximum desired block size for a SortedTree. Must be at least 1024.</param>
        /// <returns></returns>
        public SortedTreeTable <TKey, TValue> OpenOrCreateTable <TKey, TValue>(EncodingDefinition storageMethod, int maxSortedTreeBlockSize = 4096)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            if ((object)storageMethod == null)
            {
                throw new ArgumentNullException("storageMethod");
            }

            SubFileName fileName = GetFileName <TKey, TValue>();

            return(OpenOrCreateTable <TKey, TValue>(storageMethod, fileName, maxSortedTreeBlockSize));
        }
 /// <summary>
 /// Reads the header data.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="treeNodeType"></param>
 /// <param name="blockSize"></param>
 internal static void ReadHeader(BinaryStreamBase stream, out EncodingDefinition treeNodeType, out int blockSize)
 {
     stream.Position = 0;
     byte version = stream.ReadUInt8();
     if (version == 109)
     {
         stream.Position = 0;
         stream.ReadGuid();
         treeNodeType = new EncodingDefinition(stream.ReadGuid());
         blockSize = stream.ReadInt32();
     }
     else if (version == 1)
     {
         blockSize = stream.ReadInt32();
         treeNodeType = new EncodingDefinition(stream);
     }
     else
     {
         throw new VersionNotFoundException();
     }
 }
 /// <summary>
 /// Loads a <see cref="DatabaseInfo"/> from stream.
 /// </summary>
 /// <param name="stream"></param>
 public DatabaseInfo(BinaryStreamBase stream)
 {
     byte version = stream.ReadUInt8();
     switch (version)
     {
         case 1:
             DatabaseName = stream.ReadString();
             KeyTypeID = stream.ReadGuid();
             ValueTypeID = stream.ReadGuid();
             var count = stream.ReadInt32();
             EncodingDefinition[] definitions = new EncodingDefinition[count];
             for (int x = 0; x < count; x++)
             {
                 definitions[x] = new EncodingDefinition(stream);
             }
             SupportedStreamingModes = new ReadOnlyCollection<EncodingDefinition>(definitions);
             KeyType = Library.GetSortedTreeType(KeyTypeID);
             ValueType = Library.GetSortedTreeType(ValueTypeID);
             break;
         default:
             throw new VersionNotFoundException("Unknown version code.");
     }
 }