public void Read(BinaryReader reader)
        {
            TestName = reader.ReadString();
            CurrentVersion = reader.ReadString();
            Frame = reader.ReadString();

            // Read image header
            var width = reader.ReadInt32();
            var height = reader.ReadInt32();
            var format = (PixelFormat)reader.ReadInt32();
            var textureSize = reader.ReadInt32();

            // Read image data
            var imageData = new byte[textureSize];
            using (var lz4Stream = new LZ4Stream(reader.BaseStream, CompressionMode.Decompress, false, textureSize))
            {
                if (lz4Stream.Read(imageData, 0, textureSize) != textureSize)
                    throw new EndOfStreamException("Unexpected end of stream");
            }

            var pinnedImageData = GCHandle.Alloc(imageData, GCHandleType.Pinned);
            var description = new ImageDescription
            {
                Dimension = TextureDimension.Texture2D,
                Width = width,
                Height = height,
                ArraySize = 1,
                Depth = 1,
                Format = format,
                MipLevels = 1,
            };

            Image = Image.New(description, pinnedImageData.AddrOfPinnedObject(), 0, pinnedImageData, false);
        }
Esempio n. 2
0
 /// <summary>
 /// Create an atlas texture element that contains all the information from the source texture.
 /// </summary>
 /// <param name="name">The reference name of the element</param>
 /// <param name="texture"></param>
 /// <param name="sourceRegion">The region of the element in the source texture</param>
 /// <param name="borderSize">The size of the border around the element in the output atlas</param>
 /// <param name="borderModeU">The border mode along the U axis</param>
 /// <param name="borderModeV">The border mode along the V axis</param>
 /// <param name="borderColor">The color of the border</param>
 public AtlasTextureElement(string name, Image texture, RotableRectangle sourceRegion, int borderSize, TextureAddressMode borderModeU, TextureAddressMode borderModeV, Color? borderColor = null)
 {
     Name = name;
     Texture = texture;
     SourceRegion = sourceRegion;
     BorderSize = borderSize;
     BorderModeU = borderModeU;
     BorderModeV = borderModeV;
     BorderColor = borderColor ?? Color.Transparent;
 }
Esempio n. 3
0
        // Note: this comparison function is not very robust and might have to be improved at some point (does not take in account RowPitch, etc...)
        private bool CompareImages(Image outputImage, Image referenceImage)
        {
            if (outputImage.Description != referenceImage.Description)
                return false;
            
            unsafe
            {
                var ptr1 = (Color*)outputImage.DataPointer;
                var ptr2 = (Color*)referenceImage.DataPointer;

                // Fill in mock data
                for (var i = 0; i < outputImage.Description.Height * outputImage.Description.Width; ++i)
                {
                    if (*ptr1 != *ptr2)
                        return false;

                    ++ptr1;
                    ++ptr2;
                }
            }

            return true;
        }
Esempio n. 4
0
        private void SaveAndCompareTexture(Image outputImage, string fileName, ImageFileType extension = ImageFileType.Png)
        {
            // save
            Directory.CreateDirectory(ImageOutputPath);
            outputImage.Save(new FileStream(ImageOutputPath + fileName + extension.ToFileExtension(), FileMode.Create), extension); 

            // Compare
            using(var texTool = new TextureTool())
            {
                var referenceImage = LoadImage(texTool, new UFile(GoldImagePath + "/" + fileName + extension.ToFileExtension()));
                Assert.IsTrue(CompareImages(outputImage, referenceImage), "The texture outputted differs from the gold image.");
            }
        }