Top > giflib
  • giflib -- A library for processing GIFs
    • http://sourceforge.net/projects/giflib/

      giflib is a library for reading and writing gif images. It is API and ABI compatible with libungif which was in wide use while the LZW compression algorithm was patented.

git clone https://git.code.sf.net/p/giflib/code giflib-code
# libungif development stopped    2007-11-10
  • libungif は開発中止で、API/ABI 互換の giflib が今時。
cvs -d:pserver:anonymous@giflib.cvs.sourceforge.net:/cvsroot/giflib login
cvs -z3 -d:pserver:anonymous@giflib.cvs.sourceforge.net:/cvsroot/giflib co -P  giflib

使い方

  • http://giflib.sourceforge.net/doc/gif_lib.html
  • http://diary.awm.jp/~yoya/?2008091#200809141 giflib の使い方を6行で説明
    ファイル名かファイルディスクリプタ(int fd) を渡して、GIF ファイル画像を開く。 
      GifFileType *DGifOpenFileName(char *GifFileName) 
      GifFileType *DGifOpenFileHandle(int GifFileHandle) 
    実際に画像を内部表現データ(in-core allocated structures)に取り込むのは、これ。 
      int DGifSlurp(GifFileType *GifFile) 
    後は、GifFileType 構造体のメンバーを辿って欲しい情報を引き出す。
  • あ、やっぱり6行じゃ無理だった…追記
    尚、DGifSlurp 内部では逐次的にデータを取得していて、その層の API を
    使う事もできる。(util/rotat.c, gifrsize.c 参考のこと)
      while ((DGifGetRecordType(&GifFile, &RecordType)) &&
             (RecordType != TERMINATE_RECORD_TYPE)) {
          switch(RecordType) {
            case SCREEN_DESC_RECORD_TYPE:
               DGifGetScreenDesc(&GifFile);
               break;
          <略>

データ構造

DGifSlurp を呼ぶと GiFileType に以下の構造でデータを格納してくれます。
  • gif_lib.h 参照の事
    - GifFileType 
       |- SWitdh, SHeight <= スクリーンサイズ
       |- SColorResolution
       |- SBackGroundColor
       |- SColorMap <= グローバルな色パレット
       |- Image  <= SavedImages のカーソル?
       |- ImageCount <= フレーム数 (GIFアニメ用)
       |- SavedImages  <= 画像イメージデータ(の配列)
- SavedImages
   |- ExtensionBlockCount
   |- ExtensionBlocks <= 透明色indexはこれに含まれる
   |- ImageDesc
   |    |- Left, Top, Width, Height <= Page geometry
   |    |- ColorMap <= ローカルカラーマップ
   |-RasterBits <= 画像データを(1次元)配列で格納
- SColorMap, ColorMap
   |- ColorCount
   |- BitsPerPoxel
   |- Colors
       |- Red, Green, Blue

利用例

バージョン互換破壊

- int EGifCloseFile(GifFileType * GifFile);
+ int EGifCloseFile(GifFileType *GifFile, int *ErrorCode);
+ #define E_GIF_SUCCEEDED          0

- int DGifCloseFile(GifFileType * GifFile);
+ int DGifCloseFile(GifFileType * GifFile, int *ErrorCode);
+ #define D_GIF_SUCCEEDED          0

参考

関連


Reload   Diff   Front page List of pages Search Recent changes Backup Referer   Help   RSS of recent changes
Last-modified: Thu, 21 May 2020 16:11:00 JST (1436d)