/// Fired when the original's decoder's download has completed private void OnOriginalDownloadCompleted(BitmapFrameDecode original, EventArgs e) { CleanUpWeakEventSink(); // Update the underlying decoder to match the original's // We already have a _decoder from the cloning, but it's referencing the // LateBoundBitmapDecoder. When download completes, LateBoundBitmapDecoder calls // EnsureDecoder to make the _realDecoder (something like JpegBitmapDecoder), // then calls SetupFrames on the _realDecoder, which calls BitmapFrameDecode's // UpdateDecoder to set _decoder to the JpegBitmapDecoder. So the original's _decoder // changes after download completes, and the clone should change as well. UpdateDecoder(original.Decoder); FireChanged(); _downloadEvent.InvokeEvents(this, e); }
internal BitmapFrameDecode( int frameNumber, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, BitmapFrameDecode frameDecode ) : base(true) { _bitmapInit.BeginInit(); _frameNumber = frameNumber; WicSourceHandle = frameDecode.WicSourceHandle; IsSourceCached = frameDecode.IsSourceCached; CreationCompleted = frameDecode.CreationCompleted; _frameSource = frameDecode._frameSource; _decoder = frameDecode.Decoder; _syncObject = _decoder.SyncObject; _createOptions = createOptions; _cacheOption = cacheOption; _thumbnail = frameDecode._thumbnail; _isThumbnailCached = frameDecode._isThumbnailCached; _metadata = frameDecode._metadata; _isMetadataCached = frameDecode._isMetadataCached; _readOnlycolorContexts = frameDecode._readOnlycolorContexts; _isColorContextCached = frameDecode._isColorContextCached; _bitmapInit.EndInit(); if ((createOptions & BitmapCreateOptions.DelayCreation) != 0) { DelayCreation = true; } else if (!CreationCompleted) { FinalizeCreation(); } else { UpdateCachedSettings(); } }
internal BitmapFrameDecode( int frameNumber, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, BitmapFrameDecode frameDecode ) : base(true) { _bitmapInit.BeginInit(); _frameNumber = frameNumber; WicSourceHandle = frameDecode.WicSourceHandle; IsSourceCached = frameDecode.IsSourceCached; CreationCompleted = frameDecode.CreationCompleted; _frameSource = frameDecode._frameSource; _decoder = frameDecode.Decoder; _syncObject = _decoder.SyncObject; _createOptions = createOptions; _cacheOption = cacheOption; _thumbnail = frameDecode._thumbnail; _isThumbnailCached = frameDecode._isThumbnailCached; _metadata = frameDecode._metadata; _isMetadataCached = frameDecode._isMetadataCached; _readOnlycolorContexts = frameDecode._readOnlycolorContexts; _isColorContextCached = frameDecode._isColorContextCached; _bitmapInit.EndInit(); if ((createOptions & BitmapCreateOptions.DelayCreation) != 0) { DelayCreation = true; } else if (!CreationCompleted) { FinalizeCreation(); } else { UpdateCachedSettings(); } }
public WeakBitmapFrameDecodeEventSink(BitmapFrameDecode cloned, BitmapFrameDecode original) : base(cloned) { _original = original; if (!_original.IsFrozen) { _original.DownloadCompleted += OnSourceDownloadCompleted; _original.DownloadFailed += OnSourceDownloadFailed; _original.DownloadProgress += OnSourceDownloadProgress; } }
/// Fired when the original's decoder's download has completed private void OnOriginalDownloadCompleted(BitmapFrameDecode original, EventArgs e) { CleanUpWeakEventSink(); // Update the underlying decoder to match the original's // We already have a _decoder from the cloning, but it's referencing the // LateBoundBitmapDecoder. When download completes, LateBoundBitmapDecoder calls // EnsureDecoder to make the _realDecoder (something like JpegBitmapDecoder), // then calls SetupFrames on the _realDecoder, which calls BitmapFrameDecode's // UpdateDecoder to set _decoder to the JpegBitmapDecoder. So the original's _decoder // changes after download completes, and the clone should change as well. UpdateDecoder(original.Decoder); FireChanged(); _downloadEvent.InvokeEvents(this, e); }
private void CopyCommon(BitmapFrameDecode sourceBitmapFrameDecode) { _bitmapInit.BeginInit(); _frameNumber = sourceBitmapFrameDecode._frameNumber; _isThumbnailCached = sourceBitmapFrameDecode._isThumbnailCached; _isMetadataCached = sourceBitmapFrameDecode._isMetadataCached; _isColorContextCached = sourceBitmapFrameDecode._isColorContextCached; _frameSource = sourceBitmapFrameDecode._frameSource; _thumbnail = sourceBitmapFrameDecode._thumbnail; _metadata = sourceBitmapFrameDecode.InternalMetadata; _readOnlycolorContexts = sourceBitmapFrameDecode._readOnlycolorContexts; _decoder = sourceBitmapFrameDecode._decoder; if (_decoder != null && _decoder.IsDownloading) { // UpdateDecoder must be called when download completes and the real decoder // is created. Normally _decoder will call UpdateDecoder, but in this case the // decoder will not know about the cloned BitmapFrameDecode and will only call // UpdateDecoder on the original. The clone will need to listen to the original // BitmapFrameDecode for DownloadCompleted, then call UpdateDecoder on itself. // The weak event sink hooks up handlers on DownloadCompleted, DownloadFailed, // and DownloadProgress _weakBitmapFrameDecodeEventSink = new WeakBitmapFrameDecodeEventSink(this, sourceBitmapFrameDecode); } _syncObject = _decoder.SyncObject; _createOptions = sourceBitmapFrameDecode._createOptions; _cacheOption = sourceBitmapFrameDecode._cacheOption; _bitmapInit.EndInit(); }
internal void SetupFrames(BitmapDecoder decoder, ReadOnlyCollection<BitmapFrame> frames) { uint numFrames = 1; HRESULT.Check(UnsafeNativeMethods.WICBitmapDecoder.GetFrameCount(_decoderHandle, out numFrames)); _frames = new List<BitmapFrame>((int)numFrames); // initialize the list of frames to null. // We'll fill it as it's used (pay for play). for (int i = 0; i < (int)numFrames; i++) { if (i > 0 && _cacheOption != BitmapCacheOption.OnLoad) { _createOptions |= BitmapCreateOptions.DelayCreation; } BitmapFrameDecode bfd = null; if ((frames != null) && (frames.Count == (i + 1))) { // If we already have a frames collection, get the BitmapFrame from it bfd = frames[i] as BitmapFrameDecode; bfd.UpdateDecoder(this); } else if (decoder == null) { // All frames should be frozen. bfd = new BitmapFrameDecode( i, _createOptions, _cacheOption, this ); bfd.Freeze(); } else { // if we are creating from an existing cache, use the frames // already stored in that cache // All frames should be frozen. bfd = new BitmapFrameDecode( i, _createOptions, _cacheOption, decoder.Frames[i] as BitmapFrameDecode ); bfd.Freeze(); } _frames.Add(bfd); } }