Beispiel #1
0
 private bool IsJPEG(SectionData sectionData)
 {
     byte[] jpeg = { 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46 };
     for (int i = 0; i < jpeg.Length; i++)
     {
         if (sectionData.Data[i] != jpeg[i])
         {
             return false;
         }
     }
     return true;
 }
Beispiel #2
0
 internal Section(LytroFile file, SectionData sectionData)
 {
     this.LytroFile = file;
     this.sectionData = sectionData;
 }
Beispiel #3
0
        private string FindName(SectionData sectionData)
        {
            // Find the sha1 in the table of contents
            int quotecount = 0;
            int sha1Ix = this.TableOfContents.Content.IndexOf(sectionData.SHA1);
            if (sha1Ix > -1)
            {
                // Move backwards to the corresponding name
                while (quotecount < 3 && (sha1Ix-- > 0))
                {
                    if (this.TableOfContents.Content[sha1Ix] == '"')
                    {
                        quotecount++;
                    }
                }

                // Read the name if we can
                if (quotecount == 3)
                {
                    int afterFirstQuote = sha1Ix + 1;
                    return this.TableOfContents.Content.Substring(
                        afterFirstQuote,
                        this.TableOfContents.Content.IndexOf('"', afterFirstQuote) - afterFirstQuote
                    );
                }
            }

            return "unknown";
        }
Beispiel #4
0
        private Section IdentifySection(SectionData sectionData)
        {
            // Try to figure out if the data represents an image, text, raw data, etc
            Section section;

            if (sectionData.Data.Length == 1600)
            {
                // Hard coded to assume that the 20x20 LUT is 1600 bytes
                section = new LookUpTableSection(this, sectionData);
                this.LookUpTable = (LookUpTableSection)section;
            }
            else if (IsJPEG(sectionData))
            {
                // Check for the magic bytes to see if its a jpg
                section = new JpegSection(this, sectionData);
                this.JpegSections.Add((JpegSection)section);
            }
            else
            {
                string name = FindName(sectionData);

                if (name == "imageRef")
                {
                    // Assume a raw image
                    section = new RawImageSection(this, sectionData);
                    this.RawImageSections.Add((RawImageSection)section);
                }
                else
                {
                    // Assume anything that isn't called imageRef is plain text
                    section = new TextSection(this, sectionData);
                    this.TextSections.Add((TextSection)section);
                }

                section.Name = name;
            }

            return section;
        }
Beispiel #5
0
 private SectionData ParseSectionData(BinaryReader br)
 {
     SectionData sectionData = new SectionData();
     FillSectionData(br, sectionData);
     return sectionData;
 }
Beispiel #6
0
        private void FillSectionData(BinaryReader br, SectionData sectionData)
        {
            br.ReadBytes(MAGIC_LENGTH);

            // the length is stored as a big endian unsigned 32 bit int
            uint ulen = br.ReadUInt32();
            int len = (int)SwapInt(ulen);

            // copy SHA1
            sectionData.SHA1 = Encoding.ASCII.GetString(br.ReadBytes(SHA1_LENGTH));

            // move past the 35 byte empty space
            br.ReadBytes(BLANK_LENGTH);

            // Copy the data
            sectionData.Data = br.ReadBytes(len);

            // There may be some null region between sections
            while (br.PeekChar() == '\0') br.ReadByte();
        }
Beispiel #7
0
 private void ParseTableOfContents(BinaryReader br)
 {
     SectionData sectionData = new SectionData();
     FillSectionData(br, sectionData);
     this.TableOfContents = new TableOfContentsSection(this, sectionData);
 }