示例#1
0
        internal static void WriteTexture(object spriteFontContent, bool alphaOnly, ContentProcessorContext context, string filename)
        {
            dynamic sfc = ExposedObject.From(spriteFontContent);

            // Get a copy of the texture in Color format
            Texture2DContent           originalTexture = sfc.Texture;
            BitmapContent              originalBitmap  = originalTexture.Mipmaps[0];
            PixelBitmapContent <Color> colorBitmap     = new PixelBitmapContent <Color>(
                originalBitmap.Width, originalBitmap.Height);

            BitmapContent.Copy(originalBitmap, colorBitmap);


            Bitmap bitmap = new Bitmap(colorBitmap.Width, colorBitmap.Height, PixelFormat.Format32bppArgb);

            for (int x = 0; x < colorBitmap.Width; x++)
            {
                for (int y = 0; y < colorBitmap.Height; y++)
                {
                    Color c = colorBitmap.GetPixel(x, y);
                    if (alphaOnly)
                    {
                        c.R = 255; c.G = 255; c.B = 255;                 // Undo premultiplication
                    }
                    bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B));
                }
            }
            bitmap.Save(filename, ImageFormat.Png);
            bitmap.Dispose();

            context.AddOutputFile(filename);
        }
        /// <summary>
        /// Converts an array of sprite filenames into a sprite sheet object.
        /// </summary>
        public override SpriteSheetContent Process(string[] input,
                                                   ContentProcessorContext context)
        {
            SpriteSheetContent   spriteSheet   = new SpriteSheetContent();
            List <BitmapContent> sourceSprites = new List <BitmapContent>();

            // Loop over each input sprite filename.
            foreach (string inputFilename in input)
            {
                // Store the name of this sprite.
                string spriteName = Path.GetFileNameWithoutExtension(inputFilename);

                spriteSheet.SpriteNames.Add(spriteName, sourceSprites.Count);

                // Load the sprite texture into memory.
                ExternalReference <TextureContent> textureReference =
                    new ExternalReference <TextureContent>(inputFilename);

                TextureContent texture =
                    context.BuildAndLoadAsset <TextureContent,
                                               TextureContent>(textureReference, "TextureProcessor");

                sourceSprites.Add(texture.Faces[0][0]);
            }

            // Pack all the sprites into a single large texture.
            BitmapContent packedSprites = SpritePacker.PackSprites(sourceSprites,
                                                                   spriteSheet.SpriteRectangles, context);

            spriteSheet.Texture.Mipmaps.Add(packedSprites);

            return(spriteSheet);
        }
