/// <summary>
 /// Closes the encoded image handling null.
 /// </summary>
 /// <param name="encodedImage">
 /// The encoded image to close.
 /// </param>
 public static void CloseSafely(EncodedImage encodedImage)
 {
     if (encodedImage != null)
     {
         encodedImage.Dispose();
     }
 }
        /// <summary>
        /// Returns a new CloseableReference to the same underlying
        /// SharedReference or null if invalid. The SharedReference
        /// ref-count is incremented.
        /// </summary>
        public EncodedImage CloneOrNull()
        {
            EncodedImage encodedImage;

            if (_inputStreamSupplier != null)
            {
                encodedImage = new EncodedImage(_inputStreamSupplier, StreamSize);
            }
            else
            {
                CloseableReference <IPooledByteBuffer> pooledByteBufferRef =
                    CloseableReference <IPooledByteBuffer> .CloneOrNull(_pooledByteBufferRef);

                try
                {
                    encodedImage = (pooledByteBufferRef == null) ?
                                   null :
                                   new EncodedImage(pooledByteBufferRef);
                }
                finally
                {
                    // Close the recently created reference since it will be
                    // cloned again in the constructor.
                    CloseableReference <IPooledByteBuffer> .CloseSafely(pooledByteBufferRef);
                }
            }

            if (encodedImage != null)
            {
                encodedImage.CopyMetaDataFrom(this);
            }

            return(encodedImage);
        }
 /// <summary>
 /// Copy the meta data from another EncodedImage.
 /// </summary>
 /// <param name="encodedImage">
 /// The EncodedImage to copy the meta data from.
 /// </param>
 public void CopyMetaDataFrom(EncodedImage encodedImage)
 {
     Format        = encodedImage.Format;
     Width         = encodedImage.Width;
     Height        = encodedImage.Height;
     RotationAngle = encodedImage.RotationAngle;
     SampleSize    = encodedImage.SampleSize;
     StreamSize    = encodedImage.Size;
 }
 /// <summary>
 /// Returns the cloned encoded image if the parameter received is
 /// not null, null otherwise.
 /// </summary>
 /// <param name="encodedImage">The EncodedImage to clone.</param>
 public static EncodedImage CloneOrNull(EncodedImage encodedImage)
 {
     return(encodedImage != null?encodedImage.CloneOrNull() : null);
 }
 /// <summary>
 /// Checks if the encoded image is valid i.e. is not null, and
 /// is not closed.
 /// <returns>True if the encoded image is valid.</returns>
 /// </summary>
 public static bool IsValid(EncodedImage encodedImage)
 {
     return(encodedImage != null && encodedImage.Valid);
 }
 /// <summary>
 /// Returns true if all the image information has loaded, false otherwise.
 /// </summary>
 public static bool IsMetaDataAvailable(EncodedImage encodedImage)
 {
     return(encodedImage.RotationAngle >= 0 &&
            encodedImage.Width >= 0 &&
            encodedImage.Height >= 0);
 }