Skip to content

Commit 3f1fe69

Browse files
committed
Fixing declarations
1 parent f7b4f49 commit 3f1fe69

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
5656
VerticalResolution = this.header.Height,
5757
ResolutionUnits = PixelResolutionUnit.AspectRatio
5858
};
59+
QoiMetadata qoiMetadata = metadata.GetQoiMetadata();
60+
qoiMetadata.Channels = this.header.Channels;
61+
qoiMetadata.ColorSpace = this.header.ColorSpace;
5962
Image<TPixel> image = new(this.configuration, (int)this.header.Width, (int)this.header.Height, metadata);
6063
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
6164

@@ -112,8 +115,8 @@ private void ProcessHeader(BufferedReadStream stream)
112115
}
113116

114117
// These numbers are in Big Endian so we have to reverse them to get the real number
115-
uint width = BinaryPrimitives.ReadUInt32BigEndian(widthBytes),
116-
height = BinaryPrimitives.ReadUInt32BigEndian(heightBytes);
118+
uint width = BinaryPrimitives.ReadUInt32BigEndian(widthBytes);
119+
uint height = BinaryPrimitives.ReadUInt32BigEndian(heightBytes);
117120
if (width == 0 || height == 0)
118121
{
119122
throw new InvalidImageContentException(
@@ -126,8 +129,6 @@ private void ProcessHeader(BufferedReadStream stream)
126129
ThrowInvalidImageContentException();
127130
}
128131

129-
PixelTypeInfo pixelType = new(8 * channels);
130-
131132
int colorSpace = stream.ReadByte();
132133
if (colorSpace is -1 or (not 0 and not 1))
133134
{
@@ -201,9 +202,9 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
201202

202203
// Get one pixel from the difference (-2..1) of the previous pixel
203204
case QoiChunk.QoiOpDiff:
204-
byte redDifference = (byte)((operationByte & 0b00110000) >> 4),
205-
greenDifference = (byte)((operationByte & 0b00001100) >> 2),
206-
blueDifference = (byte)(operationByte & 0b00000011);
205+
byte redDifference = (byte)((operationByte & 0b00110000) >> 4);
206+
byte greenDifference = (byte)((operationByte & 0b00001100) >> 2);
207+
byte blueDifference = (byte)(operationByte & 0b00000011);
207208
readPixel = previousPixel with
208209
{
209210
R = (byte)Numerics.Modulo256(previousPixel.R + (redDifference - 2)),
@@ -218,13 +219,13 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
218219
// Get green difference in 6 bits and red and blue differences
219220
// depending on the green one
220221
case QoiChunk.QoiOpLuma:
221-
byte diffGreen = (byte)(operationByte & 0b00111111),
222-
currentGreen = (byte)Numerics.Modulo256(previousPixel.G + (diffGreen - 32)),
223-
nextByte = (byte)stream.ReadByte(),
224-
diffRedDG = (byte)(nextByte >> 4),
225-
diffBlueDG = (byte)(nextByte & 0b00001111),
226-
currentRed = (byte)Numerics.Modulo256(diffRedDG - 8 + (diffGreen - 32) + previousPixel.R),
227-
currentBlue = (byte)Numerics.Modulo256(diffBlueDG - 8 + (diffGreen - 32) + previousPixel.B);
222+
byte diffGreen = (byte)(operationByte & 0b00111111);
223+
byte currentGreen = (byte)Numerics.Modulo256(previousPixel.G + (diffGreen - 32));
224+
byte nextByte = (byte)stream.ReadByte();
225+
byte diffRedDG = (byte)(nextByte >> 4);
226+
byte diffBlueDG = (byte)(nextByte & 0b00001111);
227+
byte currentRed = (byte)Numerics.Modulo256(diffRedDG - 8 + (diffGreen - 32) + previousPixel.R);
228+
byte currentBlue = (byte)Numerics.Modulo256(diffBlueDG - 8 + (diffGreen - 32) + previousPixel.B);
228229
readPixel = previousPixel with { R = currentRed, B = currentBlue, G = currentGreen };
229230
pixel.FromRgba32(readPixel);
230231
pixelArrayPosition = GetArrayPosition(readPixel);

src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ private void WritePixels<TPixel>(Image<TPixel> image, Stream stream)
141141
// Since it wasn't found on the previously seen pixels, we save it
142142
previouslySeenPixels[pixelArrayPosition] = currentRgba32;
143143

144-
sbyte diffRed = (sbyte)(currentRgba32.R - previousPixel.R),
145-
diffGreen = (sbyte)(currentRgba32.G - previousPixel.G),
146-
diffBlue = (sbyte)(currentRgba32.B - previousPixel.B);
144+
sbyte diffRed = (sbyte)(currentRgba32.R - previousPixel.R);
145+
sbyte diffGreen = (sbyte)(currentRgba32.G - previousPixel.G);
146+
sbyte diffBlue = (sbyte)(currentRgba32.B - previousPixel.B);
147147

148148
// If so, we do a QOI_OP_DIFF
149149
if (diffRed is >= -2 and <= 1 &&
@@ -152,27 +152,27 @@ private void WritePixels<TPixel>(Image<TPixel> image, Stream stream)
152152
currentRgba32.A == previousPixel.A)
153153
{
154154
// Bottom limit is -2, so we add 2 to make it equal to 0
155-
byte dr = (byte)(diffRed + 2),
156-
dg = (byte)(diffGreen + 2),
157-
db = (byte)(diffBlue + 2),
158-
valueToWrite = (byte)((byte)QoiChunk.QoiOpDiff | (dr << 4) | (dg << 2) | db);
155+
byte dr = (byte)(diffRed + 2);
156+
byte dg = (byte)(diffGreen + 2);
157+
byte db = (byte)(diffBlue + 2);
158+
byte valueToWrite = (byte)((byte)QoiChunk.QoiOpDiff | (dr << 4) | (dg << 2) | db);
159159
stream.WriteByte(valueToWrite);
160160
}
161161
else
162162
{
163163
// else, we check if the green difference is less than -32..31 and the rest -8..7
164164
// If so, we do a QOI_OP_LUMA
165-
sbyte diffRedGreen = (sbyte)(diffRed - diffGreen),
166-
diffBlueGreen = (sbyte)(diffBlue - diffGreen);
165+
sbyte diffRedGreen = (sbyte)(diffRed - diffGreen);
166+
sbyte diffBlueGreen = (sbyte)(diffBlue - diffGreen);
167167
if (diffGreen is >= -32 and <= 31 &&
168168
diffRedGreen is >= -8 and <= 7 &&
169169
diffBlueGreen is >= -8 and <= 7 &&
170170
currentRgba32.A == previousPixel.A)
171171
{
172-
byte dr_dg = (byte)(diffRedGreen + 8),
173-
db_dg = (byte)(diffBlueGreen + 8),
174-
byteToWrite1 = (byte)((byte)QoiChunk.QoiOpLuma | (diffGreen + 32)),
175-
byteToWrite2 = (byte)((dr_dg << 4) | db_dg);
172+
byte dr_dg = (byte)(diffRedGreen + 8);
173+
byte db_dg = (byte)(diffBlueGreen + 8);
174+
byte byteToWrite1 = (byte)((byte)QoiChunk.QoiOpLuma | (diffGreen + 32));
175+
byte byteToWrite2 = (byte)((dr_dg << 4) | db_dg);
176176
stream.WriteByte(byteToWrite1);
177177
stream.WriteByte(byteToWrite2);
178178
}

0 commit comments

Comments
 (0)