示例#3
0
        public override void Write(ContentWriter output, T value)
        {
            BitmapContent content = value.Faces[0][0];

            this.WriteTextureHeader(output, content.Format, content.Width, content.Height, value.Faces.Count, value.Faces[0].Count);
            this.WriteTextureData(output, value);
        }
        public override List <Vertices> Process(TextureContent input, ContentProcessorContext context)
        {
            BitmapContent bitmap = input.Faces[0][0];

            byte[] bytes = bitmap.GetPixelData();
            Debug.Assert(bytes.Length % 4 == 0);

            // Note(manu): If this were C/C++, we could simply reinterpret the byte-array as a uint-array...
            uint[] data = new uint[bytes.Length / 4];
            for (int dataIndex = 0; dataIndex < data.Length; dataIndex++)
            {
                int byteIndex = dataIndex * 4;
                data[dataIndex] = BitConverter.ToUInt32(bytes, byteIndex);
            }

            DateTime         vertStart        = DateTime.Now;
            TextureConverter textureConverter = new TextureConverter(data, bitmap.Width)
            {
                PolygonDetectionType    = PolygonDetectionType,
                HoleDetection           = HoleDetection,
                MultipartDetection      = MultipartDetection,
                PixelOffsetOptimization = PixelOffsetOptimization,
                Transform      = Matrix.CreateScale(UniformScale * Conversion.RenderScale), // TODO(manu): Use z=1 instead?
                AlphaTolerance = (byte)AlphaTolerance,
                HullTolerance  = HullTolerance,
            };
            List <Vertices> vertices     = textureConverter.DetectVertices();
            TimeSpan        vertDuration = DateTime.Now - vertStart;

            Diagnostic(context.Logger, $"Parsing vertices took {vertDuration.TotalSeconds.ToString("0.000")} seconds (VelcroPhysics).");

            return(vertices);
        }
        /// <summary>
        /// Construye el mapa de alturas a partir de la textura especificada
        /// </summary>
        /// <param name="terrain">Textura con el mapa de alturas del terreno</param>
        /// <param name="cellScale">Escala de alturas</param>
        /// <param name="context">Contexto</param>
        /// <returns>Devuelve el mapa de alturas generado</returns>
        private HeightMap BuildHeightMap(Texture2DContent terrain, float cellScale, ContentProcessorContext context)
        {
            if (terrain.Mipmaps.Count > 0)
            {
                BitmapContent heightMapContent = terrain.Mipmaps[0];

                // Sólo se soportan texturas cuadradas
                if (heightMapContent.Width == heightMapContent.Height)
                {
                    byte[] pixelData = heightMapContent.GetPixelData();

                    // Construir el mapa de alturas
                    return(HeightMap.FromData(
                               pixelData,
                               heightMapContent.Height,
                               heightMapContent.Width,
                               cellScale));
                }
                else
                {
                    //Sólo se soportan texturas cuadradas
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new PipelineException("El archivo de mapa de alturas no tiene el formato correcto. No se encuentra la imagen");
            }
        }
示例#6
0
        public static SpriteFont Compile(GraphicsDevice g, string file, out IDisposable gR)
        {
            FontDescriptionImporter  ei = new FontDescriptionImporter();
            FontDescription          ec = ei.Import(file, new XNADynImporterContext());
            FontDescriptionProcessor ep = new FontDescriptionProcessor();
            var cec = ep.Process(ec, new XNADynProcessorContext());

            // Get Private Texture
            Texture2DContent texC   = sfcTexture.GetValue(cec) as Texture2DContent;
            MipmapChain      o      = txcMipmaps.GetValue(texC, null) as MipmapChain;
            BitmapContent    texBMP = o[0];
            SurfaceFormat    sf;

            if (!texBMP.TryGetFormat(out sf))
            {
                throw new InvalidContentException("Could Not Obtain The Surface Format Of The SpriteFont");
            }
            Texture2D texture = new Texture2D(g, texBMP.Width, texBMP.Height, false, sf);

            texture.SetData(texBMP.GetPixelData());

            // Get Private Glyph Data
            List <Rectangle> glyphs    = sfcGlyphs.GetValue(cec) as List <Rectangle>;
            List <Rectangle> cropping  = sfcCropping.GetValue(cec) as List <Rectangle>;
            List <char>      charMap   = sfcCharMap.GetValue(cec) as List <char>;
            int            lineSpacing = (int)sfcLineSpacing.GetValue(cec);
            float          spacing     = (float)sfcSpacing.GetValue(cec);
            List <Vector3> kerning     = sfcKerning.GetValue(cec) as List <Vector3>;
            char?          defaultChar = sfcDefaultChar.GetValue(cec) as char?;

            // Invoke Private SpriteFont Constructor
            gR = texture;
            return(sfConstructor.Invoke(new object[] { texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultChar }) as SpriteFont);
        }
示例#7
0
        unsafe private static BitmapContent ConvertToColor(BitmapContent input)
        {
            var width  = input.Width;
            var height = input.Height;

            SurfaceFormat format;

            input.TryGetFormat(out format);
            var formatSize = DDSImporter.GetBitmapSize(format, width, height);
            var blocks     = formatSize;
            var inData     = input.GetPixelData();

            var output = new PixelBitmapContent <Color>(width, height);

            fixed(byte *p = &inData[0])
            {
                DXT1Block *block = (DXT1Block *)p;

                //convert DXT1 to color
                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        int blockIdx   = (x / 4) + (y / 4) * (width / 4);
                        int colorIndex = x % 4 + (y % 4) * 4;

                        Color color = block[blockIdx].GetColor(colorIndex);
                        output.SetPixel(x, y, color);
                    }
                }
            }

            return(output);
        }
    private static TextureContent Compress(Type bitmapContentType, Texture texture, ContentIdentity identity)
    {
      // Let MonoGame's BitmapContent handle the compression.
      var description = texture.Description;
      switch (description.Dimension)
      {
        case TextureDimension.Texture1D:
        case TextureDimension.Texture2D:
          {
            var textureContent = new Texture2DContent { Identity = identity };
            for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
            {
              var image = texture.Images[texture.GetImageIndex(mipIndex, 0, 0)];
              var sourceBitmap = TextureHelper.ToContent(image);
              var targetBitmap = (BitmapContent)Activator.CreateInstance(bitmapContentType, image.Width, image.Height);
              BitmapContent.Copy(sourceBitmap, targetBitmap);
              textureContent.Mipmaps.Add(targetBitmap);
            }

            return textureContent;
          }
        case TextureDimension.TextureCube:
          {
            var textureContent = new TextureCubeContent { Identity = identity };
            for (int faceIndex = 0; faceIndex < 6; faceIndex++)
            {
              for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
              {
                var image = texture.Images[texture.GetImageIndex(mipIndex, faceIndex, 0)];
                var sourceBitmap = TextureHelper.ToContent(image);
                var targetBitmap = (BitmapContent)Activator.CreateInstance(bitmapContentType, image.Width, image.Height);
                BitmapContent.Copy(sourceBitmap, targetBitmap);
                textureContent.Faces[faceIndex].Add(targetBitmap);
              }
            }

            return textureContent;
          }
        case TextureDimension.Texture3D:
          {
            var textureContent = new Texture3DContent { Identity = identity };
            for (int zIndex = 0; zIndex < description.Depth; zIndex++)
            {
              textureContent.Faces.Add(new MipmapChain());
              for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
              {
                var image = texture.Images[texture.GetImageIndex(mipIndex, 0, zIndex)];
                var sourceBitmap = TextureHelper.ToContent(image);
                var targetBitmap = (BitmapContent)Activator.CreateInstance(bitmapContentType, image.Width, image.Height);
                BitmapContent.Copy(sourceBitmap, targetBitmap);
                textureContent.Faces[zIndex].Add(targetBitmap);
              }
            }

            return textureContent;
          }
      }

      throw new InvalidOperationException("Invalid texture dimension.");
    }
