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