Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GifInfoHandle's visbility to public/add ability to get frames without creating drawable #206

Closed
Saren-Arterius opened this issue Sep 20, 2015 · 11 comments

Comments

@Saren-Arterius
Copy link

Currently I am using koush/ion's GifDecoder to decode GIFs and animate the ImageSpan. However GIF corruption occurs in some GIFs, while gif-drawable don't. As a result, I am migrating from GifDecoder to gif-drawable.

I need access to GifInfoHandle, please set GifInfoHandle's visbility to public.

@koral--
Copy link
Owner

koral-- commented Sep 20, 2015

Sorry, but GifInfoHandle is intentionally package-private. What do you exactly want to do?

@Saren-Arterius
Copy link
Author

I originally intended to implement this interface

public interface GifWrapping {
        GifFrame nextFrame();

        void restart();

        void recycle();

        int getTotalFrames();
    }

And later I came to this

static class GifDrawableWrapper implements GifWrapping {

        GifDrawable drawable;
        private int nof;
        private int currentIndex;

        public GifDrawableWrapper(byte[] data) {
            try {
                drawable = new GifDrawable(data);
                drawable.pause();
                nof = drawable.getNumberOfFrames();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public GifFrame nextFrame() {
            if (drawable == null) {
                return null;
            }
            int duration = drawable.getFrameDuration(currentIndex);
            Bitmap bitmap = drawable.seekToFrameAndGet(currentIndex);
            if (currentIndex + 1 >= nof) {
                currentIndex = 0;
            } else {
                currentIndex++;
            }
            return new GifFrame(bitmap, duration);
        }

        public void restart() {
            if (drawable != null) {
                drawable.reset();
            }

        }

        public void recycle() {
            if (drawable != null) {
                drawable.recycle();
            }
        }

        @Override
        public int getTotalFrames() {
            return nof;
        }
    }

For ion's GifDecoder (typo in the class name), the original function

public static class GidDecoderWrapper implements GifWrapping {

        private GifDecoder decoder;

        public GidDecoderWrapper(byte[] data) {
            GifDecoder d;
            d = new GifDecoder(data);
            if (d.getStatus() == GifDecoder.STATUS_FORMAT_ERROR) {
                d = null;
            }
            decoder = d;
        }

        @Override
        public GifFrame nextFrame() {
            if (decoder == null) {
                return null;
            }
            return decoder.nextFrame();
        }

        @Override
        public void restart() {
            if (decoder == null) {
                return;
            }
            decoder.restart();
        }

        @Override
        public void recycle() {
            decoder = null;
        }

        @Override
        public int getTotalFrames() {
            return -1;
        }
    }

@jonasasx
Copy link

jonasasx commented Oct 8, 2015

How can I decode file/stream to android.graphics.Bitmap, using this library?

@koral--
Copy link
Owner

koral-- commented Oct 8, 2015

@Saren-Arterius what is the problem? Which method from GifInfoHandle do you need exactly?
@jonasasx generally please fill new Github issue for new questions, but you can see in listing above that there is a method: GifDrawable#seekToFrameAndGet().

@jonasasx
Copy link

jonasasx commented Oct 8, 2015

@koral--, I have to make GifInfoHandle public in my code to decode gif image to bitmap without drawable. My question was about this issue.

@koral--
Copy link
Owner

koral-- commented Oct 8, 2015

OK, I understand now. Interesting use case. I'll consider it.

@koral-- koral-- reopened this Oct 8, 2015
@koral-- koral-- changed the title Set GifInfoHandle's visbility to public Set GifInfoHandle's visbility to public/add ability to get frames without creating drawable Oct 8, 2015
@Saren-Arterius
Copy link
Author

It's just about animating ImageSpan in a TextView. It's messy, I have written a GifThread for each gif url, it will replace the drawable inside a drawable wrapper with a next frame over time, but it just works.

@Saren-Arterius
Copy link
Author

Without using GifInfoHandle, I will have to pause the new GifDrawable immediately. Don't know whether this will cause extra overhead (A new gif animating has been already submited to an executor?).

@koral-- koral-- removed the invalid label Oct 10, 2015
@koral--
Copy link
Owner

koral-- commented Oct 10, 2015

If you just want animated GIF inside ImageSpan you can use GifDrawable with custom callback which invalidates TextView. Like that in sample project: ImageSpanFragment. But drawable needs to manually paused if you don't want it to start automatically.
By default if GifDrawable is paused before drawing first frame nothing should be submitted to executor.

@Saren-Arterius
Copy link
Author

@koral-- I am currently having greater control that I can let my users to limit the GIF fps. Also, the code in my app is too fixed that it's very hard to change. Anyway, thanks for letting me know that.

@koral--
Copy link
Owner

koral-- commented Jan 10, 2016

Lightweight wrapper of GifInfoHandle - GifDecoder added in 8aded2d

@koral-- koral-- closed this as completed Jan 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@koral-- @Saren-Arterius @jonasasx and others