示例#9
0
        protected string BuildTexture(BitmapContent bitmap, IDictionary <string, object> processorParameters = null)
        {
            TextureContent texture = new Texture2DContent();

            texture.Faces[0] = new MipmapChain(bitmap);
            return(BuildObject(texture, "TextureProcessor", processorParameters));
        }
示例#10
0
        public HelpScene() : base()
        {
            int    size       = (int)(90 * GameView.scaleFactor);
            Bitmap backBitmap = BitmapLoader.LoadAndResize(Resource.Drawable.back,
                                                           size, size);
            BitmapContent backContent = new BitmapContent(backBitmap, null);
            int           hb          = (int)(80 * GameView.scaleFactor);

            backButton = new Button(backContent, new Rect(-hb, -hb, hb, hb),
                                    pivot, -265 * GameView.scaleFactor, -380 * GameView.scaleFactor);
            backButton.Pressed += () =>
            {
                MenuScene.Instance.Show(Side.Left);
                Hide(Side.Right);
            };

            titleText = new TextContent("GAME RULES", ColorBank.Red,
                                        64 * GameView.scaleFactor, pivot, 0, -160 * GameView.scaleFactor);
            int yStart = -70, yDelta = 60;

            rulesText = new TextContent[4];
            for (int i = 0; i < 4; ++i)
            {
                float y = (yStart + yDelta * i) * GameView.scaleFactor;
                rulesText[i] = new TextContent(rules[i], ColorBank.Red,
                                               36 * GameView.scaleFactor, pivot, 0, y);
            }
        }
        static void BitmapAssert(BitmapContent bitmap, Color color, int range)
        {
            byte[] rgba;
            if (bitmap is Dxt1BitmapContent)
            {
                rgba = DxtUtil.DecompressDxt1(bitmap.GetPixelData(), bitmap.Width, bitmap.Height);
            }
            else if (bitmap is Dxt3BitmapContent)
            {
                rgba = DxtUtil.DecompressDxt3(bitmap.GetPixelData(), bitmap.Width, bitmap.Height);
            }
            else if (bitmap is Dxt5BitmapContent)
            {
                rgba = DxtUtil.DecompressDxt5(bitmap.GetPixelData(), bitmap.Width, bitmap.Height);
            }
            else
            {
                rgba = bitmap.GetPixelData();
            }

            for (var p = 0; p < rgba.Length; p += 4)
            {
                Assert.That(rgba[p + 0], Is.EqualTo(color.R).Within(range));
                Assert.That(rgba[p + 1], Is.EqualTo(color.G).Within(range));
                Assert.That(rgba[p + 2], Is.EqualTo(color.B).Within(range));
                Assert.That(rgba[p + 3], Is.EqualTo(color.A).Within(range));
            }
        }
