Пример #1
0
 /// <summary>
 /// Loads a png from the specified stream, optionally with color0=transparent
 /// </summary>
 Image LoadPNG(GraphicsDevice device, Stream stream, bool color0)
 {
     pr2.sharppng.Png png = new pr2.sharppng.Png();
     PngImageOutput imageOutput = new PngImageOutput(device, color0);
     png.read(stream, imageOutput);
     return new Image(GameEngine.Game.Device, imageOutput.tex);
 }
Пример #2
0
        LargeImage LoadLargePNG(GraphicsDevice device, Stream stream, bool color0)
        {
            pr2.sharppng.Png png = new pr2.sharppng.Png();
            LargePngImageOutput imageOutput = new LargePngImageOutput(color0);
            png.read(stream, imageOutput);
            LargeImage ret = new LargeImage();
            ret.Width = imageOutput.width;
            ret.Height = imageOutput.height;
            ret.BlocksWidth = ret.Width / 2048;
            if (ret.Width > ret.BlocksWidth * 2048) ret.BlocksWidth++;
            ret.BlocksHeight = ret.Height / 2048;
            if (ret.Height > ret.BlocksHeight * 2048) ret.BlocksHeight++;
            ret.Images = new Image[ret.BlocksWidth, ret.BlocksHeight];
            for(int y=0;y<ret.BlocksHeight;y++)
                for (int x = 0; x < ret.BlocksWidth; x++)
                {
                    int px = x * 2048;
                    int py = y * 2048;
                    int xtodo = ret.Width - px;
                    if (xtodo > 2048) xtodo = 2048;
                    int ytodo = ret.Height - py;
                    if (ytodo > 2048) ytodo = 2048;
                    int[] intbuf = new int[xtodo*ytodo];
                    for(int qy=0,ctr=0;qy<ytodo;qy++)
                        for (int qx = 0; qx < xtodo; qx++,ctr++)
                        {
                            intbuf[ctr] = imageOutput.intbuf[(py + qy) * ret.Width + px + qx];
                        }

                    var tex = new Texture2D(device, xtodo, ytodo, false, SurfaceFormat.Color);
                    tex.SetData(intbuf);
                    ret.Images[x, y] = new Image(GameEngine.Game.Device, tex);
                }

            //return new Image(GameEngine.Game.Device, imageOutput.tex);
            return ret;
        }