|
|
@ -72,13 +72,7 @@ internal sealed partial class IccDataReader |
|
|
/// <returns>The read CLUT8.</returns>
|
|
|
/// <returns>The read CLUT8.</returns>
|
|
|
public IccClut ReadClut8(int inChannelCount, int outChannelCount, byte[] gridPointCount) |
|
|
public IccClut ReadClut8(int inChannelCount, int outChannelCount, byte[] gridPointCount) |
|
|
{ |
|
|
{ |
|
|
int length = 0; |
|
|
int length = this.GetClutLength(inChannelCount, outChannelCount, gridPointCount, 1); |
|
|
for (int i = 0; i < inChannelCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
length += (int)Math.Pow(gridPointCount[i], inChannelCount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
length /= inChannelCount; |
|
|
|
|
|
|
|
|
|
|
|
const float Max = byte.MaxValue; |
|
|
const float Max = byte.MaxValue; |
|
|
|
|
|
|
|
|
@ -105,13 +99,7 @@ internal sealed partial class IccDataReader |
|
|
public IccClut ReadClut16(int inChannelCount, int outChannelCount, byte[] gridPointCount) |
|
|
public IccClut ReadClut16(int inChannelCount, int outChannelCount, byte[] gridPointCount) |
|
|
{ |
|
|
{ |
|
|
int start = this.currentIndex; |
|
|
int start = this.currentIndex; |
|
|
int length = 0; |
|
|
int length = this.GetClutLength(inChannelCount, outChannelCount, gridPointCount, 2); |
|
|
for (int i = 0; i < inChannelCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
length += (int)Math.Pow(gridPointCount[i], inChannelCount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
length /= inChannelCount; |
|
|
|
|
|
|
|
|
|
|
|
const float Max = ushort.MaxValue; |
|
|
const float Max = ushort.MaxValue; |
|
|
|
|
|
|
|
|
@ -139,13 +127,7 @@ internal sealed partial class IccDataReader |
|
|
public IccClut ReadClutF32(int inChCount, int outChCount, byte[] gridPointCount) |
|
|
public IccClut ReadClutF32(int inChCount, int outChCount, byte[] gridPointCount) |
|
|
{ |
|
|
{ |
|
|
int start = this.currentIndex; |
|
|
int start = this.currentIndex; |
|
|
int length = 0; |
|
|
int length = this.GetClutLength(inChCount, outChCount, gridPointCount, 4); |
|
|
for (int i = 0; i < inChCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
length += (int)Math.Pow(gridPointCount[i], inChCount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
length /= inChCount; |
|
|
|
|
|
|
|
|
|
|
|
float[] values = new float[length * outChCount]; |
|
|
float[] values = new float[length * outChCount]; |
|
|
int offset = 0; |
|
|
int offset = 0; |
|
|
@ -160,4 +142,28 @@ internal sealed partial class IccDataReader |
|
|
this.currentIndex = start + (length * outChCount * 4); |
|
|
this.currentIndex = start + (length * outChCount * 4); |
|
|
return new IccClut(values, gridPointCount, IccClutDataType.Float, outChCount); |
|
|
return new IccClut(values, gridPointCount, IccClutDataType.Float, outChCount); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int GetClutLength(int inputChannelCount, int outputChannelCount, byte[] gridPointCount, int bytesPerValue) |
|
|
|
|
|
{ |
|
|
|
|
|
int length = 1; |
|
|
|
|
|
for (int i = 0; i < inputChannelCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
int gridPoints = gridPointCount[i]; |
|
|
|
|
|
if (gridPoints == 0 || length > int.MaxValue / gridPoints) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidIccProfileException("Invalid CLUT dimensions."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
length *= gridPoints; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long valueCount = (long)length * outputChannelCount; |
|
|
|
|
|
long byteCount = valueCount * bytesPerValue; |
|
|
|
|
|
if (valueCount > int.MaxValue || byteCount > this.data.Length - this.currentIndex) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidIccProfileException("The CLUT data is shorter than its declared dimensions."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return length; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|