@@ -310,7 +310,7 @@ public Vp8Encoder(
310
310
/// </summary>
311
311
private int MbHeaderLimit { get ; }
312
312
313
- public void EncodeHeader < TPixel > ( Image < TPixel > image , Stream stream , bool hasAlpha , bool hasAnimation )
313
+ public WebpVp8X EncodeHeader < TPixel > ( Image < TPixel > image , Stream stream , bool hasAlpha , bool hasAnimation )
314
314
where TPixel : unmanaged, IPixel < TPixel >
315
315
{
316
316
// Write bytes from the bitwriter buffer to the stream.
@@ -320,7 +320,7 @@ public void EncodeHeader<TPixel>(Image<TPixel> image, Stream stream, bool hasAlp
320
320
ExifProfile exifProfile = this . skipMetadata ? null : metadata . ExifProfile ;
321
321
XmpProfile xmpProfile = this . skipMetadata ? null : metadata . XmpProfile ;
322
322
323
- BitWriterBase . WriteTrunksBeforeData (
323
+ WebpVp8X vp8x = BitWriterBase . WriteTrunksBeforeData (
324
324
stream ,
325
325
( uint ) image . Width ,
326
326
( uint ) image . Height ,
@@ -335,9 +335,11 @@ public void EncodeHeader<TPixel>(Image<TPixel> image, Stream stream, bool hasAlp
335
335
WebpMetadata webpMetadata = WebpCommonUtils . GetWebpMetadata ( image ) ;
336
336
BitWriterBase . WriteAnimationParameter ( stream , webpMetadata . BackgroundColor , webpMetadata . RepeatCount ) ;
337
337
}
338
+
339
+ return vp8x ;
338
340
}
339
341
340
- public void EncodeFooter < TPixel > ( Image < TPixel > image , Stream stream )
342
+ public void EncodeFooter < TPixel > ( Image < TPixel > image , in WebpVp8X vp8x , bool hasAlpha , Stream stream , long initialPosition )
341
343
where TPixel : unmanaged, IPixel < TPixel >
342
344
{
343
345
// Write bytes from the bitwriter buffer to the stream.
@@ -346,7 +348,9 @@ public void EncodeFooter<TPixel>(Image<TPixel> image, Stream stream)
346
348
ExifProfile exifProfile = this . skipMetadata ? null : metadata . ExifProfile ;
347
349
XmpProfile xmpProfile = this . skipMetadata ? null : metadata . XmpProfile ;
348
350
349
- BitWriterBase . WriteTrunksAfterData ( stream , exifProfile , xmpProfile ) ;
351
+ bool updateVp8x = hasAlpha && vp8x != default ;
352
+ WebpVp8X updated = updateVp8x ? vp8x . WithAlpha ( true ) : vp8x ;
353
+ BitWriterBase . WriteTrunksAfterData ( stream , in updated , updateVp8x , initialPosition , exifProfile , xmpProfile ) ;
350
354
}
351
355
352
356
/// <summary>
@@ -357,9 +361,10 @@ public void EncodeFooter<TPixel>(Image<TPixel> image, Stream stream)
357
361
/// <param name="stream">The stream to encode the image data to.</param>
358
362
/// <param name="bounds">The region of interest within the frame to encode.</param>
359
363
/// <param name="frameMetadata">The frame metadata.</param>
360
- public void EncodeAnimation < TPixel > ( ImageFrame < TPixel > frame , Stream stream , Rectangle bounds , WebpFrameMetadata frameMetadata )
361
- where TPixel : unmanaged, IPixel < TPixel > =>
362
- this . Encode ( stream , frame , bounds , frameMetadata , true , null ) ;
364
+ /// <returns>A <see cref="bool"/> indicating whether the frame contains an alpha channel.</returns>
365
+ public bool EncodeAnimation < TPixel > ( ImageFrame < TPixel > frame , Stream stream , Rectangle bounds , WebpFrameMetadata frameMetadata )
366
+ where TPixel : unmanaged, IPixel < TPixel >
367
+ => this . Encode ( stream , frame , bounds , frameMetadata , true , null ) ;
363
368
364
369
/// <summary>
365
370
/// Encodes the static image frame to the specified stream.
@@ -384,7 +389,8 @@ public void EncodeStatic<TPixel>(Stream stream, Image<TPixel> image)
384
389
/// <param name="frameMetadata">The frame metadata.</param>
385
390
/// <param name="hasAnimation">Flag indicating, if an animation parameter is present.</param>
386
391
/// <param name="image">The image to encode from.</param>
387
- private void Encode < TPixel > ( Stream stream , ImageFrame < TPixel > frame , Rectangle bounds , WebpFrameMetadata frameMetadata , bool hasAnimation , Image < TPixel > image )
392
+ /// <returns>A <see cref="bool"/> indicating whether the frame contains an alpha channel.</returns>
393
+ private bool Encode < TPixel > ( Stream stream , ImageFrame < TPixel > frame , Rectangle bounds , WebpFrameMetadata frameMetadata , bool hasAnimation , Image < TPixel > image )
388
394
where TPixel : unmanaged, IPixel < TPixel >
389
395
{
390
396
int width = bounds . Width ;
@@ -514,6 +520,8 @@ private void Encode<TPixel>(Stream stream, ImageFrame<TPixel> frame, Rectangle b
514
520
{
515
521
encodedAlphaData ? . Dispose ( ) ;
516
522
}
523
+
524
+ return hasAlpha ;
517
525
}
518
526
519
527
/// <inheritdoc/>
0 commit comments