Exemplo n.º 1
0
        public void MultiShade32( RawImage image, out int[] colorbuffer, out int[] idbuffer, out int[] borderbuffer )
        {
            colorbuffer = new int[image.PixelCount];
            idbuffer = new int[image.PixelCount];
            borderbuffer = new int[image.PixelCount];

            int height = image.Size.Height;
            int width = image.Size.Width;
            Pixel[,] memory = image.Memory;

            int bufidx = 0;
            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    // shading
                    byte color = (byte)(0xFF-(memory[x,y].Color << 2));
                    colorbuffer[bufidx] = (color << 16) | (color << 8) | color;

                    // don't bother for id, as it won't be used anyway.
                    //idbuffer[bufidx] = idc.ConvertID( memory[x,y].ID );

                    // Border
                    unchecked {
                        borderbuffer[bufidx] = memory[x,y].Border == 0 ? 0 : (int)(0xFFFF0000);
                    }

                    bufidx++;
                }
            }
        }
Exemplo n.º 2
0
        public int[] Shade32( RawImage image )
        {
            int[] buffer = new int[image.PixelCount];
            int bufidx = 0;

            for ( int y=0; y<image.Size.Height; ++y ) {
                for ( int x=0; x<image.Size.Width; ++x ) {
                    buffer[bufidx++] = shades[((rangecheck[(image[x,y].Color-0+128+32)]<<6) |
                                       (int)(provinces[image[x,y].ID].Terrain.Color) )];
                }
            }

            return buffer;
        }
Exemplo n.º 3
0
        public int[] Shade32( RawImage image )
        {
            int[] buffer = new int[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    buffer[bufidx++] = idc.ConvertID( memory[x,y].ID );
                }
            }

            return buffer;
        }
Exemplo n.º 4
0
        public short[] Shade16( RawImage image )
        {
            short[] buffer = new short[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    buffer[bufidx++] = (short)idc.ConvertID( memory[x,y].ID, IDConvertorMode.RGB16 );
                }
            }

            return buffer;
        }
Exemplo n.º 5
0
        public int[] Shade32( RawImage image )
        {
            int[] buffer = new int[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    ushort owner = memory[x,y].IsBorder() && drawborders ? Province.BorderID : memory[x,y].ID;
                    buffer[bufidx++] = shades[((rangecheck[(memory[x,y].Color-0+128+32)]<<6) | (int)(provinces[owner].Terrain.Color) )];
                }
            }

            return buffer;
        }
Exemplo n.º 6
0
        public short[] Shade16( RawImage image )
        {
            short[] buffer = new short[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    ushort owner = memory[x,y].IsBorder() && drawborders ? Province.BorderID : memory[x,y].ID;
                    int color32 = shades[((rangecheck[(memory[x,y].Color-0+128+32)]<<6) | (int)(provinces[owner].Terrain.Color) )];
                    buffer[bufidx++] = (short)((((color32 >> 19) & 31) << 10) | (((color32 >> 11) & 31) << 5) | (((color32 >> 3) & 31)));
                }
            }

            return buffer;
        }
Exemplo n.º 7
0
        public int[] Shade32( RawImage image )
        {
            int[] buffer = new int[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    unchecked {
                        buffer[bufidx++] =  memory[x,y].Border == 0 ? 0 : (int)(0xFFFF0000);
                    }
                }
            }

            return buffer;
        }
Exemplo n.º 8
0
        private short[] Shade16Diff( RawImage image )
        {
            // Diff version
            int bufidx = 0;
            int height = image.Size.Height;
            int width = image.Size.Width;
            ushort[] prebuffer = idmap.ExportBitmapBuffer( image.Location, image.Size );
            short[] buffer = new short[prebuffer.Length];
            Pixel[,] memory = image.Memory;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    buffer[bufidx] = (short)((prebuffer[bufidx]-memory[x,y].ID) != 0 ? (0xFF << 10) : 0);
                    bufidx++;
                }
            }

            return buffer;
        }
Exemplo n.º 9
0
        public int[] Shade32( RawImage image )
        {
            if ( diff ) return Shade32Diff( image );

            // Normal version
            int bufidx = 0;
            int height = image.Size.Height;
            int width = image.Size.Width;
            ushort[] prebuffer = idmap.ExportBitmapBuffer( image.Location, image.Size );
            int[] buffer = new int[prebuffer.Length];

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    buffer[bufidx] = idc.ConvertID( prebuffer[bufidx] );
                    bufidx++;
                }
            }

            return buffer;
        }
