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); }
internal override void write(System.IO.BinaryWriter writer, out long nextIfdPos) { System.IO.Stream stream = writer.BaseStream; nextIfdPos = -1; if (dirArray.Length <= 0) { return; } uint offset = Convert.ToUInt32(stream.Position + 2 + dirArray.Length * 12 + 4); long startOffset = offset; bool r1, r2, r3, r4; r1 = r2 = r3 = r4 = false; ushort dircnt = 0; for (int i = 0; i < dirArray.Length; i++) { switch (dirArray[i].Tag) { case StkInfoCollection.UIC1Tag: r1 = UIC1data != null && UIC1data.Count > 0; dircnt++; break; case StkInfoCollection.UIC2Tag: r2 = UIC2data.getContent().Length > 0; dircnt++; break; case StkInfoCollection.UIC3Tag: r3 = UIC3data.getContent().Length > 0; dircnt++; break; case StkInfoCollection.UIC4Tag: r4 = UIC4data != null && UIC4data.Count > 0; dircnt++; break; default: dircnt++; break; } } writer.Write(dircnt); for (int i = 0; i < dirArray.Length; i++) { if (dirArray[i].Tag != StkInfoCollection.UIC1Tag && dirArray[i].Tag != StkInfoCollection.UIC2Tag && dirArray[i].Tag != StkInfoCollection.UIC3Tag && dirArray[i].Tag != StkInfoCollection.UIC4Tag) { dirArray[i].write(writer, ref offset); } } long currPosTemp = stream.Position; if (currPosTemp < startOffset) { byte[] space = new byte[startOffset - currPosTemp]; writer.Write(space); } else if (currPosTemp > startOffset) { throw new WriteFileException("Offset calculation failed."); } for (int i = 0; i < dirArray.Length; i++) { if (dirArray[i].Tag == StkInfoCollection.UIC1Tag || dirArray[i].Tag == StkInfoCollection.UIC2Tag || dirArray[i].Tag == StkInfoCollection.UIC3Tag || dirArray[i].Tag == StkInfoCollection.UIC4Tag) { continue; } if (dirArray[i].Data.dataLength() > 4) { dirArray[i].Data.write(writer); } } stream.Seek(currPosTemp, System.IO.SeekOrigin.Begin); if (r1) { writer.Write(Convert.ToUInt16(StkInfoCollection.UIC1Tag)); writer.Write(Convert.ToUInt16(4)); long offtemp = stream.Position; stream.Seek(offset, System.IO.SeekOrigin.Begin); long[] uic1off = preWriteUIC1tagData(writer); long dataoff = postWriteUIC1tagData(writer, uic1off, ref offset); stream.Seek(offtemp, System.IO.SeekOrigin.Begin); writer.Write(uic1off.Length); writer.Write(Convert.ToUInt32(dataoff)); } if (r2) { writer.Write(Convert.ToUInt16(StkInfoCollection.UIC2Tag)); writer.Write(Convert.ToUInt16(5)); writer.Write(numPlane); writer.Write(offset); long offtemp = stream.Position; stream.Seek(offset, System.IO.SeekOrigin.Begin); UIC2data.write(writer); offset = Convert.ToUInt32(stream.Position); stream.Seek(offtemp, System.IO.SeekOrigin.Begin); } if (r3) { writer.Write(Convert.ToUInt16(StkInfoCollection.UIC3Tag)); writer.Write(Convert.ToUInt16(5)); writer.Write(numPlane); writer.Write(offset); long offtemp = stream.Position; stream.Seek(offset, System.IO.SeekOrigin.Begin); UIC3data.write(writer); offset = Convert.ToUInt32(stream.Position); stream.Seek(offtemp, System.IO.SeekOrigin.Begin); } if (r4) { writer.Write(Convert.ToUInt16(StkInfoCollection.UIC4Tag)); writer.Write(Convert.ToUInt16(4)); writer.Write(numPlane); writer.Write(offset); long offtemp = stream.Position; stream.Seek(offset, System.IO.SeekOrigin.Begin); writeUIC4tagData(writer, ref offset); stream.Seek(offtemp, System.IO.SeekOrigin.Begin); } nextIfdPos = stream.Position; writer.Write(Convert.ToUInt32(nextIFD)); stream.Seek(offset, System.IO.SeekOrigin.Begin); }