示例#12
0
 internal FontContent(BitmapContent texture, int height, Dictionary <char, Glyph> glyphs, SortedDictionary <uint, int> kerningPairs)
 {
     this.texture         = new Texture2DContent();
     this.texture.Mipmaps = texture;
     this.height          = height;
     this.glyphs          = glyphs;
     this.kerningPairs    = kerningPairs;
 }
示例#13
0
        public void BitmapCompressFullResize()
        {
            var b1 = new PixelBitmapContent <Color>(16, 16);

            Fill(b1, Color.Red);
            var b2 = new Dxt1BitmapContent(8, 8);

            BitmapContent.Copy(b1, b2);
        }
示例#14
0
        /// <summary>
        /// Once the arranging is complete, copies the bitmap data for each
        /// sprite to its chosen position in the single larger output bitmap.
        /// </summary>
        static BitmapContent CopySpritesToOutput(List <ArrangedSprite> sprites,
                                                 IList <BitmapContent> sourceSprites,
                                                 ICollection <Rectangle> outputSprites,
                                                 int width, int height)
        {
            BitmapContent output = new PixelBitmapContent <Color>(width, height);

            foreach (ArrangedSprite sprite in sprites)
            {
                BitmapContent source = sourceSprites[sprite.Index];

                int x = sprite.X;
                int y = sprite.Y;

                int w = source.Width;
                int h = source.Height;

                // Copy the main sprite data to the output sheet.
                BitmapContent.Copy(source, new Rectangle(0, 0, w, h),
                                   output, new Rectangle(x + 1, y + 1, w, h));

                // Copy a border strip from each edge of the sprite, creating
                // a one pixel padding area to avoid filtering problems if the
                // sprite is scaled or rotated.
                BitmapContent.Copy(source, new Rectangle(0, 0, 1, h),
                                   output, new Rectangle(x, y + 1, 1, h));

                BitmapContent.Copy(source, new Rectangle(w - 1, 0, 1, h),
                                   output, new Rectangle(x + w + 1, y + 1, 1, h));

                BitmapContent.Copy(source, new Rectangle(0, 0, w, 1),
                                   output, new Rectangle(x + 1, y, w, 1));

                BitmapContent.Copy(source, new Rectangle(0, h - 1, w, 1),
                                   output, new Rectangle(x + 1, y + h + 1, w, 1));

                // Copy a single pixel from each corner of the sprite,
                // filling in the corners of the one pixel padding area.
                BitmapContent.Copy(source, new Rectangle(0, 0, 1, 1),
                                   output, new Rectangle(x, y, 1, 1));

                BitmapContent.Copy(source, new Rectangle(w - 1, 0, 1, 1),
                                   output, new Rectangle(x + w + 1, y, 1, 1));

                BitmapContent.Copy(source, new Rectangle(0, h - 1, 1, 1),
                                   output, new Rectangle(x, y + h + 1, 1, 1));

                BitmapContent.Copy(source, new Rectangle(w - 1, h - 1, 1, 1),
                                   output, new Rectangle(x + w + 1, y + h + 1, 1, 1));

                // Remember where we placed this sprite.
                outputSprites.Add(new Rectangle(x + 1, y + 1, w, h));
            }

            return(output);
        }
        void BitmapCompressFullResize <T>(T color1)
            where T : struct, IEquatable <T>
        {
            var b1 = new PixelBitmapContent <T>(16, 16);

            Fill(b1, color1);
            var b2 = new Dxt1BitmapContent(8, 8);

            BitmapContent.Copy(b1, b2);
        }