Exemplo n.º 10
0
        public void MultiShade32( RawImage image, out int[] colorbuffer, out ushort[] idbuffer, out byte[] borderbuffer )
        {
            colorbuffer = new int[image.PixelCount];
            idbuffer = new ushort[image.PixelCount];
            borderbuffer = new byte[image.PixelCount];

            int height = image.Size.Height;
            int width = image.Size.Width;
            Pixel[,] memory = image.Memory;

            int bufidx = 0;
            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    byte color = (byte)(0xFF-(memory[x,y].Color << 2));
                    colorbuffer[bufidx] = (color << 16) | (color << 8) | color;
                    idbuffer[bufidx] = memory[x,y].ID;
                    borderbuffer[bufidx++] = memory[x,y].Border;
                }
            }
        }
Exemplo n.º 11
0
        public short[] Shade16( RawImage image )
        {
            short[] buffer = new short[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    byte color = (byte)(0x1F-(memory[x,y].Color>>1));
                    if ( memory[x,y].IsBorder() && drawBorders ) {
                        buffer[bufidx++] = (short)(0x1F << 10);
                    }
                    else {
                        buffer[bufidx++] = (short)((color << 10) | (color << 5) | color);
                    }
                }
            }

            return buffer;
        }
Exemplo n.º 12
0
        public int[] Shade32( RawImage image )
        {
            int[] buffer = new int[image.PixelCount];
            int bufidx = 0;
            Pixel[,] memory = image.Memory;
            int height = image.Size.Height;
            int width = image.Size.Width;

            for ( int y=0; y<height; ++y ) {
                for ( int x=0; x<width; ++x ) {
                    byte color = (byte)(0xFF-(memory[x,y].Color << 2));
                    if ( memory[x,y].IsBorder() && drawBorders ) {
                        buffer[bufidx++] = 0xFF0000;
                    }
                    else {
                        buffer[bufidx++] = (color << 16) | (color << 8) | color;
                    }
                }
            }

            return buffer;
        }
Exemplo n.º 13
0
 public ImageDecoder( RawImage target )
 {
     memory = target.Memory;
     ClearBuffer();
 }
Exemplo n.º 14
0
 public ImageEncoder( RawImage source )
 {
     this.source = source;
 }
Exemplo n.º 15
0
        public void EncodeImage( RawImage image )
        {
            // This should be on an integral boundary
            if ( !CoordMap.FitToGrid( image.Bounds ).Equals( image.Bounds ) )
                throw new ArgumentOutOfRangeException( "image.Bounds", "The bounds of the RawImage are not on grid bounds." );

            // We have to enlarge our memory because the encoding needs to have the right/bottom values.
            Pixel[,] oldmem = image.Memory;
            int w = oldmem.GetLength(0);
            int h = oldmem.GetLength(1);
            Pixel[,] newmem  = new Pixel[w+1,h+1];
            // Copy the memory
            for ( int x=0; x<w; ++x ) {
                Array.Copy( oldmem, x*h, newmem, x*(h+1), h );
                newmem[x,h] = newmem[x,h-1];
            }
            Array.Copy( newmem, (w-1)*(h+1), newmem, w*(h+1), h+1 );
            image.Memory = newmem;

            // Get the size of the rectangle in blocks
            Size size = MapToBlockCoordinates( image.Size );
            ImageEncoder encoder = new ImageEncoder( image );
            Point gridloc = image.Location;
            for ( int y=0; y<size.Height; ++y ) {
                for ( int x=0; x<size.Width; ++x ) {
                    this[GetBlockIndex(gridloc)] = encoder.Encode( x << BlockFactor, y << BlockFactor );
                    gridloc.X += BlockSize;
                }
                gridloc.X = image.Location.X;
                gridloc.Y += BlockSize;
            }

            // Reinstate old memory, since the caller might need it again.
            image.Memory = oldmem;
        }
