public Image <Rgba32> TryCreateRGBSpectralImage() { if (this.ComponentCount != 3) { return(null); } LibJpegTools.ComponentData c0 = this.Components[0]; LibJpegTools.ComponentData c1 = this.Components[1]; LibJpegTools.ComponentData c2 = this.Components[2]; if (c0.Size != c1.Size || c1.Size != c2.Size) { return(null); } var result = new Image <Rgba32>(c0.WidthInBlocks * 8, c0.HeightInBlocks * 8); for (int by = 0; by < c0.HeightInBlocks; by++) { for (int bx = 0; bx < c0.WidthInBlocks; bx++) { this.WriteToImage(bx, by, result); } } return(result); }
internal void WriteToImage(int bx, int by, Image <Rgba32> image) { LibJpegTools.ComponentData c0 = this.Components[0]; LibJpegTools.ComponentData c1 = this.Components[1]; LibJpegTools.ComponentData c2 = this.Components[2]; Block8x8 block0 = c0.SpectralBlocks[bx, by]; Block8x8 block1 = c1.SpectralBlocks[bx, by]; Block8x8 block2 = c2.SpectralBlocks[bx, by]; float d0 = c0.MaxVal - c0.MinVal; float d1 = c1.MaxVal - c1.MinVal; float d2 = c2.MaxVal - c2.MinVal; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { float val0 = c0.GetBlockValue(block0, x, y); float val1 = c0.GetBlockValue(block1, x, y); float val2 = c0.GetBlockValue(block2, x, y); var v = new Vector4(val0, val1, val2, 1); Rgba32 color = default; color.FromVector4(v); int yy = (by * 8) + y; int xx = (bx * 8) + x; image[xx, yy] = color; } } }
public bool Equals(SpectralData other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (this.ComponentCount != other.ComponentCount) { return(false); } for (int i = 0; i < this.ComponentCount; i++) { LibJpegTools.ComponentData a = this.Components[i]; LibJpegTools.ComponentData b = other.Components[i]; if (!a.Equals(b)) { return(false); } } return(true); }