示例#16
0
        Button CreateHexagonButton(int size, int id, float x, float y)
        {
            int           hsize   = (int)(0.85 * size);
            int           vsize   = (int)(0.9 * size);
            Rect          bounds  = new Rect(-hsize / 2, -vsize / 2, hsize / 2, vsize / 2);
            Bitmap        bitmap  = BitmapLoader.LoadAndResize(id, size, size);
            BitmapContent content = new BitmapContent(bitmap, null);

            return(new Button(content, bounds, pivot, x, y));
        }
示例#17
0
        public override ImageSpriteStub Process(Texture2DContent input, ContentProcessorContext context)
        {
            string        textureName = Path.GetFileNameWithoutExtension(context.OutputFilename) + "Texture";
            BitmapContent texture     = input.Mipmaps[0];

            ExternalReference <Texture2DContent> texRef = context.WriteAsset(input, textureName);
            Rectangle texRect = new Rectangle(0, 0, texture.Width, texture.Height);

            return(new ImageSpriteStub(texRef, texRect));
        }
        static BitmapContent BitmapConvert(Type bitmapType, Color color, int w, int h)
        {
            var b1 = new PixelBitmapContent <Color>(w, h);

            Fill(b1, color);
            var b2 = (BitmapContent)Activator.CreateInstance(bitmapType, b1.Width, b1.Height);

            BitmapContent.Copy(b1, b2);
            return(b2);
        }
        private List <Glyph> ExtractGlyphs(PixelBitmapContent <Color> bitmap)
        {
            var glyphs  = new List <Glyph>();
            var regions = new List <Rectangle>();

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    if (bitmap.GetPixel(x, y) != transparentPixel)
                    {
                        // if we don't have a region that has this pixel already
                        var re = regions.Find(r => {
                            return(r.Contains(x, y));
                        });
                        if (re == Rectangle.Empty)
                        {
                            // we have found the top, left of a image.
                            // we now need to scan for the 'bounds'
                            int top    = y;
                            int bottom = y;
                            int left   = x;
                            int right  = x;
                            while (bitmap.GetPixel(right, bottom) != transparentPixel)
                            {
                                right++;
                            }
                            while (bitmap.GetPixel(left, bottom) != transparentPixel)
                            {
                                bottom++;
                            }
                            // we got a glyph :)
                            regions.Add(new Rectangle(left, top, right - left, bottom - top));
                            x = right;
                        }
                        else
                        {
                            x += re.Width;
                        }
                    }
                }
            }

            for (int i = 0; i < regions.Count; i++)
            {
                var rect      = regions[i];
                var newBitmap = new PixelBitmapContent <Color>(rect.Width, rect.Height);
                BitmapContent.Copy(bitmap, rect, newBitmap, new Rectangle(0, 0, rect.Width, rect.Height));
                var glyph = new Glyph(GetCharacterForIndex(i), newBitmap);
                glyph.CharacterWidths.B = glyph.Bitmap.Width;
                glyphs.Add(glyph);
                //newbitmap.Save (GetCharacterForIndex(i)+".png", System.Drawing.Imaging.ImageFormat.Png);
            }
            return(glyphs);
        }
示例#20
0
 private void ConvertToColor(TextureContent textureContent)
 {
     foreach (var face in textureContent.Faces)
     {
         for (int m = 0; m < face.Count; m++)
         {
             BitmapContent input  = face[m];
             BitmapContent output = ConvertToColor(input);
             face[m] = output;
         }
     }
     return;
 }
