Exemplo n.º 1
0
    IReadOnlyTexture <byte> Write(IReadOnlyTexture <byte> existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
    {
        if (existing == null)
        {
            throw new ArgumentNullException(nameof(existing));
        }
        int width  = info.Width;
        int height = info.Height;

        if (width == 0 || height == 0)
        {
            throw new ArgumentException("Explicit width and height must be defined when using FontSpriteLoader", nameof(info));
        }

        var repacked = new SimpleTexture <byte>(existing.Id, existing.Name, width, height * existing.Regions.Count);

        for (int i = 0; i < existing.Regions.Count; i++)
        {
            var oldFrame = existing.GetRegionBuffer(i);
            repacked.AddRegion(0, i * height, width, height);
            BlitUtil.BlitDirect(oldFrame, repacked.GetMutableRegionBuffer(i));
        }

        var font = _loader.Serdes(repacked, info, mapping, s, jsonUtil);

        return(font == null ? null : existing);
    }
Exemplo n.º 2
0
        static IReadOnlyTexture <byte> Read(AssetInfo info, ISerializer s)
        {
            ushort width     = s.UInt16("Width", 0);
            ushort height    = s.UInt16("Height", 0);
            int    something = s.UInt8(null, 0);

            ApiUtil.Assert(something == 0);
            byte frameCount = s.UInt8("Frames", 1);

            var result = new SimpleTexture <byte>(info.AssetId, width, height * frameCount);

            for (int i = 0; i < frameCount; i++)
            {
                byte[] frameBytes = s.Bytes("Frame" + i, null, width * height);
                result.AddRegion(0, i * height, width, height);
                BlitUtil.BlitDirect(
                    new ReadOnlyImageBuffer <byte>(width, height, width, frameBytes),
                    result.GetMutableRegionBuffer(i));
            }

            s.Check();
            return(result);
        }
Exemplo n.º 3
0
    public static IReadOnlyTexture <T> CombineFramesVertically <T>(IAssetId id, IList <IReadOnlyTexture <T> > frames) where T : unmanaged
    {
        if (frames == null)
        {
            throw new ArgumentNullException(nameof(frames));
        }
        int[] yOffsets   = new int[frames.Count];
        int   currentY   = 0;
        int   totalWidth = 0;

        for (int i = 0; i < frames.Count; i++)
        {
            yOffsets[i] = currentY;
            currentY   += frames[i].Height;
            if (frames[i].Width > totalWidth)
            {
                totalWidth = frames[i].Width;
            }
        }

        if (totalWidth == 0 || currentY == 0)
        {
            throw new InvalidOperationException($"Tried to combine frames, but the width or height was 0");
        }

        var result = new SimpleTexture <T>(id, totalWidth, currentY);

        for (int i = 0; i < frames.Count; i++)
        {
            var fy    = yOffsets[i];
            var frame = frames[i];
            result.AddRegion(0, fy, frame.Width, frame.Height);
            BlitDirect(frame.GetLayerBuffer(0), result.GetMutableRegionBuffer(i));
        }

        return(result);
    }