Exemplo n.º 16
0
        public RawImage DecodeImage( Rectangle rect )
        {
            // Calculate the integral rectangle, i.e. on block boundaries
            Rectangle integralrect = CoordMap.FitToGrid( rect );
            // Get the size of the rectangle in blocks
            Size size = CoordMap.ActualToBlocks( integralrect.Size );

            // Create the image
            RawImage image = new RawImage( zoom, integralrect );
            ImageDecoder decoder = new ImageDecoder( image );

            #if false
            // Create a grid of decompressed blocks first
            Point gridloc = integralrect.Location;
            for ( int y=0; y<size.Height; ++y ) {
                for ( int x=0; x<size.Width; ++x ) {
                    MapBlock self = (MapBlock)this[GetBlockIndex( gridloc )];
                    MapBlock right = (MapBlock)this[GetBlockIndex( gridloc.X + BlockSize, gridloc.Y )];
                    MapBlock bottom = (MapBlock)this[GetBlockIndex( gridloc.X, gridloc.Y + BlockSize )];
                    MapBlock bottomright = (MapBlock)this[GetBlockIndex( gridloc.X + BlockSize, gridloc.Y + BlockSize )];

                    decoder.Decode4( x << BlockFactor, y << BlockFactor, self, right, bottom, bottomright );

                    gridloc.X = NormalizeX( gridloc.X + (BlockSize << zoom) );
                }
                gridloc.Y += BlockSize << zoom;
                gridloc.X = integralrect.Location.X;
            }
            #else
            // Create a grid of decompressed blocks first
            Point gridloc = new Point( NormalizeX( integralrect.Right - BlockSize ), integralrect.Bottom - BlockSize);
            for ( int x=size.Width-1; x>=0; --x ) {
                MapBlock self = (MapBlock)this[GetBlockIndex( gridloc )];
                MapBlock right = (MapBlock)this[GetBlockIndex( gridloc.X + BlockSize, gridloc.Y )];
                MapBlock bottom = (MapBlock)this[GetBlockIndex( gridloc.X, gridloc.Y + BlockSize )];
                MapBlock bottomright = (MapBlock)this[GetBlockIndex( gridloc.X + BlockSize, gridloc.Y + BlockSize )];
                gridloc.Y -= BlockSize;

                decoder.Decode4( x << BlockFactor, (size.Height-1) << BlockFactor, self, right, bottom, bottomright );
                for ( int y=size.Height-2; y>=0; --y ) {
                    self = (MapBlock)this[GetBlockIndex( gridloc )];
                    right = (MapBlock)this[GetBlockIndex( gridloc.X + BlockSize, gridloc.Y )];

                    decoder.Decode2( x << BlockFactor, y << BlockFactor, self, right );
                    gridloc.Y -= BlockSize;
                }
                gridloc.X = NormalizeX( gridloc.X - BlockSize );
                gridloc.Y = integralrect.Bottom - BlockSize;
            }
            #endif
            return image;
        }
Exemplo n.º 17
0
        public RawImage DecodeBlockImage( MapBlock block, Point location )
        {
            location = CoordMap.FitToGrid( location );
            RawImage image = new RawImage( zoom, new Rectangle( location, new Size( BlockSize, BlockSize ) ) );

            ImageDecoder decoder = new ImageDecoder( image );
            decoder.Decode1( 0, 0, block );

            return image;
        }
Exemplo n.º 18
0
 public override int[] Shade32( RawImage image )
 {
     return shader.Shade32( image );
 }
Exemplo n.º 19
0
 public override short[] Shade16( RawImage image )
 {
     return shader.Shade16( image );
 }
Exemplo n.º 20
0
 public abstract int[] Shade32( RawImage image );
Exemplo n.º 21
0
        public RawImage Shrink()
        {
            Rectangle smallbounds = bounds;
            smallbounds.X /= 2;
            smallbounds.Y /= 2;
            smallbounds.Width /= 2;
            smallbounds.Height /= 2;

            RawImage result = new RawImage( this.zoom+1, smallbounds );

            int[] colorbuffer;
            ushort[] idbuffer;
            byte[] borderbuffer;
            new GrayScaledShader().MultiShade32( this, out colorbuffer, out idbuffer, out borderbuffer );

            Bitmap orig, small;

            orig = Visualiser.CreateImage32( colorbuffer, bounds.Size );
            small = ResizeBitmap( orig, InterpolationMode.HighQualityBicubic );
            colorbuffer = Visualiser.CreateBuffer32( small );
            orig.Dispose(); small.Dispose();

            short[] idbuffercopy = new short[idbuffer.Length];
            for ( int i=0; i<idbuffer.Length; ++i ) idbuffercopy[i] = (short)idbuffer[i];
            orig = Visualiser.CreateImage16( idbuffercopy, bounds.Size );
            small = ResizeBitmap( orig, InterpolationMode.NearestNeighbor );
            idbuffercopy = Visualiser.CreateBuffer16( small );
            idbuffer = new ushort[idbuffercopy.Length];
            for ( int i=0; i<idbuffer.Length; ++i ) idbuffer[i] = (ushort)idbuffercopy[i];
            orig.Dispose(); small.Dispose();

            orig = Visualiser.CreateImage8( borderbuffer, bounds.Size );
            small = ResizeBitmap( orig, InterpolationMode.NearestNeighbor );
            borderbuffer = Visualiser.CreateBuffer8( small );
            orig.Dispose(); small.Dispose();

            return new GrayScaledShader().Unshade32( result.zoom+1, smallbounds, colorbuffer, idbuffer, borderbuffer );
        }
Exemplo n.º 22
0
            public int[] Shade32( RawImage image )
            {
                int[] buffer = new int[image.PixelCount];
                int bufidx = 0;
                Pixel[,] memory = image.Memory;
                int height = image.Size.Height;
                int width = image.Size.Width;

                for ( int y=0; y<height; ++y ) {
                    for ( int x=0; x<width; ++x ) {
                        int id = memory[x,y].ID;
                        buffer[bufidx++] = id == Province.TerraIncognitaID ? Province.MaxValue : id;
                    }
                }

                return buffer;
            }
Exemplo n.º 23
0
 public abstract short[] Shade16( RawImage image );