@@ -51,8 +51,10 @@ public static void ExecuteDecodingTest(KtxFile file, string outputFile)
5151 Assert . Equal ( ( uint ) pixels . Width , file . header . PixelWidth ) ;
5252 Assert . Equal ( ( uint ) pixels . Height , file . header . PixelHeight ) ;
5353
54- using var outFs = File . OpenWrite ( outputFile ) ;
55- SaveAsPng ( pixels , outFs ) ;
54+ using ( var outFs = File . OpenWrite ( outputFile ) )
55+ {
56+ SaveAsPng ( pixels , outFs ) ;
57+ }
5658 }
5759
5860 #region Dds
@@ -70,15 +72,16 @@ public static void ExecuteDdsWritingTest(Memory2D<ColorRgba32>[] images, Compres
7072 encoder . OutputOptions . Format = format ;
7173 encoder . OutputOptions . FileFormat = OutputFileFormat . Dds ;
7274
73- using var fs = File . OpenWrite ( outputFile ) ;
74-
75- if ( images . Length == 1 )
75+ using ( var fs = File . OpenWrite ( outputFile ) )
7676 {
77- encoder . EncodeToStream ( images [ 0 ] , fs ) ;
78- }
79- else
80- {
81- encoder . EncodeCubeMapToStream ( images [ 0 ] , images [ 1 ] , images [ 2 ] , images [ 3 ] , images [ 4 ] , images [ 5 ] , fs ) ;
77+ if ( images . Length == 1 )
78+ {
79+ encoder . EncodeToStream ( images [ 0 ] , fs ) ;
80+ }
81+ else
82+ {
83+ encoder . EncodeCubeMapToStream ( images [ 0 ] , images [ 1 ] , images [ 2 ] , images [ 3 ] , images [ 4 ] , images [ 5 ] , fs ) ;
84+ }
8285 }
8386 }
8487
@@ -102,8 +105,10 @@ public static void ExecuteDdsReadingTest(DdsFile file, DxgiFormat format, string
102105 Assert . Contains ( pixels , x => x . a == 0 ) ;
103106 }
104107
105- using var outFs = File . OpenWrite ( string . Format ( outputFile , i ) ) ;
106- SaveAsPng ( images [ i ] , outFs ) ;
108+ using ( var outFs = File . OpenWrite ( string . Format ( outputFile , i ) ) )
109+ {
110+ SaveAsPng ( images [ i ] , outFs ) ;
111+ }
107112 }
108113 }
109114
@@ -128,26 +133,30 @@ await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
128133
129134 public static float DecodeKtxCheckPSNR ( string filename , Memory2D < ColorRgba32 > original )
130135 {
131- using var fs = File . OpenRead ( filename ) ;
132- var ktx = KtxFile . Load ( fs ) ;
133- var decoder = new BcDecoder ( )
136+ using ( var fs = File . OpenRead ( filename ) )
134137 {
135- OutputOptions = { Bc4Component = ColorComponent . Luminance }
136- } ;
137- var decoded = decoder . Decode2D ( ktx ) ;
138+ var ktx = KtxFile . Load ( fs ) ;
139+ var decoder = new BcDecoder ( )
140+ {
141+ OutputOptions = { Bc4Component = ColorComponent . Luminance }
142+ } ;
143+ var decoded = decoder . Decode2D ( ktx ) ;
138144
139- return CalculatePSNR ( original , decoded ) ;
145+ return CalculatePSNR ( original , decoded ) ;
146+ }
140147 }
141148
142149 public static float DecodeKtxCheckRMSEHdr ( string filename , HdrImage original )
143150 {
144- using var fs = File . OpenRead ( filename ) ;
145- var ktx = KtxFile . Load ( fs ) ;
146- var decoder = new BcDecoder ( ) ;
151+ using ( var fs = File . OpenRead ( filename ) )
152+ {
153+ var ktx = KtxFile . Load ( fs ) ;
154+ var decoder = new BcDecoder ( ) ;
147155
148- var decoded = decoder . DecodeHdr ( ktx ) ;
156+ var decoded = decoder . DecodeHdr ( ktx ) ;
149157
150- return ImageQuality . CalculateLogRMSE ( original . pixels , decoded ) ;
158+ return ImageQuality . CalculateLogRMSE ( original . pixels , decoded ) ;
159+ }
151160 }
152161
153162 public static void ExecuteEncodingTest ( Memory2D < ColorRgba32 > image , CompressionFormat format , CompressionQuality quality , string filename , ITestOutputHelper output )
@@ -234,25 +243,27 @@ public static unsafe void SaveAsPng(Memory2D<ColorRgba32> image, Stream stream)
234243 {
235244 int width = image . Width ;
236245 int height = image . Height ;
237- using var bmp = new Bitmap ( width , height , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) ;
238- var data = bmp . LockBits ( new Rectangle ( 0 , 0 , width , height ) ,
239- ImageLockMode . WriteOnly , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) ;
240- byte * ptr = ( byte * ) data . Scan0 ;
241- var span = image . Span ;
242- for ( int y = 0 ; y < height ; y ++ )
246+ using ( var bmp = new Bitmap ( width , height , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) )
243247 {
244- for ( int x = 0 ; x < width ; x ++ )
248+ var data = bmp . LockBits ( new Rectangle ( 0 , 0 , width , height ) ,
249+ ImageLockMode . WriteOnly , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) ;
250+ byte * ptr = ( byte * ) data . Scan0 ;
251+ var span = image . Span ;
252+ for ( int y = 0 ; y < height ; y ++ )
245253 {
246- var c = span [ y , x ] ;
247- ptr [ 0 ] = c . b ;
248- ptr [ 1 ] = c . g ;
249- ptr [ 2 ] = c . r ;
250- ptr [ 3 ] = c . a ;
251- ptr += 4 ;
254+ for ( int x = 0 ; x < width ; x ++ )
255+ {
256+ var c = span [ y , x ] ;
257+ ptr [ 0 ] = c . b ;
258+ ptr [ 1 ] = c . g ;
259+ ptr [ 2 ] = c . r ;
260+ ptr [ 3 ] = c . a ;
261+ ptr += 4 ;
262+ }
252263 }
264+ bmp . UnlockBits ( data ) ;
265+ bmp . Save ( stream , ImageFormat . Png ) ;
253266 }
254- bmp . UnlockBits ( data ) ;
255- bmp . Save ( stream , ImageFormat . Png ) ;
256267 }
257268
258269 public static void SaveAsPng ( ColorRgbFloat [ ] pixels , int width , int height , Stream stream )
0 commit comments