public void ComponentScalingIsCorrect_1ChannelJpegGolang() { using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(TestImages.Jpeg.Baseline.Jpeg400)) { 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); GolangComponent c0 = decoder.Components[0]; VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); } }
public void PrintComponentDataGolang(string imageFile) { var sb = new StringBuilder(); using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(imageFile)) { sb.AppendLine(imageFile); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); GolangComponent c0 = decoder.Components[0]; GolangComponent c1 = decoder.Components[1]; sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); } this.Output.WriteLine(sb.ToString()); }
public static ComponentData Load(GolangComponent 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_MultiChannelJpegGolang( string imageFile, int componentCount, object expectedLumaFactors, object expectedChromaFactors) { var fLuma = (Size)expectedLumaFactors; var fChroma = (Size)expectedChromaFactors; using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(imageFile)) { Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.Components.Length); GolangComponent c0 = decoder.Components[0]; GolangComponent c1 = decoder.Components[1]; GolangComponent 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) { GolangComponent 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> /// <param name="metadataOnly">Whether to decode metadata only.</param> private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) { 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] != SupportedPrecision) { 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"); } if (!metadataOnly) { this.Components = new GolangComponent[this.ComponentCount]; for (int i = 0; i < this.ComponentCount; i++) { byte componentIdentifier = this.Temp[6 + (3 * i)]; var component = new GolangComponent(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); this.ColorSpace = this.DeduceJpegColorSpace(); foreach (GolangComponent component in this.Components) { component.InitializeDerivedData(this.configuration.MemoryManager, this); } } }