Skip to content

Commit

Permalink
getInputSourceByteCount() added
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Feb 11, 2014
1 parent 5e05c14 commit d4a2a81
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/pl/droidsonroids/gif/GifDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class GifDrawable extends Drawable implements Animatable, MediaPlayerCont

private final int[] mColors;
private final int[] mMetaData = new int[ 4 ];//[w,h,imageCount,errorCode]
private final long mInputSourceLength;

private final Runnable mResetTask = new Runnable()
{
Expand Down Expand Up @@ -149,6 +150,7 @@ public GifDrawable ( String filePath ) throws IOException
{
if ( filePath == null )
throw new NullPointerException( "Source is null" );
mInputSourceLength=new File(filePath).length();
mGifInfoPtr = openFile( mMetaData, filePath );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
}
Expand All @@ -161,7 +163,11 @@ public GifDrawable ( String filePath ) throws IOException
*/
public GifDrawable ( File file ) throws IOException
{
this( file.getPath() );
if ( file == null )
throw new NullPointerException( "Source is null" );
mInputSourceLength=file.length();
mGifInfoPtr = openFile( mMetaData, file.getPath() );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
}

/**
Expand All @@ -180,6 +186,7 @@ public GifDrawable ( InputStream stream ) throws IOException
throw new IllegalArgumentException( "InputStream does not support marking" );
mGifInfoPtr = openStream( mMetaData, stream );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
mInputSourceLength=-1L;
}

/**
Expand All @@ -196,6 +203,7 @@ public GifDrawable ( AssetFileDescriptor afd ) throws IOException
FileDescriptor fd = afd.getFileDescriptor();
mGifInfoPtr = openFd( mMetaData, fd, afd.getStartOffset() );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
mInputSourceLength=afd.getLength();
}

/**
Expand All @@ -210,6 +218,7 @@ public GifDrawable ( FileDescriptor fd ) throws IOException
throw new NullPointerException( "Source is null" );
mGifInfoPtr = openFd( mMetaData, fd, 0 );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
mInputSourceLength=-1L;
}

/**
Expand All @@ -225,6 +234,7 @@ public GifDrawable ( byte[] bytes ) throws IOException
throw new NullPointerException( "Source is null" );
mGifInfoPtr = openByteArray( mMetaData, bytes );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
mInputSourceLength=bytes.length;
}

/**
Expand All @@ -243,6 +253,7 @@ public GifDrawable ( ByteBuffer buffer ) throws IOException
throw new IllegalArgumentException( "ByteBuffer is not direct" );
mGifInfoPtr = openDirectByteBuffer( mMetaData, buffer );
mColors = new int[ mMetaData[ 0 ] * mMetaData[ 1 ] ];
mInputSourceLength=buffer.capacity();
}

/**
Expand Down Expand Up @@ -578,12 +589,23 @@ public int getFrameByteCount ()

/**
* Returns size of the allocated memory used to store pixels of this object.
* It counts length of all frame buffers. This size cannot change during runtime.
* It counts length of all frame buffers. Returned value does not change during runtime.
* @return size of the allocated memory used to store pixels of this object
*/
public long getAllocationByteCount()
{
return getAllocationByteCount( mGifInfoPtr )+mColors.length*4L;
}

/**
* Returns length of the input source obtained at the opening time or -1 if
* length is unknown. Returned value does not change during runtime.
* For GifDrawables constructed from {@link InputStream} and {@link FileDescriptor} -1 is always returned.
* In case of {@link File}, file path, byte array and {@link ByteBuffer} length is always known.
* @return number of bytes backed by input source or -1 if it is unknown
*/
public long getInputSourceByteCount()
{
return mInputSourceLength;
}
}

0 comments on commit d4a2a81

Please sign in to comment.