SeekSet() public method

public SeekSet ( long position ) : void
position long
return void
Beispiel #1
0
    private void ParseBitmap(ByteStream stream, CreateArgs createArgs)
    {
        if ((stream.ReadString(3) != "BM ") || (stream.ReadByte() != 0x1e)){
            throw new InvalidDataException("Not a BM file.");
        }

        Header header = ReadHeader(stream, EHeaderType.FileHeader);
        DebugCheck.Assert(stream.Position == 32);

        if ((header.W == 1) && (header.H != 1)) {
            // multiple bitmaps in this file.
            _fps = stream.ReadByte();
            stream.Skip(1);

            long baseOfs = stream.Position;

            int[] offsets = new int[header.IY];
            for (int i = 0; i < offsets.Length; ++i) {
                offsets[i] = stream.ReadLittleInt32();
            }

            for (int i = 0; i < offsets.Length; ++i) {
                stream.SeekSet(offsets[i] + baseOfs);
                Header subHeader = ReadHeader(stream, EHeaderType.SubHeader);
                Frame frame = ReadColumns(stream, subHeader, null, createArgs);
                _frames.Add(frame);
            }
        } else {
            int[] columnOffsets = null;

            if (header.Compressed != 0) {
                // read column offsets.
                stream.SeekSet(header.DataSize);
                columnOffsets = new int[header.W];

                for (int i = 0; i < columnOffsets.Length; ++i) {
                    columnOffsets[i] = stream.ReadLittleInt32() + 32;
                }
            }

            Frame frame = ReadColumns(stream, header, columnOffsets, createArgs);
            _frames.Add(frame);
        }
    }
Beispiel #2
0
    public static Frame ReadColumns(ByteStream stream, Header header, int[] columnOffsets, CreateArgs createArgs)
    {
        try {
            Texture2D texture = new Texture2D(header.W, header.H, createArgs.TextureFormat, createArgs.bMipmap, false);

            texture.anisoLevel = createArgs.AnisoLevel;
            texture.filterMode = createArgs.FilterMode;
            texture.wrapMode = createArgs.WrapMode;

            Color32[] pixels = new Color32[header.W*header.H];
            byte[] column = new byte[header.H];
            bool bIsTransparent = (header.Transparent & 0x8) != 0;

            for (int x = 0; x < header.W; ++x) {
                if (columnOffsets != null) {
                    stream.SeekSet(columnOffsets[x]);
                }

                DecodeColumn(stream, column, header.Compressed);

                if (createArgs.TextureFormat == TextureFormat.Alpha8) {
                    int pixelOfs = x;

                    for (int y = 0; y < header.H; ++y, pixelOfs += header.W) {
                        byte color = column[y];
                        pixels[pixelOfs] = new Color32(color, color, color, color);
                    }

                } else {
                    int pixelOfs = x;

                    for (int y = 0; y < header.H; ++y, pixelOfs += header.W) {
                        byte color = column[y];

                        if (bIsTransparent && (color == 0)) {
                            pixels[pixelOfs] = PAL.Transparent;
                        } else {
                            pixels[pixelOfs] = createArgs.Pal.Colors[color];
                        }
                    }
                }
            }

            texture.SetPixels32(pixels);
            texture.Apply();

            return new Frame(texture, bIsTransparent);
        } catch (UnityException e) {
            throw e;
        }
    }
Beispiel #3
0
 string GetChunkType(ByteStream stream)
 {
     long pos = stream.Position;
     string type = stream.ReadString(4);
     stream.SeekSet(pos);
     return type;
 }