public void PrintComponentData(string imageFile) { StringBuilder bld = new StringBuilder(); using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) { bld.AppendLine(imageFile); bld.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); OrigComponent c0 = decoder.Components[0]; OrigComponent c1 = decoder.Components[1]; bld.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); bld.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); } this.Output.WriteLine(bld.ToString()); }
public void ComponentScalingIsCorrect_1ChannelJpeg() { using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(TestImages.Jpeg.Baseline.Jpeg400, true)) { Assert.Equal(1, decoder.ComponentCount); Assert.Equal(1, decoder.Components.Length); Size expectedSizeInBlocks = decoder.ImageSizeInPixels.DivideRoundUp(8); Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); var uniform1 = new Size(1, 1); OrigComponent c0 = decoder.Components[0]; VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); } }
public static ComponentData Load(OrigComponent c) { var result = new ComponentData( c.SizeInBlocks.Width, c.SizeInBlocks.Height, c.Index ); for (int y = 0; y < result.HeightInBlocks; y++) { for (int x = 0; x < result.WidthInBlocks; x++) { short[] data = c.GetBlockReference(x, y).ToArray(); result.MakeBlock(data, y, x); } } return(result); }
public void ComponentScalingIsCorrect_MultiChannelJpeg( string imageFile, int componentCount, object expectedLumaFactors, object expectedChromaFactors) { Size fLuma = (Size)expectedLumaFactors; Size fChroma = (Size)expectedChromaFactors; using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) { Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.Components.Length); OrigComponent c0 = decoder.Components[0]; OrigComponent c1 = decoder.Components[1]; OrigComponent c2 = decoder.Components[2]; var uniform1 = new Size(1, 1); Size expectedLumaSizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(fLuma); Size divisor = fLuma.DivideBy(fChroma); Size expectedChromaSizeInBlocks = expectedLumaSizeInBlocks.DivideRoundUp(divisor); VerifyJpeg.VerifyComponent(c0, expectedLumaSizeInBlocks, fLuma, uniform1); VerifyJpeg.VerifyComponent(c1, expectedChromaSizeInBlocks, fChroma, divisor); VerifyJpeg.VerifyComponent(c2, expectedChromaSizeInBlocks, fChroma, divisor); if (componentCount == 4) { OrigComponent c3 = decoder.Components[2]; VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1); } } }
/// <summary> /// Processes the Start of Frame marker. Specified in section B.2.2. /// </summary> /// <param name="remaining">The remaining bytes in the segment block.</param> private void ProcessStartOfFrameMarker(int remaining) { if (this.ComponentCount != 0) { throw new ImageFormatException("Multiple SOF markers"); } switch (remaining) { case 6 + (3 * 1): // Grayscale image. this.ComponentCount = 1; break; case 6 + (3 * 3): // YCbCr or RGB image. this.ComponentCount = 3; break; case 6 + (3 * 4): // YCbCrK or CMYK image. this.ComponentCount = 4; break; default: throw new ImageFormatException("Incorrect number of components"); } this.InputProcessor.ReadFull(this.Temp, 0, remaining); // We only support 8-bit precision. if (this.Temp[0] != 8) { throw new ImageFormatException("Only 8-Bit precision supported."); } int height = (this.Temp[1] << 8) + this.Temp[2]; int width = (this.Temp[3] << 8) + this.Temp[4]; this.ImageSizeInPixels = new Size(width, height); if (this.Temp[5] != this.ComponentCount) { throw new ImageFormatException("SOF has wrong length"); } this.Components = new OrigComponent[this.ComponentCount]; for (int i = 0; i < this.ComponentCount; i++) { byte componentIdentifier = this.Temp[6 + (3 * i)]; var component = new OrigComponent(componentIdentifier, i); component.InitializeCoreData(this); this.Components[i] = component; } int h0 = this.Components[0].HorizontalSamplingFactor; int v0 = this.Components[0].VerticalSamplingFactor; this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0); foreach (OrigComponent component in this.Components) { component.InitializeDerivedData(this); } this.ColorSpace = this.DeduceJpegColorSpace(); }