示例#21
0
        public static void CompressPngToTexture2DContent(
            ParsedPath pngFileName,
            string compressionType,
            out Texture2DContent textureContent)
        {
            PngFile pngFile = PngFileReader.ReadFile(pngFileName);

            SquishMethod? squishMethod  = null;
            SurfaceFormat surfaceFormat = SurfaceFormat.Color;

            switch (compressionType.ToLower())
            {
            case "dxt1":
                squishMethod  = SquishMethod.Dxt1;
                surfaceFormat = SurfaceFormat.Dxt1;
                break;

            case "dxt3":
                squishMethod  = SquishMethod.Dxt3;
                surfaceFormat = SurfaceFormat.Dxt3;
                break;

            case "dxt5":
                squishMethod  = SquishMethod.Dxt5;
                surfaceFormat = SurfaceFormat.Dxt5;
                break;

            default:
            case "none":
                surfaceFormat = SurfaceFormat.Color;
                break;
            }

            BitmapContent bitmapContent;

            if (surfaceFormat != SurfaceFormat.Color)
            {
                byte[] rgbaData = Squish.CompressImage(
                    pngFile.RgbaData, pngFile.Width, pngFile.Height,
                    squishMethod.Value, SquishFit.IterativeCluster, SquishMetric.Default, SquishExtra.None);

                bitmapContent = new BitmapContent(surfaceFormat, pngFile.Width, pngFile.Height, rgbaData);
            }
            else
            {
                bitmapContent = new BitmapContent(SurfaceFormat.Color, pngFile.Width, pngFile.Height, pngFile.RgbaData);
            }

            textureContent = new Texture2DContent(bitmapContent);
        }
示例#22
0
        private MipmapChain CreateFace(BitmapContent bitmapContent, int w, int h, int xOffset)
        {
            PixelBitmapContent <Color> result;

            result = new PixelBitmapContent <Color>(w, h);

            Rectangle sourceRegion = new Rectangle(xOffset, 0, w, h);

            Rectangle destinationRegion = new Rectangle(0, 0, w, h);

            BitmapContent.Copy(bitmapContent, sourceRegion, result, destinationRegion);

            return(result);
        }
示例#23
0
        Button CreateItem(int bitmap_id, string text, Rect bounds,
                          float x, float y)
        {
            ComplexContent cc       = new ComplexContent(null);
            int            size     = (int)(110 * GameView.scaleFactor);
            Bitmap         bitmap   = BitmapLoader.LoadAndResize(bitmap_id, size, size);
            BitmapContent  bContent = new BitmapContent(bitmap, cc.pivot);
            TextContent    tContent = new TextContent(text, ColorBank.Red,
                                                      50 * GameView.scaleFactor, cc.pivot, 0, 120 * GameView.scaleFactor);

            cc.contents.Add(bContent);
            cc.contents.Add(tContent);
            return(new Button(cc, bounds, pivot, x, y));
        }
示例#24
0
        private static void RenderAtlas(TextureAtlasContent output)
        {
            var outputBmp = new PixelBitmapContent <Color>(output.Width, output.Height);

            foreach (var sprite in output.DestinationSprites)
            {
                var srcBmp  = sprite.Texture.Faces[0][0];
                var srcRect = new Rectangle(0, 0, srcBmp.Width, srcBmp.Height);
                BitmapContent.Copy(srcBmp, srcRect, outputBmp, sprite.Bounds);
            }
            var mipmapChain = new MipmapChain(outputBmp);

            output.Texture.Mipmaps = mipmapChain;
        }
示例#25
0
        private static BitmapContent ConvertBitmap(BitmapContent source, Type newType, int width, int height)
        {
            BitmapContent content;

            try
            {
                content = (BitmapContent)Activator.CreateInstance(newType, new object[] { width, height });
            }
            catch (TargetInvocationException exception)
            {
                throw new Exception(exception.InnerException.Message);
            }
            BitmapContent.Copy(source, content);
            return(content);
        }
示例#26
0
 public static void ResizeToPowerOfTwo(TextureContent texture)
 {
     foreach (MipmapChain chain in texture.Faces)
     {
         for (int i = 0; i < chain.Count; i++)
         {
             BitmapContent source = chain[i];
             int           width  = RoundUpToPowerOfTwo(source.Width);
             int           height = RoundUpToPowerOfTwo(source.Height);
             if ((width != source.Width) || (height != source.Height))
             {
                 chain[i] = ConvertBitmap(source, source.GetType(), width, height);
             }
         }
     }
 }
