-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
9,602 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace PNGNet | ||
{ | ||
public class ByteStreamReader : Stream | ||
{ | ||
private byte[] _data; | ||
private long _position; | ||
|
||
public ByteStreamReader(byte[] data) | ||
{ | ||
_data = data; | ||
_position = 0; | ||
} | ||
|
||
public override bool CanRead | ||
{ | ||
get { return true; } | ||
} | ||
|
||
public override bool CanSeek | ||
{ | ||
get { return true; } | ||
} | ||
|
||
public override bool CanWrite | ||
{ | ||
get { return false; } | ||
} | ||
|
||
public override void Flush() | ||
{ | ||
// don't need to flush | ||
} | ||
|
||
public override long Length | ||
{ | ||
get { return _data.LongLength; } | ||
} | ||
|
||
public override long Position | ||
{ | ||
get { return _position; } | ||
set { _position = value; } | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
long length = (_position + count > _data.Length) ? _data.Length - _position - 1 : count; | ||
|
||
if (_position >= _data.Length) | ||
return 0; | ||
|
||
for (long i = 0; i < length; i++, _position++) | ||
buffer[offset + i] = _data[_position]; | ||
|
||
return (int)length; | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
switch (origin) | ||
{ | ||
case SeekOrigin.Begin: | ||
_position = offset; | ||
break; | ||
|
||
case SeekOrigin.Current: | ||
_position += offset; | ||
break; | ||
|
||
case SeekOrigin.End: | ||
_position = _data.Length - 1 + offset; | ||
break; | ||
|
||
default: | ||
throw new ArgumentException(); | ||
} | ||
|
||
return _position; | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* PNG.Net | ||
* | ||
* Copyright (C) 2008 wj32 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace PNGNet | ||
{ | ||
/// <summary> | ||
/// Provides functions to calculate CRC32 hashes of data. | ||
/// </summary> | ||
public static class CRC32 | ||
{ | ||
private const uint Polynomial = 0xedb88320; | ||
private static uint[] Table; | ||
|
||
/// <summary> | ||
/// Initializes the CRC32 table. | ||
/// </summary> | ||
public static void Initialize() | ||
{ | ||
uint h = 1; | ||
|
||
Table = new uint[256]; | ||
Table[0] = 0; | ||
|
||
for (int i = 128; i != 0; i >>= 1) | ||
{ | ||
h = (h >> 1) ^ (((h & 1) != 0) ? Polynomial : 0); | ||
|
||
for (int j = 0; j < 256; j += 2 * i) | ||
Table[i + j] = Table[j] ^ h; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Performs CRC32 on a sequence of bytes. Initializes the table if not already intialized. | ||
/// </summary> | ||
/// <param name="crc32">Specify the value of the previous hash, or specify 0.</param> | ||
/// <param name="data">The data to be hashed.</param> | ||
/// <returns></returns> | ||
public static uint Hash(uint crc32, byte[] data, int offset, int length) | ||
{ | ||
if (Table == null) | ||
Initialize(); | ||
|
||
crc32 ^= 0xffffffff; | ||
|
||
for (int i = offset; i < offset + length; i++) | ||
crc32 = (crc32 >> 8) ^ Table[(crc32 ^ data[i]) & 0xff]; | ||
|
||
return crc32 ^ 0xffffffff; | ||
} | ||
} | ||
} |
Oops, something went wrong.