Esempio n. 1
0
        // Not all STK file info can be read : The STK documentation I used might be out of date?
        internal override void postRead(System.IO.BinaryReader reader)
        {
            System.IO.Stream   stream  = reader.BaseStream;
            List <TiffDirData> dirTemp = new List <TiffDirData>();

            TiffDirData dir = search(StkInfoCollection.UIC2Tag);

            if (dir != null)
            {
                if (dir.Offset < 0)
                {
                    throw new ReadFileException("Corrupted stack file.");
                }

                try
                {
                    stream.Seek(dir.Offset, System.IO.SeekOrigin.Begin);
                    UIC2data = new TiffData(TiffData.TIFFdataType.Rational, 3 * numPlane);
                    UIC2data.read(reader);
                    dirTemp.Add(dir);
                }
                catch
                {
                    throw new ReadFileException("Corrupted stack file.");
                }
            }

            dir = search(StkInfoCollection.UIC3Tag);
            if (dir != null)
            {
                try
                {
                    stream.Seek(dir.Offset, System.IO.SeekOrigin.Begin);
                    UIC3data = new TiffData(TiffData.TIFFdataType.Rational, numPlane);
                    UIC3data.read(reader);
                    dirTemp.Add(dir);
                }
                catch
                {
                    UIC3data = null;
                }
            }

            dir = search(StkInfoCollection.UIC4Tag);
            if (dir != null)
            {
                try
                {
                    stream.Seek(dir.Offset, System.IO.SeekOrigin.Begin);
                    readUIC4tagData(reader);
                    dirTemp.Add(dir);
                }
                catch
                {
                    UIC4data = null;
                }
            }

            dir = search(StkInfoCollection.UIC1Tag);
            if (dir != null)
            {
                try
                {
                    stream.Seek(dir.Offset, System.IO.SeekOrigin.Begin);
                    readUIC1tagData(reader, dir.Data.Count);
                    dirTemp.Add(dir);
                }
                catch
                {
                    UIC1data = null;
                }
            }

            for (int i = 0; i < dirArray.Length; i++)
            {
                if (dirArray[i].Tag == StkInfoCollection.UIC1Tag)
                {
                    continue;
                }
                else if (dirArray[i].Tag == StkInfoCollection.UIC2Tag)
                {
                    continue;
                }
                else if (dirArray[i].Tag == StkInfoCollection.UIC3Tag)
                {
                    continue;
                }
                else if (dirArray[i].Tag == StkInfoCollection.UIC4Tag)
                {
                    continue;
                }
                else if (dirArray[i].Offset > 0)
                {
                    try
                    {
                        stream.Seek(dirArray[i].Offset, System.IO.SeekOrigin.Begin);
                        dirArray[i].readData(reader);
                    }
                    catch
                    {
                        continue;
                    }
                }
                dirTemp.Add(dirArray[i]);
            }
            dirArray = dirTemp.ToArray();
            this.sort();
        }
