예제 #1
0
        public override HashSet<ChunkContainer> GetChunks(LocationPool locationPool)
        {
            HashSet<ChunkContainer> result = new HashSet<ChunkContainer>();

            if (Locations.Count == 0)
            {
                return result;
            }

            if (IsRectangle())
            {
                TransparentRectangleChunk rectangleChunk = new TransparentRectangleChunk();
                rectangleChunk.Origin = BoundingBox.UpperLeft;
                rectangleChunk.Width = BoundingBox.Width();
                rectangleChunk.Height = BoundingBox.Height();
                TransparentRectangleChunkContainer container = new TransparentRectangleChunkContainer();
                container.Chunk = rectangleChunk;
                container.Locations = Locations;
                result.Add(container);
                return result;
            }

            TransparentBitPlaneChunk transparentChunk = new TransparentBitPlaneChunk();
            transparentChunk.Origin = BoundingBox.UpperLeft;
            transparentChunk.Width = BoundingBox.Width();
            transparentChunk.Height = BoundingBox.Height();
            transparentChunk.Initialize();
            TransparentBitPlaneChunkContainer transparentChunkContainer = new TransparentBitPlaneChunkContainer();
            transparentChunkContainer.Chunk = transparentChunk;
            transparentChunkContainer.Locations = Locations;
            foreach (Location location in Locations)
            {
                transparentChunk.SetColor(location.Point.X, location.Point.Y);
            }

            result.Add(transparentChunkContainer);
            return result;
        }
예제 #2
0
파일: Frame.cs 프로젝트: neuroradiology/Sxz
        public void SetData(byte[] data)
        {
            //skip label and size
            int index = 0;
            PaletteChunk paletteChunk = new DefaultPaletteChunk();
            while (index < data.Length)
            {
                string label = Encoding.ASCII.GetString(data, index, 2);

                //case statement would work better here
                if (label.Equals(ColorBitPlaneChunk.Label))
                {
                  int size = BitConverter.ToInt16(data, index + 2);
                  byte[] chunkData = new byte[size + 4];
                  Array.Copy(data, index, chunkData, 0, chunkData.Length);
                  ColorBitPlaneChunk colorChunk = new ColorBitPlaneChunk();
                  colorChunk.Palette = paletteChunk;
                  colorChunk.SetData(chunkData);
                  Chunks.Add(colorChunk);
                  index += size + 4;
                }
                else if (label.Equals(ColorRectangleChunk.Label))
                {
                    int size = BitConverter.ToInt16(data, index + 2);
                    byte[] chunkData = new byte[size + 4];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    ColorRectangleChunk colorRectangleChunk = new ColorRectangleChunk();
                    colorRectangleChunk.Palette = paletteChunk;
                    colorRectangleChunk.SetData(chunkData);
                    Chunks.Add(colorRectangleChunk);
                    index += size + 4;
                }
                else if (label.Equals(MonoBitPlaneChunk.Label))
                {
                    int size = BitConverter.ToInt16(data, index + 2);
                    byte[] chunkData = new byte[size + 4];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    MonoBitPlaneChunk monoChunk = new MonoBitPlaneChunk();
                    monoChunk.Palette = paletteChunk;
                    monoChunk.SetData(chunkData);
                    Chunks.Add(monoChunk);
                    index += size + 4;
                }
                else if (label.Equals(TransparentBitPlaneChunk.Label))
                {
                    int size = BitConverter.ToInt16(data, index + 2);
                    byte[] chunkData = new byte[size + 4];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    TransparentBitPlaneChunk transparentChunk = new TransparentBitPlaneChunk();
                    transparentChunk.SetData(chunkData);
                    Chunks.Add(transparentChunk);
                    index += size + 4;
                }
                else if (label.Equals(MonoRectangleChunk.Label))
                {
                    //must be background
                    MonoRectangleChunk chunk = new MonoRectangleChunk();
                    byte[] chunkData = new byte[11];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    chunk.Palette = paletteChunk;
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += chunkData.Length;
                }
                else if (label.Equals(TransparentRectangleChunk.Label))
                {
                    //must be background
                    TransparentRectangleChunk chunk = new TransparentRectangleChunk();
                    byte[] chunkData = new byte[10];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += chunkData.Length;
                }
                else if (label.Equals(PaletteChunk.Label))
                {
                    //must be background
                    PaletteChunk chunk = new PaletteChunk();
                    int count = (data[index + 2] + 1) * 3;
                    byte[] chunkData = new byte[count + 3];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += chunkData.Length;
                    paletteChunk = chunk;
                }
                else if (label.Equals(DefaultPaletteChunk.Label))
                {
                    //must be background
                    DefaultPaletteChunk chunk = new DefaultPaletteChunk();
                    int count = (data[index + 2] + 1) * 3;
                    byte[] chunkData = new byte[count + 3];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += chunkData.Length;
                    paletteChunk = chunk;
                }
                else if (label.Equals(GrayBitPlaneChunk.Label))
                {
                    int size = BitConverter.ToInt16(data, index + 2);
                    byte[] chunkData = new byte[size + 4];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    GrayBitPlaneChunk chunk = new GrayBitPlaneChunk();
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += size + 4;
                }
                else if (label.Equals(BlackWhiteBitPlaneChunk.Label))
                {
                    int size = BitConverter.ToInt16(data, index + 2);
                    byte[] chunkData = new byte[size + 4];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    BlackWhiteBitPlaneChunk chunk = new BlackWhiteBitPlaneChunk();
                    chunk.SetData(chunkData);
                    Chunks.Add(chunk);
                    index += size + 4;
                }
                else if (label.Equals(BackgroundChunk.Label))
                {
                    //Console.WriteLine("default to background with label " + label);
                    //must be background
                    BackgroundChunk background = new BackgroundChunk();
                    background.Palette = paletteChunk;
                    byte[] chunkData = new byte[3];
                    Array.Copy(data, index, chunkData, 0, chunkData.Length);
                    background.SetData(chunkData);
                    Chunks.Add(background);
                    index += chunkData.Length;
                }
                else
                {
                    Console.WriteLine("Invalid chunk label " + label);
                    Console.WriteLine("At " + index + " " + Chunks.Count);
                    if (Chunks.Last() != null)
                    {
                        Console.WriteLine("Last chunk was " + Chunks.Last().Origin.ToString());
                    }

                    return;
                }
            }
        }