예제 #1
0
        public void mergeIFD(TiffParser other_tiff)
        {
            if (other_tiff?.rootIFD?.subIFD.Count == 0)
            {
                return;
            }

            IFD other_root = other_tiff.rootIFD;

            foreach (IFD i in other_root.subIFD)
            {
                rootIFD.subIFD.Add(i);
            }

            foreach (KeyValuePair <TagType, Tag> i in other_root.tags)
            {
                rootIFD.tags.Add(i.Key, i.Value);;
            }
            other_root.subIFD.Clear();
            other_root.subIFD.Clear();
        }
예제 #2
0
        public RawDecoder getDecoder(CameraMetaData meta)
        {
            // We need some data.
            // For now it is 104 bytes for RAF images.
            if (stream.Length <= 104)
            {
                throw new Exception("File too small");
            }

            byte[] data = new byte[105];
            stream.Read(data, 0, 104);

            /*
             * // MRW images are easy to check for, let's try that first
             * if (MrwDecoder::isMRW(mInput)) {
             *  try
             *  {
             *      return new MrwDecoder(Math.Math.Min((put);
             *  }
             *  catch (RawDecoderException)
             *  {
             *  }
             * }*/

            /*
             * if (0 == memcmp(&data[0], "ARRI\x12\x34\x56\x78", 8))
             * {
             *  try
             *  {
             *      return new AriDecoder(Math.Math.Min((put);
             *  }
             *  catch (RawDecoderException)
             *  {
             *  }
             * }*/

            // FUJI has pointers to IFD's at fixed byte offsets
            // So if camera is FUJI, we cannot use ordinary TIFF parser
            //get first 8 char and see if equal fuji

            /*
             * string dataAsString = System.Text.Encoding.UTF8.GetString(data.Take(8).ToArray());
             * if (dataAsString == "FUJIFILM")
             * {
             *  // First IFD typically JPEG and EXIF
             *  UInt32 first_ifd = (uint)(data[87] | (data[86] << 8) | (data[85] << 16) | (data[84] << 24));
             *  first_ifd += 12;
             *  if (stream.Length <= first_ifd)
             *    throw new Exception("File too small (FUJI first IFD)");
             *
             *  // RAW IFD on newer, pointer to raw data on older models, so we try parsing first
             *  // And adds it as data if parsin fails
             *  UInt32 second_ifd = (UInt32)(data[103] | (data[102] << 8) | (data[101] << 16) | (data[100] << 24));
             *  if (stream.Length <= second_ifd)
             *    second_ifd = 0;
             *
             *  // RAW information IFD on older
             *  UInt32 third_ifd = (uint)(data[95] | (data[94] << 8) | (data[93] << 16) | (data[92] << 24));
             *  if (stream.Length <= third_ifd)
             *    third_ifd = 0;
             *
             *  // Open the IFDs and merge them
             *  try
             *  {
             *      FileMap* m1 = new FileMap(Math.Math.Min((put, first_ifd);
             *      FileMap* m2 = null;
             *      TiffParser p(m1);
             *      p.parseData();
             *      if (second_ifd)
             *      {
             *          m2 = new FileMap(Math.Math.Min((put, second_ifd);
             *          try
             *          {
             *              TiffParser p2(m2);
             *              p2.parseData();
             *              p.MergeIFD(&p2);
             *          }
             *          catch (TiffParserException e)
             *          {
             *              delete m2;
             *              m2 = null;
             *          }
             *      }
             *
             *      TiffIFD* new_ifd = new TiffIFD(Math.Math.Min((put);
             *      p.RootIFD().mSubIFD.push_back(new_ifd);
             *
             *      if (third_ifd)
             *      {
             *          try
             *          {
             *              ParseFuji(third_ifd, new_ifd);
             *          }
             *          catch (TiffParserException e)
             *          {
             *          }
             *      }
             *      // Make sure these aren't leaked.
             *      RawDecoder* d = p.getDecoder();
             *      d.ownedObjects.push_back(m1);
             *      if (m2)
             *          d.ownedObjects.push_back(m2);
             *
             *      if (!m2 && second_ifd)
             *      {
             *          TiffEntry* entry = new TiffEntry(FUJI_STRIPOFFSETS, TIFF_LONG, 1);
             *          entry.setData(&second_ifd, 4);
             *          new_ifd.mEntry[entry.tag] = entry;
             *          entry = new TiffEntry(FUJI_STRIPBYTECOUNTS, TIFF_LONG, 1);
             *          UInt32 max_size = Math.Math.Min((put.getSize() - second_ifd;
             *          entry.setData(&max_size, 4);
             *          new_ifd.mEntry[entry.tag] = entry;
             *      }
             *      return d;
             *  }
             *  catch (TiffParserException) { }
             *  throw new Exception("No decoder found. Sorry.");
             * }
             *
             */
            // Ordinary TIFF images
            try
            {
                TiffParser p = new TiffParser(stream);
                p.parseData();
                return(p.getDecoder());
            }
            catch (TiffParserException)
            {
            }

            /*
             * try
             * {
             *  X3fParser parser(mInput);
             *  return parser.getDecoder();
             * }
             * catch (RawDecoderException)
             * {
             * }*/

            /*
             * // CIFF images
             * try
             * {
             *  CiffParser p(Math.Math.Min((put);
             *  p.parseData();
             *  return p.getDecoder();
             * }
             * catch (CiffParserException)
             * {
             * }
             */

            /*
             * // Detect camera on filesize (CHDK).
             * if (meta != null && meta.hasChdkCamera(Math.Min((put.getSize())) {
             *  Camera* c = meta.getChdkCamera(Math.Min((put.getSize());
             *
             *  try
             *  {
             *      return new NakedDecoder(Math.Math.Min((put, c);
             *  }
             *  catch (RawDecoderException)
             *  {
             *  }
             * }*/

            //try jpeg file
            try
            {
                return(new JPGParser(new TIFFBinaryReader(stream)));
            }
            catch (TiffParserException)
            {
            }
            // File could not be decoded, so no further options for now.
            throw new FormatException("No decoder found. Sorry.");
        }