解读Android GIF文件native渲染之OpenGL

本系列文章以koral实现的GIF文件native渲染为根据,解读实现的大致过程以及关键代码分析,github地址:https://github.com/koral–/android-gif-drawable
由前文中纹理贴图native实现可知,若想实现图像的OpenGL渲染(主要glTexImage2D函数),首先需要解析出该图像文件(当时PNG为例)的图像数据以及其它相关信息,然后利用native OpenGL API实现,而GIF文件的渲染过程稍微麻烦一些,因为涉及到多帧图像的渲染,具体过程可以大致分为以下几个步骤。

(1)创建解析GIF文件的句柄

利用GIFLIB解析GIF文件,把相关信息保存在GifInfo结构体中,并将该结构体的指针(long)返回给JAVA层,作为访问GIF文件这些信息的句柄。从JAVA层到GIFLIB的大致实现流程如下:
这里写图片描述
GifInfo结构体:

struct GifInfo {
    void (*destructor)(GifInfo *, JNIEnv *);
    GifFileType *gifFilePtr;
    GifWord originalWidth, originalHeight;
    uint_fast16_t sampleSize;
    long long lastFrameRemainder;
    long long nextStartTime;
    uint_fast32_t currentIndex;
    GraphicsControlBlock *controlBlock;
    argb *backupPtr;
    long long startPos;
    unsigned char *rasterBits;
    uint_fast32_t rasterSize;
    char *comment;
    uint_fast16_t loopCount;
    uint_fast16_t currentLoop;
    RewindFunc rewindFunction;
    jfloat speedFactor;
    int32_t stride;
    jlong sourceLength;
    bool isOpaque;
    void *frameBufferDescriptor;
};

解析GIF文件相关信息的关键代码:

/******************************************************************************
This routine should be called before any other DGif calls. Note that
this routine is called automatically from DGif file open routines.
******************************************************************************/
int
DGifGetScreenDesc(GifFileType *GifFile) {
//    bool SortFlag;
    GifByteType Buf[3];
//    GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;

//    if (!IS_READABLE(Private)) {
//        /* This file was NOT o
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值