示例#27
0
        private SpriteFontContent CreateSpriteFontContent(
            string fontName,
            double fontSize,
            FontSlant fontSlant,
            FontWeight fontWeight,
            int spacing,
            char?defaultChar,
            List <char> fontChars,
            ParsedPath pngFile)
        {
            double bitmapWidth       = 0;
            double bitmapHeight      = 0;
            List <CharacterData> cds = CreateCharacterData(
                fontName, fontSlant, fontWeight, fontSize, fontChars, out bitmapWidth, out bitmapHeight);

            BitmapContent bitmapContent = CreateBitmapContent(
                bitmapWidth, bitmapHeight, fontName, fontSlant, fontWeight, fontSize, cds, pngFile);

            List <Microsoft.Xna.Framework.Rectangle> locations = new List <Microsoft.Xna.Framework.Rectangle>();
            List <Microsoft.Xna.Framework.Rectangle> croppings = new List <Microsoft.Xna.Framework.Rectangle>();
            List <Vector3> kernings = new List <Vector3>();

            foreach (var cd in cds)
            {
                locations.Add(new Microsoft.Xna.Framework.Rectangle(
                                  (int)cd.Location.X, (int)cd.Location.Y, (int)cd.Location.Width, (int)cd.Location.Height));
                croppings.Add(new Microsoft.Xna.Framework.Rectangle(
                                  (int)cd.Cropping.X, (int)cd.Cropping.Y, (int)cd.Location.Width, (int)cd.Location.Height));
                kernings.Add(new Vector3(
                                 (float)Math.Round(cd.Kerning.X, MidpointRounding.AwayFromZero),
                                 (float)Math.Round(cd.Kerning.Y, MidpointRounding.AwayFromZero),
                                 (float)Math.Round(cd.Kerning.Z, MidpointRounding.AwayFromZero)));
            }

            int   verticalSpacing   = 0;
            float horizontalSpacing = spacing;

            return(new SpriteFontContent(
                       new Texture2DContent(bitmapContent),
                       locations,
                       fontChars,
                       croppings,
                       verticalSpacing,
                       horizontalSpacing,
                       kernings,
                       defaultChar));
        }
示例#28
0
        public override TextureCubeContent Process(TextureCubeContent input, ContentProcessorContext context)
        {
//          System.Diagnostics.Debugger.Launch();
            TextureCubeContent tc = new TextureCubeContent();

            tc.Name     = input.Name;
            tc.Identity = input.Identity;
            int i = 0;

            foreach (var item in input.Faces)
            {
                PixelBitmapContent <Color> bmpInput = (PixelBitmapContent <Color>)item[0];
                BitmapContent BitmapContent         = BlurCubemapFace(bmpInput, bmpInput.Height, bmpInput.Width);
                tc.Faces[i++] = BitmapContent;
            }
            return(tc);
        }
示例#29
0
        public void BitmapCopyFullResize()
        {
            var b1 = new PixelBitmapContent <Color>(8, 8);

            Fill(b1, Color.Red);
            var b2 = new PixelBitmapContent <Color>(4, 4);

            BitmapContent.Copy(b1, b2);

            for (var y = 0; y < b2.Height; y++)
            {
                for (var x = 0; x < b2.Width; x++)
                {
                    Assert.AreEqual(Color.Red, b2.GetPixel(x, y));
                }
            }
        }
示例#30
0
            private void CommitLevel()
            {
                if (faceIndex >= 0)
                {
                    BitmapContent newBitmap = CreateBitmapContent(dataWidth, dataHeight);

                    newBitmap.SetPixelData(tempBitmapData);

                    outputTextureContent.Faces[faceIndex].Add(newBitmap);

                    dataSize  = -1;
                    dataWidth = dataHeight = -1;
                    faceIndex = -1;
                    mipIndex  = -1;
                    dataIndex = 0;
                }
            }