Exemple #1
0
        public override void Open()
        {
            Close();

            Header   = TimHeader.Read(IOStream);
            Palettes = TimPalettes.TryRead(Header, IOStream);
        }
Exemple #2
0
        public static TimHeader Read(Stream input)
        {
            TimHeader result = input.ReadStruct <TimHeader>();

            result.Validate();

            return(result);
        }
Exemple #3
0
        public static TimImageHeader Read(TimHeader header, Stream input)
        {
            TimImageHeader result = input.ReadStruct <TimImageHeader>();

            if (header.BytesPerPixel == 0)
            {
                result.Width *= 2;
            }
            return(result);
        }
Exemple #4
0
        private static TimPalettes Read(TimHeader header, Stream input)
        {
            TimPalettesHeader palettesHeader = TimPalettesHeader.Read(input);

            BitmapPalette[] palettes = new BitmapPalette[palettesHeader.PalettesCount];
            for (int i = 0; i < palettes.Length; i++)
            {
                palettes[i] = ReadPalette(palettesHeader, input);
            }
            return(new TimPalettes(palettesHeader, palettes));
        }
Exemple #5
0
        public TimPixelFormatsConverter(TimHeader header, TimImageHeader imageHeader, Stream input, Stream output)
        {
            Exceptions.CheckArgumentNull(header, "header");
            Exceptions.CheckArgumentNull(imageHeader, "imageHeader");
            Exceptions.CheckArgumentNull(input, "input");
            Exceptions.CheckArgumentNull(output, "output");

            _header      = header;
            _imageHeader = imageHeader;
            _input       = input;
            _output      = output;
        }
Exemple #6
0
        public static TimPalettes TryRead(TimHeader header, Stream input)
        {
            Exceptions.CheckArgumentNull(header, "header");
            Exceptions.CheckArgumentNull(input, "input");

            if (!header.HasPalette)
            {
                return(null);
            }

            return(Read(header, input));
        }
Exemple #7
0
        public static TimImage Read(TimHeader header, Stream input)
        {
            TimImageHeader imageHeader = TimImageHeader.Read(header, input);
            GLTexture      layer       = TimTexture2DReader.Read(header, imageHeader, input);

            //SafeHGlobalHandle pixels = new SafeHGlobalHandle(imageHeader.Width * imageHeader.Height * header.OutputPixelFormat.BitsPerPixel / 8);
            SafeHGlobalHandle pixels = new SafeHGlobalHandle(imageHeader.ContentSize);

            try
            {
                using (UnmanagedMemoryStream output = new UnmanagedMemoryStream(pixels, 0, (long)pixels.ByteLength, FileAccess.Write))
                    TimPixelFormatsConverter.Convert(header, imageHeader, input, output);
            }
            catch
            {
                pixels.Dispose();
                throw;
            }
            return(new TimImage(imageHeader, layer));
        }
 public TimTexture2DReader(TimHeader header, TimImageHeader imageHeader, Stream input)
 {
     _header      = Exceptions.CheckArgumentNull(header, "header");
     _imageHeader = Exceptions.CheckArgumentNull(imageHeader, "imageHeader");
     _input       = Exceptions.CheckReadableStream(input, "input");
 }
        public static GLTexture Read(TimHeader header, TimImageHeader imageHeader, Stream input)
        {
            TimTexture2DReader converter = new TimTexture2DReader(header, imageHeader, input);

            return(converter.Read());
        }
Exemple #10
0
        public static void Convert(TimHeader header, TimImageHeader imageHeader, Stream input, Stream output)
        {
            TimPixelFormatsConverter converter = new TimPixelFormatsConverter(header, imageHeader, input, output);

            converter.Convert();
        }
Exemple #11
0
 public override void Close()
 {
     IOStream.Seek(0, SeekOrigin.Begin);
     Header   = null;
     Palettes = null;
 }