Release 1.1.3: reveal faint nebula structure with human-readable preview modes
All checks were successful
Release AstroFrame / packages (push) Successful in 1m6s
All checks were successful
Release AstroFrame / packages (push) Successful in 1m6s
This commit is contained in:
parent
5ad7a6a79e
commit
d3362c8341
15 changed files with 300 additions and 24 deletions
43
tests/AstroFrame.Validation/ColorPreviewRegression.cs
Normal file
43
tests/AstroFrame.Validation/ColorPreviewRegression.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using AstroFrame.Engine;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
static class ColorPreviewRegression
|
||||
{
|
||||
public static void Run(Action<bool,string> check)
|
||||
{
|
||||
string directory=Path.Combine(Path.GetTempPath(),"AstroFrame-color-"+Guid.NewGuid());Directory.CreateDirectory(directory);
|
||||
try
|
||||
{
|
||||
const int size=128;ColorPreviewPlane? last=null;Frame? frame=null;
|
||||
foreach(string pattern in new[]{"RGGB","GRBG","GBRG","BGGR"})foreach(var offset in new[]{(X:0,Y:0),(X:1,Y:0),(X:0,Y:1),(X:1,Y:1)})
|
||||
{
|
||||
float[] pixels=new float[size*size];for(int y=0;y<size;y++)for(int x=0;x<size;x++)pixels[y*size+x]=pattern[((y+offset.Y)%2)*2+(x+offset.X)%2] switch{'R'=>600,'G'=>1000,_=>1400};
|
||||
string path=Path.Combine(directory,$"{pattern}-{offset.X}-{offset.Y}.fit");ImageRegression.WriteFits(path,pixels,size,size,0,pattern,offset.X,offset.Y);
|
||||
var color=ColorPreview.ReadFits(path)!;bool correct=color.Red.All(v=>v==600)&&color.Green.All(v=>v==1000)&&color.Blue.All(v=>v==1400);
|
||||
check(correct,$"Bayer color channels respect {pattern} with offsets {offset.X},{offset.Y}");
|
||||
check(Fits.Read(path).Pixels.All(v=>v==1000),$"color support preserves analysis grayscale for {pattern} with offsets {offset.X},{offset.Y}");
|
||||
last=color;frame=Fits.Inspect(path);
|
||||
}
|
||||
byte[] sourceHash=SHA256.HashData(File.ReadAllBytes(frame!.Path));string cache=ColorPreview.PathFor(directory,frame!);ColorPreview.Write(last!,cache,frame!);var restored=ColorPreview.Read(cache,frame!);
|
||||
check(restored.Red.SequenceEqual(last!.Red)&&restored.Green.SequenceEqual(last.Green)&&restored.Blue.SequenceEqual(last.Blue),"color caches retain linear RGB samples without losing channel order");
|
||||
var neutral=ColorPreview.Render(ColorPreview.Prepare(restored));
|
||||
check(Enumerable.Range(0,neutral.Length/4).All(i=>neutral[i*4]==neutral[i*4+1]&&neutral[i*4+1]==neutral[i*4+2]),"sky neutralization does not turn a constant colored pedestal into false nebula color");
|
||||
check(sourceHash.SequenceEqual(SHA256.HashData(File.ReadAllBytes(frame.Path))),"color reading, preparing, rendering and caching preserve source FITS bytes");
|
||||
bool refused=false;try{ColorPreview.Read(cache,new Frame{Length=frame.Length+1,Modified=frame.Modified});}catch(InvalidDataException){refused=true;}
|
||||
check(refused,"changed sources invalidate color caches independently of quality data");
|
||||
const int w=96,h=96;var random=new Random(1902);float[][] channels=[new float[w*h],new float[w*h],new float[w*h]];
|
||||
for(int y=0;y<h;y++)for(int x=0;x<w;x++)for(int c=0;c<3;c++)channels[c][y*w+x]=(float)(1000+(c==0?80:0)*Math.Exp(-Math.Pow((x-48)/12.0,2)-Math.Pow((y-48)/20.0,2))+(random.NextDouble()-.5)*12);
|
||||
var input=(float[])channels[0].Clone();var display=ColorPreview.Prepare(new(w,h,channels[0],channels[1],channels[2]));var output=ColorPreview.Render(display);
|
||||
check(Enumerable.Range(0,w*h).Count(i=>output[i*4+2]>output[i*4]+30&&output[i*4+2]>output[i*4+1]+30)>20,"color nebula preserves a real red diffuse signal through the linked stretch");
|
||||
var extremes=ColorPreview.Render(new(new(new(2,1,[0,10]),0,10,.5,true),[[100,100],[-50,-50],[-50,-50]],1));
|
||||
check(extremes.Take(3).All(v=>v==0)&&extremes.Skip(4).Take(3).All(v=>v==255),"linked color stays neutral at black and white instead of clipping individual channels");
|
||||
check(channels[0].SequenceEqual(input)&&Enumerable.Range(0,w*h).All(i=>output[i*4+3]==255),"color display leaves linear channels untouched and emits opaque pixels");
|
||||
using(var cancel=new CancellationTokenSource()){cancel.Cancel();bool cancelled=false;try{ColorPreview.ReadFits(frame.Path,cancel.Token);}catch(OperationCanceledException){cancelled=true;}check(cancelled,"color FITS reading cancels before processing rows");}
|
||||
string mono=Path.Combine(directory,"mono.fit");ImageRegression.WriteFits(mono,Enumerable.Repeat(1000f,128*128).ToArray(),128,128,0);
|
||||
check(ColorPreview.ReadFits(mono)==null,"monochrome FITS files never acquire fabricated color channels");
|
||||
string invalid=Path.Combine(directory,"invalid.fit");ImageRegression.WriteFits(invalid,Enumerable.Repeat(1000f,128*128).ToArray(),128,128,0,"XXXX");
|
||||
check(ColorPreview.ReadFits(invalid)==null,"unknown Bayer layouts fall back to grayscale instead of guessing color");
|
||||
}
|
||||
finally{Directory.Delete(directory,true);}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue