File tree Expand file tree Collapse file tree
src/ImageSharp.Textures/Formats/Ktx2
ImageSharp.Textures.Tests/Formats/Ktx2 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,8 @@ public Texture DecodeTexture(Stream stream)
6969 int width = ( int ) this . ktxHeader . PixelWidth ;
7070 int height = ( int ) this . ktxHeader . PixelHeight ;
7171
72- var levelIndices = new LevelIndex [ this . ktxHeader . LevelCount ] ;
72+ // Zero levels means only the base level is present, so we must read at least 1.
73+ LevelIndex [ ] levelIndices = new LevelIndex [ Math . Max ( 1 , this . ktxHeader . LevelCount ) ] ;
7374 for ( int i = 0 ; i < levelIndices . Length ; i ++ )
7475 {
7576 stream . Read ( this . buffer , 0 , 24 ) ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) Six Labors.
2+ // Licensed under the Six Labors Split License.
3+
4+ using System . ComponentModel ;
5+ using SixLabors . ImageSharp . Textures . Formats . Ktx2 ;
6+ using SixLabors . ImageSharp . Textures . TextureFormats ;
7+
8+ namespace SixLabors . ImageSharp . Textures . Tests . Formats . Ktx2 ;
9+
10+ [ Trait ( "Format" , "Ktx2" ) ]
11+ public class Ktx2DecoderTests
12+ {
13+ private static readonly Ktx2Decoder Ktx2Decoder = new ( ) ;
14+
15+ [ Fact ]
16+ [ Description ( "Ensure that a single mipmap level does not result in an empty mipmap collection" ) ]
17+ public void Ktx2Decoder_LevelCountZero_DecodesBaseLevelMipMap ( )
18+ {
19+ string path = Path . Combine (
20+ TestEnvironment . InputImagesDirectoryFullPath ,
21+ "Ktx2" ,
22+ "Flat" ,
23+ "rgba32-srgb-mips.ktx2" ) ;
24+
25+ using FileStream fileStream = File . OpenRead ( path ) ;
26+ using Texture texture = Ktx2Decoder . DecodeTexture ( Configuration . Default , fileStream ) ;
27+
28+ FlatTexture flatTexture = texture as FlatTexture ;
29+ Assert . NotNull ( flatTexture ) ;
30+ Assert . Single ( flatTexture . MipMaps ) ;
31+ Assert . Equal ( 256 , flatTexture . MipMaps [ 0 ] . GetImage ( ) . Width ) ;
32+ Assert . Equal ( 256 , flatTexture . MipMaps [ 0 ] . GetImage ( ) . Height ) ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ version https://git-lfs.github.com/spec/v1
2+ oid sha256:90846eff319fdfd03121b3e0300fc4106ddcc2a4df881598cca9978e04710004
3+ size 393468
You can’t perform that action at this time.
0 commit comments