@@ -95,8 +95,11 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
9595 bool useGlobalTable = this . colorTableMode == GifColorTableMode . Global ;
9696
9797 // Quantize the image returning a palette.
98- QuantizedFrame < TPixel > quantized =
99- this . quantizer . CreateFrameQuantizer < TPixel > ( image . GetConfiguration ( ) ) . QuantizeFrame ( image . Frames . RootFrame ) ;
98+ QuantizedFrame < TPixel > quantized = null ;
99+ using ( IFrameQuantizer < TPixel > frameQuantizer = this . quantizer . CreateFrameQuantizer < TPixel > ( image . GetConfiguration ( ) ) )
100+ {
101+ quantized = frameQuantizer . QuantizeFrame ( image . Frames . RootFrame ) ;
102+ }
100103
101104 // Get the number of bits.
102105 this . bitDepth = ImageMaths . GetBitsNeededForColorDepth ( quantized . Palette . Length ) . Clamp ( 1 , 8 ) ;
@@ -133,7 +136,6 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
133136
134137 // Clean up.
135138 quantized ? . Dispose ( ) ;
136- quantized = null ;
137139
138140 // TODO: Write extension etc
139141 stream . WriteByte ( GifConstants . EndIntroducer ) ;
@@ -158,7 +160,8 @@ private void EncodeGlobal<TPixel>(Image<TPixel> image, QuantizedFrame<TPixel> qu
158160 }
159161 else
160162 {
161- using ( QuantizedFrame < TPixel > paletteQuantized = palleteQuantizer . CreateFrameQuantizer ( image . GetConfiguration ( ) ) . QuantizeFrame ( frame ) )
163+ using ( IFrameQuantizer < TPixel > palleteFrameQuantizer = palleteQuantizer . CreateFrameQuantizer ( image . GetConfiguration ( ) ) )
164+ using ( QuantizedFrame < TPixel > paletteQuantized = palleteFrameQuantizer . QuantizeFrame ( frame ) )
162165 {
163166 this . WriteImageData ( paletteQuantized , stream ) ;
164167 }
@@ -181,14 +184,17 @@ private void EncodeLocal<TPixel>(Image<TPixel> image, QuantizedFrame<TPixel> qua
181184 if ( previousFrame != null && previousMeta . ColorTableLength != frameMetadata . ColorTableLength
182185 && frameMetadata . ColorTableLength > 0 )
183186 {
184- quantized = this . quantizer . CreateFrameQuantizer < TPixel > (
185- image . GetConfiguration ( ) ,
186- frameMetadata . ColorTableLength ) . QuantizeFrame ( frame ) ;
187+ using ( IFrameQuantizer < TPixel > frameQuantizer = this . quantizer . CreateFrameQuantizer < TPixel > ( image . GetConfiguration ( ) , frameMetadata . ColorTableLength ) )
188+ {
189+ quantized = frameQuantizer . QuantizeFrame ( frame ) ;
190+ }
187191 }
188192 else
189193 {
190- quantized = this . quantizer . CreateFrameQuantizer < TPixel > ( image . GetConfiguration ( ) )
191- . QuantizeFrame ( frame ) ;
194+ using ( IFrameQuantizer < TPixel > frameQuantizer = this . quantizer . CreateFrameQuantizer < TPixel > ( image . GetConfiguration ( ) ) )
195+ {
196+ quantized = frameQuantizer . QuantizeFrame ( frame ) ;
197+ }
192198 }
193199 }
194200
0 commit comments