Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ExifReader.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
10 public class ExifReader
11 {
12 private readonly byte[] data;
13 private readonly int len;
14 private int pos;
15 private bool bigEndian = true;
16
20 public int Position
21 {
22 get => this.pos;
23 set
24 {
25 if (value < 0 || value >= this.len)
26 throw new ArgumentOutOfRangeException(nameof(Position), "Position out of range.");
27
28 this.pos = value;
29 }
30 }
31
35 public bool BigEndian
36 {
37 get => this.bigEndian;
38 set => this.bigEndian = value;
39 }
40
44 public int Length => this.len;
45
49 public bool EoF => this.pos >= this.len;
50
55 public ExifReader(byte[] Data)
56 {
57 this.data = Data;
58 this.len = Data.Length;
59 this.pos = 0;
60 }
61
66 public int NextByte()
67 {
68 if (this.pos < this.len)
69 return this.data[this.pos++];
70 else
71 return -1;
72 }
73
78 public int NextSHORT()
79 {
80 int i = this.NextByte();
81 if (i < 0)
82 return -1;
83
84 int j = this.NextByte();
85 if (j < 0)
86 return -1;
87
88 if (this.bigEndian)
89 {
90 i <<= 8;
91 i |= j;
92
93 return i;
94 }
95 else
96 {
97 j <<= 8;
98 j |= i;
99
100 return j;
101 }
102 }
103
108 public uint? NextLONG()
109 {
110 int i = this.NextSHORT();
111 if (i < 0)
112 return null;
113
114 int j = this.NextSHORT();
115 if (j < 0)
116 return null;
117
118 if (this.bigEndian)
119 {
120 i <<= 16;
121 i |= (ushort)j;
122
123 return (uint)i;
124 }
125 else
126 {
127 j <<= 16;
128 j |= (ushort)i;
129
130 return (uint)j;
131 }
132 }
133
138 public string NextASCIIString()
139 {
140 int Start = this.pos;
141 while (this.pos < this.len && this.data[this.pos] != 0)
142 this.pos++;
143
144 string Result = Encoding.ASCII.GetString(this.data, Start, this.pos - Start);
145 this.pos++;
146
147 return Result;
148 }
149 }
150}
uint? NextLONG()
Gets next LONG (unsigned int). If no more bytes are available, null is returned.
Definition: ExifReader.cs:108
string NextASCIIString()
Gets the next ASCII string.
Definition: ExifReader.cs:138
int NextByte()
Gets next byte. If no more bytes are available, -1 is returned.
Definition: ExifReader.cs:66
bool BigEndian
If Big-Endian encoding is used.
Definition: ExifReader.cs:36
int Length
Length of data block
Definition: ExifReader.cs:44
ExifReader(byte[] Data)
EXIF reader
Definition: ExifReader.cs:55
int NextSHORT()
Gets next SHORT (unsigned short). If no more bytes are available, -1 is returned.
Definition: ExifReader.cs:78