public RAWSequenceSource(RAWDATAFORMAT theRawDataFormat, int theWidth, int theHeight, byte[,] theBayerPattern, string[] thePaths) { rawDataFormat = theRawDataFormat; width = theWidth; height = theHeight; bayerPattern = theBayerPattern; paths = thePaths; }
public CRISequenceSource(string[] thePaths) { byte[] tmpValue; paths = thePaths; Dictionary <UInt32, byte[]> tagData = readCRITagData(paths[0]); bool isInvalid = false; if (tagData.ContainsKey((UInt32)Key.FrameInfo)) { tmpValue = tagData[(UInt32)Key.FrameInfo]; width = (int)BitConverter.ToUInt32(tmpValue, 0); height = (int)BitConverter.ToUInt32(tmpValue, 4); // Bayer pattern and bit depth. UInt32 colorModel = BitConverter.ToUInt32(tmpValue, 8); switch (colorModel) { case (UInt32)ColorModel.COLOR_MODEL_BAYER_GRGR_CINTEL_10: bayerPattern = new byte[2, 2] { { 1, 0 }, { 2, 1 } }; throw new Exception("10 bit modes not supported (yet?)"); //rawDataFormat = RAWDATAFORMAT.BAYERRG12p; break; // 12 bit modes // NOTE: Untested so far! case (UInt32)ColorModel.COLOR_MODEL_BAYER_BGGR_CINTEL_12: bayerPattern = new byte[2, 2] { { 2, 1 }, { 1, 0 } }; rawDataFormat = RAWDATAFORMAT.BAYERRG12p; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_GBGB_CINTEL_12: bayerPattern = new byte[2, 2] { { 1, 2 }, { 0, 1 } }; rawDataFormat = RAWDATAFORMAT.BAYERRG12p; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_RGRG_CINTEL_12: bayerPattern = new byte[2, 2] { { 0, 1 }, { 1, 2 } }; rawDataFormat = RAWDATAFORMAT.BAYERRG12p; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_GRGR_CINTEL_12: bayerPattern = new byte[2, 2] { { 1, 0 }, { 2, 1 } }; rawDataFormat = RAWDATAFORMAT.BAYERRG12p; break; // 16 bit modes case (UInt32)ColorModel.COLOR_MODEL_BAYER_BGGR_CINTEL_16: bayerPattern = new byte[2, 2] { { 2, 1 }, { 1, 0 } }; rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_GBGB_CINTEL_16: bayerPattern = new byte[2, 2] { { 1, 2 }, { 0, 1 } }; rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_RGRG_CINTEL_16: bayerPattern = new byte[2, 2] { { 0, 1 }, { 1, 2 } }; rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; break; case (UInt32)ColorModel.COLOR_MODEL_BAYER_GRGR_CINTEL_16: bayerPattern = new byte[2, 2] { { 1, 0 }, { 2, 1 } }; rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; break; default: break; } } else { isInvalid = true; } /* * if (tagData.ContainsKey((UInt32)Key.CodecType)) * { * tmpValue = tagData[(UInt32)Key.CodecType]; * UInt32 codecType = BitConverter.ToUInt32(tmpValue, 0); * if(codecType != (UInt32)ContainerCodecType.CODEC_TYPE_NONE) * { * throw new Exception("Only uncompressed CRI files supported"); // Actually, this will not detect compression reliably! So currently this whole code doesn't work yet. * } * } * else * { * isInvalid = true; * }*/ if (isInvalid) { throw new Exception("No width/height tag data found in CRI file"); } }
public StreampixSequenceSource(string sequencePath) { path = sequencePath; using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.Unicode)) { reader.BaseStream.Seek(28, SeekOrigin.Begin); version = reader.ReadUInt32(); reader.BaseStream.Seek(36, SeekOrigin.Begin); description = new string(reader.ReadChars(52)); // The length seems to vary. Officially length is supposedly 512 bytes but that seems to be nonsense. But who knows. reader.BaseStream.Seek(548, SeekOrigin.Begin); width = reader.ReadUInt32(); height = reader.ReadUInt32(); bitDepth = reader.ReadUInt32(); bitDepthReal = reader.ReadUInt32(); singleImageByteSize = reader.ReadUInt32(); imageFormat = (ImageFormat)reader.ReadUInt32(); reader.BaseStream.Seek(572, SeekOrigin.Begin); imageCount = reader.ReadUInt32(); reader.BaseStream.Seek(580, SeekOrigin.Begin); singleImageRealByteSize = reader.ReadUInt32(); reader.BaseStream.Seek(608, SeekOrigin.Begin); // Bayer pattern parsing // Should correspond to these in this order: GBRG, GRBG, BGGR a RGGB.Moje kamera pouziva RGGB co je v nastaveni 3 patern ale jeho kamera a jeho kamera Basler pouziva GBRG cos je u tebe cislo 0. UInt32 bayerPatternAsUINT = reader.ReadUInt32(); // 0= red, 1=green,2=blue switch (bayerPatternAsUINT) { // GBRG case 0: bayerPattern = new byte[2, 2] { { 1, 2 }, { 0, 1 } }; break; // GRBG case 1: bayerPattern = new byte[2, 2] { { 1, 0 }, { 2, 1 } }; break; // BGGR case 2: bayerPattern = new byte[2, 2] { { 2, 1 }, { 1, 0 } }; break; // RGGB case 3: default: bayerPattern = new byte[2, 2] { { 0, 1 }, { 1, 2 } }; break; } reader.BaseStream.Seek(620, SeekOrigin.Begin); compression = (Compression)reader.ReadUInt32(); reader.BaseStream.Seek(660, SeekOrigin.Begin); UInt32 imageBytesAlignment = reader.ReadUInt32(); // Not quite sure what this one does tbh if (bitDepthReal == bitDepth && bitDepth == 16) { rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; } else if (bitDepthReal == 12 && bitDepth == 16) { rawDataFormat = RAWDATAFORMAT.BAYER12BITDARKCAPSULEDIN16BIT; } else if (bitDepthReal == 12 && bitDepth == 12 && imageFormat == ImageFormat.MONO_BAYER_PPACKED) { rawDataFormat = RAWDATAFORMAT.BAYERRG12p; } else { rawDataFormat = RAWDATAFORMAT.INVALID; } seqFileBasenameNoDots = Path.GetFileNameWithoutExtension(path).Replace(".", "_"); } }
public DNGSequenceSource(string[] thePaths) { /* * char[] bayerSubstitution = { "\x0"[0], "\x1"[0], "\x2"[0] }; * * string bayerPatternTag = bayerSubstitution[bayerPattern[0, 0]].ToString() + * bayerSubstitution[bayerPattern[0, 1]] + bayerSubstitution[bayerPattern[1, 0]] + * bayerSubstitution[bayerPattern[1, 1]]; */ paths = thePaths; using (Tiff input = Tiff.Open(thePaths[0], "r")) { float baselineExposure = input.GetField(TiffTag.BASELINEEXPOSURE) == null ? 0 : input.GetField(TiffTag.BASELINEEXPOSURE)[0].ToFloat(); // Try to make Adobe DNG work bool subIFDTagExists = input.GetField(TIFFTAG_SUBIFDS) != null; if (subIFDTagExists) { UInt64 offsetOfSubIFD = (UInt64)input.GetField(TIFFTAG_SUBIFDS)[1].TolongArray()[0]; input.SetSubDirectory((long)offsetOfSubIFD); } width = input.GetField(TiffTag.IMAGEWIDTH)[0].ToInt(); height = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt(); ushort? whiteLevel = null; FieldValue[] whiteLevelInfo = input.GetField(TiffTag.WHITELEVEL); if (whiteLevelInfo?.Length > 0) { whiteLevel = whiteLevelInfo[0].ToUShortArray()[0]; } // For debugging int[] tagList = new int[input.GetTagListCount()]; for (int i = 0; i < tagList.Length; i++) { tagList[i] = input.GetTagListEntry(i); } byte[] bayerTiffBytes = input.GetField(TIFFTAG_CFAPATTERN)[0].ToByteArray(); // We can probably get away with not doing any substitution because we follow the same logic for the bayer pattern values, with 0=red, 1=green, 2=blue bayerPattern = new byte[2, 2] { { bayerTiffBytes[0], bayerTiffBytes[1] }, { bayerTiffBytes[2], bayerTiffBytes[3] } }; int bitDepth = input.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt(); if (bitDepth == 12) { rawDataFormat = RAWDATAFORMAT.TIFF12BITPACKED; } else if (bitDepth == 16 && ((int)Math.Round(baselineExposure) == 4 || whiteLevel == 4095)) // White level 4095 is what you get when Adobe DNG converter compresses a 12 bit packed file. It's still a dark capsuled 12 in 16 bit really. { rawDataFormat = RAWDATAFORMAT.BAYER12BITDARKCAPSULEDIN16BIT; } else if (bitDepth == 16 && (int)Math.Round(baselineExposure) == 0) { rawDataFormat = RAWDATAFORMAT.BAYER12BITBRIGHTCAPSULEDIN16BIT; } } }