Esempio n. 2
0
        private void readUIC1tagData(System.IO.BinaryReader reader, int count)
        {
            System.IO.Stream stream = reader.BaseStream;

            UIC1data = new SortedList <uint, TiffData[]>();
            for (int i = 0; i < count; i++)
            {
                uint id = reader.ReadUInt32();

                // ONE LONG
                //New Lut??
                if (id == StkInfoCollection.AutoScale || id == StkInfoCollection.MinScale || id == StkInfoCollection.MaxScale || id == StkInfoCollection.SpatialCalibration ||
                    id == StkInfoCollection.ThreshState || id == StkInfoCollection.ThreshStateRed || id == StkInfoCollection.ThreshStateBlue || id == StkInfoCollection.ThreshStateGreen ||
                    id == StkInfoCollection.ThreshStateLo || id == StkInfoCollection.ThreshStateHi || id == StkInfoCollection.Zoom || id == StkInfoCollection.CurrentBuffer ||
                    id == StkInfoCollection.GrayFit || id == StkInfoCollection.GrayPointCount || id == StkInfoCollection.WavelengthTag ||
                    id == StkInfoCollection.RedAutoScaleInfo || id == StkInfoCollection.RedMinScaleInfo || id == StkInfoCollection.RedMaxScaleInfo ||
                    id == StkInfoCollection.GreenAutoScaleInfo || id == StkInfoCollection.GreenMinScaleInfo || id == StkInfoCollection.GreenMaxScaleInfo ||
                    id == StkInfoCollection.BlueAutoScaleInfo || id == StkInfoCollection.BlueMinScaleInfo || id == StkInfoCollection.BlueMaxScaleInfo ||
                    id == StkInfoCollection.GrayUnitName || id == StkInfoCollection.StandardLUT || id == StkInfoCollection.NewLUT ||
                    id == 10)
                {
                    TiffData data = new TiffData(TiffData.TIFFdataType.Long, 1);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                }
                // ONE RATIONAL
                else if (id == StkInfoCollection.XCalibration || id == StkInfoCollection.YCalibration || id == StkInfoCollection.CreateTime || id == StkInfoCollection.LastSavedTime ||
                         id == StkInfoCollection.GrayX || id == StkInfoCollection.GrayY || id == StkInfoCollection.GrayMin || id == StkInfoCollection.GrayMax ||
                         id == StkInfoCollection.AutoScaleLoInfo || id == StkInfoCollection.AutoScaleHiInfo ||
                         id == StkInfoCollection.RedAutoScaleLoInfo || id == StkInfoCollection.RedAutoScaleHiInfo ||
                         id == StkInfoCollection.GreenAutoScaleLoInfo || id == StkInfoCollection.GreenAutoScaleHiInfo ||
                         id == StkInfoCollection.BlueAutoScaleHiInfo || id == StkInfoCollection.BlueAutoScaleLoInfo)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Rational, 1);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // 2*N LONG (N RATIONALs)
                else if (id == StkInfoCollection.AbsoluteZ)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Rational, numPlane);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // N LONGs
                else if (id == StkInfoCollection.AbsoluteZValid)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Long, numPlane);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // STRING
                else if (id == StkInfoCollection.CalibrationUnits || id == StkInfoCollection.Name)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Ascii, reader.ReadInt32());
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // OFFSET OF A LONG
                else if (id == StkInfoCollection.Gamma || id == StkInfoCollection.GammaRed || id == StkInfoCollection.GammaGreen || id == StkInfoCollection.GammaBlue)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Long, 1);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // RGB TABLE
                else if (id == StkInfoCollection.UserLutTable)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Byte, 768);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // 4*N long (2*N RATIONALS)
                else if (id == StkInfoCollection.StagePosition || id == StkInfoCollection.CameraChipOffset)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    stream.Seek(offset, System.IO.SeekOrigin.Begin);
                    TiffData data = new TiffData(TiffData.TIFFdataType.Rational, 2 * numPlane);
                    data.read(reader);
                    UIC1data.Add(id, new TiffData[1] {
                        data
                    });
                    stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                }
                // IGNORED FOR NOW
                else if (id == StkInfoCollection.CameraBin || id == StkInfoCollection.ImagePropertyEx || id == StkInfoCollection.OverlayPlaneColor)
                {
                    reader.ReadUInt32();
                }
                // N STRINGs
                else if (id == StkInfoCollection.StageLabel)
                {
                    long offset  = reader.ReadUInt32();
                    long currPos = stream.Position;
                    if (offset >= 0)
                    {
                        try {
                            stream.Seek(offset, System.IO.SeekOrigin.Begin);
                            uint[]     pos  = new uint[numPlane];
                            TiffData[] data = new TiffData[numPlane];
                            stream.Seek(reader.ReadUInt32(), System.IO.SeekOrigin.Begin);
                            for (int x = 0; x < numPlane; x++)
                            {
                                data[x] = new TiffData(TiffData.TIFFdataType.Ascii, reader.ReadInt32());
                            }
                            UIC1data.Add(id, data);
                        } catch {
                        } finally {
                            stream.Seek(currPos, System.IO.SeekOrigin.Begin);
                        }
                    }
                }
                // ignore undefined tags
                else
                {
                    return;
                }
            }
        }