Пример #1
0
        public override HashSet<ChunkContainer> GetChunks(LocationPool locationPool)
        {
            HashSet<ChunkContainer> result = new HashSet<ChunkContainer>();

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

            if (Palette.Count() == 1)
            {
                if (IsRectangle())
                {
                    MonoRectangleChunk rectangleChunk = new MonoRectangleChunk();
                    rectangleChunk.Origin = BoundingBox.UpperLeft;
                    rectangleChunk.Width = BoundingBox.Width();
                    rectangleChunk.Height = BoundingBox.Height();
                    MonoRectangleChunkContainer container = new MonoRectangleChunkContainer();
                    container.Chunk = rectangleChunk;
                    container.Locations = GetLocations(BoundingBox);
                    container.Color = Palette.Colors.First();
                    result.Add(container);
                    return result;
                }

                //output a monochunk?
                MonoBitPlaneChunk monoColorChunk = new MonoBitPlaneChunk();
                monoColorChunk.Width = BoundingBox.Width();
                monoColorChunk.Height = BoundingBox.Height();
                monoColorChunk.Initialize();
                monoColorChunk.Origin = BoundingBox.UpperLeft;

                foreach (Location location in Locations)
                {
                    monoColorChunk.SetColor(location.Point.X, location.Point.Y);
                }

                MonoBitPlaneChunkContainer monoContainer = new MonoBitPlaneChunkContainer();
                monoContainer.Chunk = monoColorChunk;
                monoContainer.Locations = Locations;
                monoContainer.Color = Palette.Colors.First();
                result.Add(monoContainer);

                return result;

            }

            if (IsRectangle())
            {
                MultiColorRectangleChunkContainer container = new MultiColorRectangleChunkContainer();
                ColorRectangleChunk rectangleChunk = new ColorRectangleChunk();
                rectangleChunk.Origin = BoundingBox.UpperLeft;
                rectangleChunk.Width = BoundingBox.Width();
                rectangleChunk.Height = BoundingBox.Height();
                //rectangleChunk.Direction = Direction.Left;
                rectangleChunk.Initialize();
                container.Chunk = rectangleChunk;
                container.Locations = Locations;
                rectangleChunk.Palette = Palette.GetPaletteChunk();

                foreach (Location location in Locations)
                {
                    rectangleChunk.SetColor(location.Color, location.Point.X, location.Point.Y);
                }

                result.Add(container);
                return result;
            }

            //Don't break it into further rectangles right now... just output a bitplane
            MultiColorBitPlaneChunkContainer chunkContainer = new MultiColorBitPlaneChunkContainer();
            ColorBitPlaneChunk colorBitPlaneChunk = new ColorBitPlaneChunk();
            colorBitPlaneChunk.Origin = BoundingBox.UpperLeft;
            colorBitPlaneChunk.Height = BoundingBox.Height();
            colorBitPlaneChunk.Width = BoundingBox.Width();
            colorBitPlaneChunk.Palette = Palette.GetPaletteChunk();
            colorBitPlaneChunk.Initialize();
            chunkContainer.Chunk = colorBitPlaneChunk;
            chunkContainer.Locations = Locations;

            foreach (Location location in Locations)
            {
                //bitmask must use local coordinates
                colorBitPlaneChunk.SetColor(location.Color, location.Point.X, location.Point.Y);
            }

            result.Add(chunkContainer);

            return result;
        }
Пример #2
0
        /// <summary>
        /// To return a RectangleChunk we will need the bounding box and a check for missing locations
        /// </summary>
        /// <returns></returns>
        public override HashSet<ChunkContainer> GetChunks(LocationPool locationPool)
        {
            HashSet<ChunkContainer> result = new HashSet<ChunkContainer>();

            if (IsRectangle())
            {
                MonoRectangleChunk rectangleChunk = new MonoRectangleChunk();
                rectangleChunk.Origin = BoundingBox.UpperLeft;
                rectangleChunk.Width = BoundingBox.Width();
                rectangleChunk.Height = BoundingBox.Height();
                MonoRectangleChunkContainer container = new MonoRectangleChunkContainer();
                container.Chunk = rectangleChunk;
                container.Locations = GetLocations(BoundingBox);
                //container.AdditionalSize = NewColorCount(locationPool.Palette);
                container.Color = Color;
                result.Add(container);
                return result;
            }

            //break up into many rectangles and return rest here
            HashSet<Location> locations = new HashSet<Location>(Locations);
            HashSet<BoundingBox> rectangles = GetAllRectangles(locations, BoundingBox);

            foreach (BoundingBox rectangle in rectangles)
            {
                MonoRectangleChunk rectangleChunk = new MonoRectangleChunk();
                rectangleChunk.Origin = rectangle.UpperLeft;
                rectangleChunk.Width = rectangle.Width();
                rectangleChunk.Height = rectangle.Height();
                MonoRectangleChunkContainer container = new MonoRectangleChunkContainer();
                container.Chunk = rectangleChunk;
                container.Color = Color;
                //container.AdditionalSize = NewColorCount(locationPool.Palette);
                container.Locations = GetLocations(rectangle);
                result.Add(container);
            }

            //now for the remaining locations, create monocolorchunks
            BoundingBox remaining = new BoundingBox();
            foreach (Location location in locations)
            {
                remaining.Add(location.Point);
            }

            MonoBitPlaneChunk monoColorChunk = new MonoBitPlaneChunk();
            monoColorChunk.Width = remaining.Width();
            monoColorChunk.Height = remaining.Height();
            monoColorChunk.Initialize();
            monoColorChunk.Origin = remaining.UpperLeft;

            foreach (Location location in locations)
            {
                monoColorChunk.SetColor(location.Point.X, location.Point.Y);
            }

            MonoBitPlaneChunkContainer monoContainer = new MonoBitPlaneChunkContainer();
            monoContainer.Chunk = monoColorChunk;
            monoContainer.Locations = GetLocations(remaining);
            monoContainer.Color = Color;
            result.Add(monoContainer);

            return result;
        }