private void CalculateConvolution(ComputeContext computeContext) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); float dx; bool shiftXParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dx); if (!shiftXParse) { throw new SyntaxErrorException(", needs to be ."); } float dy; bool shiftYParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dy); if (!shiftYParse) { throw new SyntaxErrorException(", needs to be ."); } float dz; bool shiftZParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dz); if (!shiftZParse) { throw new SyntaxErrorException(", needs to be ."); } int pixelCount = _imageDimensionX * _imageDimensionY * _imageDimensionZ; Console.WriteLine("Computing..."); Console.WriteLine("Reading kernel..."); String kernelPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; String kernelString; using (var sr = new StreamReader(kernelPath + "\\convolution.cl")) kernelString = sr.ReadToEnd(); Console.WriteLine("Reading kernel... done"); float[] selectedTransformation = Transformations.GetTransformation((TransformationType)comboBoxTransform.SelectedItem, 1.0f / float.Parse(textBoxPixelSize.Text), 1.0f / float.Parse(textBoxPixelSize.Text), 1.0f / float.Parse(textBoxPixelSize.Text), dx, dy, dz); //create openCL program ComputeProgram computeProgram = new ComputeProgram(computeContext, kernelString); computeProgram.Build(computeContext.Devices, null, null, IntPtr.Zero); ComputeProgramBuildStatus computeProgramBuildStatus = computeProgram.GetBuildStatus(_selectedComputeDevice); Console.WriteLine("computeProgramBuildStatus\n\t" + computeProgramBuildStatus); String buildLog = computeProgram.GetBuildLog(_selectedComputeDevice); Console.WriteLine("buildLog"); if (buildLog.Equals("\n")) { Console.WriteLine("\tbuildLog is empty..."); } else { Console.WriteLine("\t" + buildLog); } float[] fluorophores = CsvData.ReadFluorophores(_sourceFilename); ///////////////////////////////////////////// // Create a Command Queue & Event List ///////////////////////////////////////////// ComputeCommandQueue computeCommandQueue = new ComputeCommandQueue(computeContext, _selectedComputeDevice, ComputeCommandQueueFlags.None); //////////////////////////////////////////////////////////////// // Create Buffers Transform //////////////////////////////////////////////////////////////// ComputeBuffer <float> fluorophoresCoords = new ComputeBuffer <float>(computeContext, ComputeMemoryFlags.ReadWrite, fluorophores.LongLength); ComputeBuffer <float> transformationMatrix = new ComputeBuffer <float>(computeContext, ComputeMemoryFlags.ReadOnly, selectedTransformation.LongLength); ///////////////////////////////////////////// // Create the transformFluorophoresKernel /////////////////////////////////////////////////////////// ComputeKernel transformFluorophoresKernel = computeProgram.CreateKernel("transform_fluorophores"); ///////////////////////////////////////////// // Set the transformFluorophoresKernel arguments ///////////////////////////////////////////// transformFluorophoresKernel.SetMemoryArgument(0, fluorophoresCoords); transformFluorophoresKernel.SetMemoryArgument(1, transformationMatrix); ///////////////////////////////////////////// // Configure the work-item structure ///////////////////////////////////////////// long[] globalWorkOffsetTransformFluorophoresKernel = null; long[] globalWorkSizeTransformFluorophoresKernel = new long[] { fluorophores.Length / 4 }; long[] localWorkSizeTransformFluorophoresKernel = null; //////////////////////////////////////////////////////// // Enqueue the transformFluorophoresKernel for execution //////////////////////////////////////////////////////// computeCommandQueue.WriteToBuffer(fluorophores, fluorophoresCoords, true, null); computeCommandQueue.WriteToBuffer(selectedTransformation, transformationMatrix, true, null); computeCommandQueue.Execute(transformFluorophoresKernel, globalWorkOffsetTransformFluorophoresKernel, globalWorkSizeTransformFluorophoresKernel, localWorkSizeTransformFluorophoresKernel, null); // computeCommandQueue.ExecuteTask(transformFluorophoresKernel, transformFluorophoresEvents); float[] transformedFluorophores = new float[fluorophores.Length]; computeCommandQueue.ReadFromBuffer(fluorophoresCoords, ref transformedFluorophores, true, null); computeCommandQueue.Finish(); //TODO remove, only for testing // for (int i = 0; i < transformedFluorophores.Length; i++) // { // Console.WriteLine(transformedFluorophores[i]); // } // /TODO remove, only for testing stopwatch.Stop(); Console.WriteLine("Transform fluophores duration:\n\t" + stopwatch.Elapsed); stopwatch.Reset(); stopwatch.Start(); // fluorophoresCoords are now transformed (done in place) //////////////////////////////////////////////////////////////// // Create Buffers Convolve Fluorophores //////////////////////////////////////////////////////////////// const int convolve_kernel_lwgs = 16; int totalBuffer = (int)Math.Ceiling(pixelCount / (float)convolve_kernel_lwgs) * convolve_kernel_lwgs; ComputeBuffer <float> resultImage = new ComputeBuffer <float>(computeContext, ComputeMemoryFlags.WriteOnly, totalBuffer); ///////////////////////////////////////////// // Create the transformFluorophoresKernel ///////////////////////////////////////////// ComputeKernel convolveFluorophoresKernel = computeProgram.CreateKernel("convolve_fluorophores"); ///////////////////////////////////////////// // Set the convolveFluorophoresKernel arguments ///////////////////////////////////////////// convolveFluorophoresKernel.SetMemoryArgument(0, resultImage); convolveFluorophoresKernel.SetValueArgument(1, _imageDimensionX); convolveFluorophoresKernel.SetValueArgument(2, _imageDimensionY); convolveFluorophoresKernel.SetMemoryArgument(3, fluorophoresCoords); convolveFluorophoresKernel.SetLocalArgument(4, convolve_kernel_lwgs); convolveFluorophoresKernel.SetValueArgument(5, fluorophores.Length / 4); ///////////////////////////////////////////// // Configure the work-item structure ///////////////////////////////////////////// long[] globalWorkOffsetTransformConvolveFluorophoresKernel = null; long[] globalWorkSizeTransformConvolveFluorophoresKernel = new long[] { pixelCount }; long[] localWorkSizeTransformConvolveFluorophoresKernel = new long[] { convolve_kernel_lwgs }; //////////////////////////////////////////////////////// // Enqueue the convolveFluorophoresKernel for execution //////////////////////////////////////////////////////// computeCommandQueue.Execute(convolveFluorophoresKernel, globalWorkOffsetTransformConvolveFluorophoresKernel, globalWorkSizeTransformConvolveFluorophoresKernel, localWorkSizeTransformConvolveFluorophoresKernel, null); float[] resultImageData = new float[totalBuffer]; computeCommandQueue.ReadFromBuffer(resultImage, ref resultImageData, true, null); computeCommandQueue.Finish(); for (int i = 0; i < pixelCount; i++) { Console.WriteLine(resultImageData[i]); } Console.WriteLine("Writing data to file..."); // CsvData.WriteToDisk("..\\..\\..\\output.csv", resultImageData); TiffData.WriteToDisk(resultImageData, _saveFilename, _imageDimensionX, _imageDimensionY); Bitmap bitmap = new Bitmap(_imageDimensionX, _imageDimensionY); float max = resultImageData.Max(); float scale = 255 / (float)max; // for (int r = 0; r < _imageDimensionY; r++) // { // for (int c = 0; c < _imageDimensionX; c++) // { // float value = resultImageData[c*(r + 1)]; // Color newColor = Color.FromArgb((int)(value * scale), (int)(value * scale), (int)(value * scale)); // bitmap.SetPixel(c,r, newColor); // } // } ushort[] ushortdata = new ushort[resultImageData.Length]; for (int i = 0; i < resultImageData.Length; i++) { ushortdata[i] = (ushort)resultImageData[i]; } uint[] convertGray16ToRgb = ConvertGray16ToRGB(ushortdata, 16); byte[] bytes = new byte[convertGray16ToRgb.Length * 4]; // // int[] resultImageData2 = new int[resultImageData.Length]; // for (int index = 0; index < convertGray16ToRgb.Length; index++) { // resultImageData2[index] = (int)(scale*resultImageData[index]); byte[] bytes1 = BitConverter.GetBytes(convertGray16ToRgb[index]); bytes[index] = bytes1[0]; bytes[4 * index + 1] = bytes1[1]; bytes[4 * index + 2] = bytes1[2]; bytes[4 * index + 3] = bytes1[3]; } // // for (int r = 0; r < _imageDimensionY; r++) // { // for (int c = 0; c < _imageDimensionX; c++) // { // float value = resultImageData2[c*(r + 1)]; // Color newColor = Color.FromArgb((int)(value), (int)(value), (int)(value)); // bitmap.SetPixel(c,r, newColor); // } // } // bitmap.Save("c:\\temp.bmp"); using (MemoryStream ms = new MemoryStream(bytes)) { Image image = Bitmap.FromStream(ms); image.Save("c:\\temp.bmp"); } Console.WriteLine("Writing data to file... done"); stopwatch.Stop(); Console.WriteLine("Convolve fluophores duration:\n\t" + stopwatch.Elapsed); Console.WriteLine("Computing... done"); }
// 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(); }
internal override void setFromInfoCollection(TiffInfoCollection info) { base.setFromInfoCollection(info); StkInfoCollection allInfo = info as StkInfoCollection; if (allInfo == null) { return; } List <TiffDirData> dirTemp = new List <TiffDirData>(); numPlane = allInfo.NumberOfPlanes; uint[] uic2 = new uint[6 * numPlane]; if (allInfo.validUIC2tag()) { for (int i = 0; i < Math.Min(numPlane, allInfo.ZDistance.Length); i++) { if (allInfo.ZDistance[i] != null) { Array content = allInfo.ZDistance[i].Data.getContent(); if (content == null || content.Length <= 0) { continue; } uint[] temp = (uint[])content; uic2[6 * i] = temp[0]; uic2[6 * i + 1] = temp[1]; } else { uic2[6 * i] = 0; uic2[6 * i + 1] = 0; } } for (int i = 0; i < Math.Min(numPlane, allInfo.CreationTime.Length); i++) { if (allInfo.CreationTime[i] != null) { Array content = allInfo.CreationTime[i].Data.getContent(); if (content == null || content.Length <= 0) { continue; } uint[] temp = (uint[])content; uic2[6 * i + 2] = temp[0]; uic2[6 * i + 3] = temp[1]; } else { uic2[6 * i + 2] = 0; uic2[6 * i + 3] = 0; } } for (int i = 0; i < Math.Min(numPlane, allInfo.ModifiedTime.Length); i++) { if (allInfo.ModifiedTime[i] != null) { Array content = allInfo.ModifiedTime[i].Data.getContent(); if (content == null || content.Length <= 0) { continue; } uint[] temp = (uint[])(content); uic2[6 * i + 4] = temp[0]; uic2[6 * i + 5] = temp[1]; } else { uic2[6 * i + 4] = 0; uic2[6 * i + 5] = 0; } } } UIC2data = new TiffData(TiffData.TIFFdataType.Rational); UIC2data.setContent(uic2); TiffDirData ddTemp = new TiffDirData(); ddTemp.Tag = StkInfoCollection.UIC2Tag; ddTemp.Data = new TiffData(TiffData.TIFFdataType.Rational, numPlane); dirTemp.Add(ddTemp); if (allInfo.validUIC3tag()) { uint[] uic3 = new uint[2 * numPlane]; for (int i = 0; i < numPlane; i++) { if (allInfo.Wavelength[i] != null) { uint[] temp = (uint[])(allInfo.Wavelength[i].Data.getContent()); uic3[2 * i] = temp[0]; uic3[2 * i + 1] = temp[1]; } else { uic3[2 * i] = 0; uic3[2 * i + 1] = 0; } } UIC3data = new TiffData(TiffData.TIFFdataType.Rational); UIC3data.setContent(uic3); ddTemp = new TiffDirData(); ddTemp.Tag = StkInfoCollection.UIC3Tag; ddTemp.Data = new TiffData(TiffData.TIFFdataType.Rational, numPlane); dirTemp.Add(ddTemp); } UIC4data = new SortedList <ushort, TiffData[]>(); if (allInfo.validUIC4tag()) { ddTemp = new TiffDirData(); ddTemp.Tag = StkInfoCollection.UIC4Tag; ddTemp.Data = new TiffData(TiffData.TIFFdataType.Byte, numPlane); dirTemp.Add(ddTemp); foreach (KeyValuePair <ushort, List <TiffInfo> > pair in allInfo.UIC4DataDeepCopy) { if (pair.Value.Count != numPlane) { continue; } TiffData[] temp = new TiffData[numPlane]; for (int j = 0; j < numPlane; j++) { temp[j] = (pair.Value)[j].Data; } UIC4data.Add(pair.Key, temp); } } UIC1data = new SortedList <uint, TiffData[]>(); if (allInfo.validUIC1tag()) { ddTemp = new TiffDirData(); ddTemp.Tag = StkInfoCollection.UIC1Tag; SortedList <uint, List <TiffInfo> > uic1Copy = allInfo.UIC1DataDeepCopy; ddTemp.Data = new TiffData(TiffData.TIFFdataType.Byte, uic1Copy.Count); dirTemp.Add(ddTemp); foreach (KeyValuePair <uint, List <TiffInfo> > pair in uic1Copy) { TiffData[] temp = new TiffData[pair.Value.Count]; for (int i = 0; i < pair.Value.Count; i++) { temp[i] = pair.Value[i].Data; } UIC1data.Add(pair.Key, temp); } } TiffDirData[] newDir = new TiffDirData[dirArray.Length + dirTemp.Count]; for (int i = 0; i < dirArray.Length; i++) { newDir[i] = dirArray[i]; } for (int i = dirArray.Length; i < newDir.Length; i++) { newDir[i] = dirTemp[i - dirArray.Length]; } dirArray = newDir; Array.Sort(dirArray); }
private long[] preWriteUIC1tagData(System.IO.BinaryWriter writer) { System.IO.Stream stream = writer.BaseStream; long[] offset = new long[UIC1data.Count]; for (int i = 0; i < UIC1data.Count; i++) { uint id = UIC1data.Keys[i]; // ONE LONG 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) { //do nothing, write data later offset[i] = -1; } // ONE RATIONAL or 2*N LONG (N RATIONALs) or N Longs 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 || id == StkInfoCollection.AbsoluteZ || id == StkInfoCollection.AbsoluteZValid || id == StkInfoCollection.StagePosition || id == StkInfoCollection.CameraChipOffset) { offset[i] = stream.Position; TiffData data = UIC1data.Values[i][0]; data.write(writer); } // STRING else if (id == StkInfoCollection.CalibrationUnits || id == StkInfoCollection.Name) { offset[i] = stream.Position; TiffData data = UIC1data.Values[i][0]; writer.Write(data.Count); data.write(writer); } // OFFSET OF A LONG else if (id == StkInfoCollection.Gamma || id == StkInfoCollection.GammaRed || id == StkInfoCollection.GammaGreen || id == StkInfoCollection.GammaBlue) { offset[i] = stream.Position; TiffData data = UIC1data.Values[i][0]; data.write(writer); } // RGB TABLE else if (id == StkInfoCollection.UserLutTable) { offset[i] = stream.Position; TiffData data = UIC1data.Values[i][0]; data.write(writer); } // IGNORED FOR NOW else if (id == StkInfoCollection.CameraBin || id == StkInfoCollection.ImagePropertyEx || id == StkInfoCollection.OverlayPlaneColor) { offset[i] = -2; } // N Strings else if (id == StkInfoCollection.StageLabel) { offset[i] = stream.Position; for (int j = 0; j < UIC1data.Values[i].Length; j++) { TiffData data = UIC1data.Values[i][j]; writer.Write(data.Count); data.write(writer); } } //IDs not known how to write else { offset[i] = -3; } } return(offset); }
private void readUIC4tagData(System.IO.BinaryReader reader) { System.IO.Stream stream = reader.BaseStream; UIC4data = new SortedList <ushort, TiffData[]>(); ushort id = reader.ReadUInt16(); while (id > 0) { // UIC4 2*(# OF PLANES) RATIONALS if (id == StkInfoCollection.StagePosition || id == StkInfoCollection.CameraChipOffset) { TiffData[] data = new TiffData[numPlane]; for (int i = 0; i < numPlane; i++) { data[i] = new TiffData(TiffData.TIFFdataType.Rational, 2); data[i].read(reader); } UIC4data.Add(id, data); } // UIC4 (# OF PLANES) STRINGS else if (id == StkInfoCollection.StageLabel) { TiffData[] data = new TiffData[numPlane]; for (int i = 0; i < numPlane; i++) { data[i] = new TiffData(TiffData.TIFFdataType.Ascii, reader.ReadInt32()); data[i].read(reader); } UIC4data.Add(id, data); } // UIC4 (# OF PLANES) RATIONALS else if (id == StkInfoCollection.AbsoluteZ || id == StkInfoCollection.CameraBin) { TiffData[] data = new TiffData[numPlane]; for (int i = 0; i < numPlane; i++) { data[i] = new TiffData(TiffData.TIFFdataType.Rational, 1); data[i].read(reader); } UIC4data.Add(id, data); } // UIC4 (# OF PLANES) LONGS else if (id == StkInfoCollection.AbsoluteZValid) { TiffData[] data = new TiffData[numPlane]; for (int i = 0; i < numPlane; i++) { data[i] = new TiffData(TiffData.TIFFdataType.Long, 1); data[i].read(reader); } UIC4data.Add(id, data); } // ignore any other tags else { return; } id = reader.ReadUInt16(); } }
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; } } }