Browse Source

Update ByteExtensions.cs

Original implementation didn't work for bit-length of 4

Former-commit-id: bc96d70df88c933fc10b815a9b08327bbdae5461
Former-commit-id: 2678a00b2afc86526cffd3bb68d6bb5be1652a92
Former-commit-id: d64de4730e2465cb9e89c1d7c673ca86d2893523
pull/1/head
Vladislav Richter 10 years ago
parent
commit
cc126254fd
  1. 5
      src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs

5
src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs

@ -32,7 +32,8 @@ namespace ImageProcessorCore
{
result = new byte[bytes.Length * 8 / bits];
int factor = (int)Math.Pow(2, bits) - 1;
// BUGFIX I dont think it should be there, but I am not sure if it breaks something else
//int factor = (int)Math.Pow(2, bits) - 1;
int mask = 0xFF >> (8 - bits);
int resultOffset = 0;
@ -40,7 +41,7 @@ namespace ImageProcessorCore
{
for (int shift = 0; shift < 8; shift += bits)
{
int colorIndex = ((b >> (8 - bits - shift)) & mask) * (255 / factor);
int colorIndex = ((b >> (8 - bits - shift)) & mask); // * (255 / factor);
result[resultOffset] = (byte)colorIndex;

Loading…
Cancel
Save