using AstroFrame.Engine; static class PreviewRegression { public static void Run(Action check) { const int w=360,h=640;var random=new Random(839);float[] pixels=new float[w*h]; for(int y=0;y diff=[];for(int y=0;yv/255.0))<.25,"preview transfer keeps background grain subordinate to the image"); check(untouched.SequenceEqual(pixels),"preview reduction, stretching and nebula mode never alter analysis pixels"); check(frame.Max()>frame[0]+80&&diffuse.Length==frame.Length&&!diffuse.SequenceEqual(frame),"frame preview preserves conspicuous stars and diffuse view retains the full preview geometry"); float[] filament=new float[w*h];random=new Random(8461); for(int y=0;y core=[],sky=[]; for(int y=20;y20,"nebula preview makes a faint narrow filament visible above adjacent sky"); check(original.SequenceEqual(filament),"faint-detail smoothing never modifies the original linear preview samples"); var alternate=PreviewRenderer.Render(enhanced,.18,true);var brighter=PreviewRenderer.Render(enhanced,.30,true); check(!alternate.SequenceEqual(enhancedPixels)&&alternate.Zip(brighter).All(pair=>pair.Second>=pair.First),"asinh offers a distinct monotonic stretch and responds to brightness adjustments"); var highMedian=new PreviewDisplay(new(1,1,[.7f]),0,1,.7,true); check(Math.Abs(PreviewRenderer.Render(highMedian,.18,true)[0]-255*.25)<2&&PreviewRenderer.Render(highMedian,.30,true)[0]>PreviewRenderer.Render(highMedian,.18,true)[0],"asinh brightness remains adjustable when the source median already exceeds the display target"); var flat=PreviewRenderer.Prepare(new(32,32,Enumerable.Repeat(1000f,1024).ToArray()),true); check(PreviewRenderer.Render(flat).Distinct().Count()==1&&PreviewRenderer.Render(flat,.18,true).Distinct().Count()==1,"constant fields remain constant without invented diffuse structure"); using(var cancel=new CancellationTokenSource()){cancel.Cancel();bool cancelled=false;try{PreviewRenderer.Diffuse(new(w,h,filament),cancel.Token);}catch(OperationCanceledException){cancelled=true;}check(cancelled,"diffuse preview preparation cancels while smoothing");} string path=Path.Combine(Path.GetTempPath(),"AstroFrame-preview-"+Guid.NewGuid()+".bin");var f=new Frame{Length=7654,Modified=4321}; try { PreviewRenderer.Write(image,path,f);var cached=PreviewRenderer.Read(path,f); check(cached.Pixels.SequenceEqual(PreviewRenderer.Reduce(image,1).Pixels),"linear display cache reopens without lost samples or another FITS read"); bool refused=false;try{PreviewRenderer.Read(path,new Frame{Length=7655,Modified=4321});}catch(InvalidDataException){refused=true;}check(refused,"changed sources invalidate display caches independently of quality measurements"); } finally{if(File.Exists(path))File.Delete(path);} } }