@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
2222 /// <remarks>
2323 /// A useful decoding source example can be found at <see href="https://dxr.mozilla.org/mozilla-central/source/image/decoders/nsBMPDecoder.cpp"/>
2424 /// </remarks>
25- internal sealed class BmpDecoderCore
25+ internal sealed class BmpDecoderCore : IImageDecoderInternals
2626 {
2727 /// <summary>
2828 /// The default mask for the red part of the color for 16 bit rgb bitmaps.
@@ -89,11 +89,6 @@ internal sealed class BmpDecoderCore
8989 /// </summary>
9090 private BmpInfoHeader infoHeader ;
9191
92- /// <summary>
93- /// The global configuration.
94- /// </summary>
95- private readonly Configuration configuration ;
96-
9792 /// <summary>
9893 /// Used for allocating memory during processing operations.
9994 /// </summary>
@@ -111,67 +106,28 @@ internal sealed class BmpDecoderCore
111106 /// <param name="options">The options.</param>
112107 public BmpDecoderCore ( Configuration configuration , IBmpDecoderOptions options )
113108 {
114- this . configuration = configuration ;
109+ this . Configuration = configuration ;
115110 this . memoryAllocator = configuration . MemoryAllocator ;
116111 this . options = options ;
117112 }
118113
114+ /// <inheritdoc />
115+ public Configuration Configuration { get ; }
116+
119117 /// <summary>
120118 /// Gets the dimensions of the image.
121119 /// </summary>
122120 public Size Dimensions => new Size ( this . infoHeader . Width , this . infoHeader . Height ) ;
123121
124- /// <summary>
125- /// Decodes the image from the specified this._stream and sets
126- /// the data to image.
127- /// </summary>
128- /// <typeparam name="TPixel">The pixel format.</typeparam>
129- /// <param name="stream">The stream, where the image should be
130- /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
131- /// <exception cref="System.ArgumentNullException">
132- /// <para><paramref name="stream"/> is null.</para>
133- /// </exception>
134- /// <returns>The decoded image.</returns>
135- public async Task < Image < TPixel > > DecodeAsync < TPixel > ( Stream stream )
136- where TPixel : unmanaged, IPixel < TPixel >
137- {
138- // if we can seek then we arn't in a context that errors on async operations
139- if ( stream . CanSeek )
140- {
141- return this . Decode < TPixel > ( stream ) ;
142- }
143- else
144- {
145- // cheat for now do async copy of the stream into memory stream and use the sync version
146- // we should use an array pool backed memorystream implementation
147- using ( var ms = new MemoryStream ( ) )
148- {
149- await stream . CopyToAsync ( ms ) . ConfigureAwait ( false ) ;
150- ms . Position = 0 ;
151- return this . Decode < TPixel > ( ms ) ;
152- }
153- }
154- }
155-
156- /// <summary>
157- /// Decodes the image from the specified this._stream and sets
158- /// the data to image.
159- /// </summary>
160- /// <typeparam name="TPixel">The pixel format.</typeparam>
161- /// <param name="stream">The stream, where the image should be
162- /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
163- /// <exception cref="System.ArgumentNullException">
164- /// <para><paramref name="stream"/> is null.</para>
165- /// </exception>
166- /// <returns>The decoded image.</returns>
122+ /// <inheritdoc />
167123 public Image < TPixel > Decode < TPixel > ( Stream stream )
168- where TPixel : unmanaged, IPixel < TPixel >
124+ where TPixel : unmanaged, IPixel < TPixel >
169125 {
170126 try
171127 {
172128 int bytesPerColorMapEntry = this . ReadImageHeaders ( stream , out bool inverted , out byte [ ] palette ) ;
173129
174- var image = new Image < TPixel > ( this . configuration , this . infoHeader . Width , this . infoHeader . Height , this . metadata ) ;
130+ var image = new Image < TPixel > ( this . Configuration , this . infoHeader . Width , this . infoHeader . Height , this . metadata ) ;
175131
176132 Buffer2D < TPixel > pixels = image . GetRootFramePixelBuffer ( ) ;
177133
@@ -242,30 +198,13 @@ public Image<TPixel> Decode<TPixel>(Stream stream)
242198 }
243199 }
244200
245- /// <summary>
246- /// Reads the raw image information from the specified stream.
247- /// </summary>
248- /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
201+ /// <inheritdoc />
249202 public IImageInfo Identify ( Stream stream )
250203 {
251204 this . ReadImageHeaders ( stream , out _ , out _ ) ;
252205 return new ImageInfo ( new PixelTypeInfo ( this . infoHeader . BitsPerPixel ) , this . infoHeader . Width , this . infoHeader . Height , this . metadata ) ;
253206 }
254207
255- /// <summary>
256- /// Reads the raw image information from the specified stream.
257- /// </summary>
258- /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
259- public async Task < IImageInfo > IdentifyAsync ( Stream stream )
260- {
261- using ( var ms = new FixedCapacityPooledMemoryStream ( stream . Length ) )
262- {
263- await stream . CopyToAsync ( ms ) . ConfigureAwait ( false ) ;
264- ms . Position = 0 ;
265- return this . Identify ( ms ) ;
266- }
267- }
268-
269208 /// <summary>
270209 /// Returns the y- value based on the given height.
271210 /// </summary>
@@ -999,7 +938,7 @@ private void ReadRgb24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, b
999938 int newY = Invert ( y , height , inverted ) ;
1000939 Span < TPixel > pixelSpan = pixels . GetRowSpan ( newY ) ;
1001940 PixelOperations < TPixel > . Instance . FromBgr24Bytes (
1002- this . configuration ,
941+ this . Configuration ,
1003942 row . GetSpan ( ) ,
1004943 pixelSpan ,
1005944 width ) ;
@@ -1028,7 +967,7 @@ private void ReadRgb32Fast<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
1028967 int newY = Invert ( y , height , inverted ) ;
1029968 Span < TPixel > pixelSpan = pixels . GetRowSpan ( newY ) ;
1030969 PixelOperations < TPixel > . Instance . FromBgra32Bytes (
1031- this . configuration ,
970+ this . Configuration ,
1032971 row . GetSpan ( ) ,
1033972 pixelSpan ,
1034973 width ) ;
@@ -1065,7 +1004,7 @@ private void ReadRgb32Slow<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
10651004 this . stream . Read ( row ) ;
10661005
10671006 PixelOperations < Bgra32 > . Instance . FromBgra32Bytes (
1068- this . configuration ,
1007+ this . Configuration ,
10691008 row . GetSpan ( ) ,
10701009 bgraRowSpan ,
10711010 width ) ;
@@ -1101,7 +1040,7 @@ private void ReadRgb32Slow<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
11011040 Span < TPixel > pixelSpan = pixels . GetRowSpan ( newY ) ;
11021041
11031042 PixelOperations < TPixel > . Instance . FromBgra32Bytes (
1104- this . configuration ,
1043+ this . Configuration ,
11051044 row . GetSpan ( ) ,
11061045 pixelSpan ,
11071046 width ) ;
@@ -1115,7 +1054,7 @@ private void ReadRgb32Slow<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
11151054 {
11161055 this . stream . Read ( row ) ;
11171056 PixelOperations < Bgra32 > . Instance . FromBgra32Bytes (
1118- this . configuration ,
1057+ this . Configuration ,
11191058 row . GetSpan ( ) ,
11201059 bgraRowSpan ,
11211060 width ) ;
0 commit comments