Home | History | Annotate | Download | only in gif
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FXCODEC_GIF_CFX_GIF_H_
      8 #define CORE_FXCODEC_GIF_CFX_GIF_H_
      9 
     10 #include <memory>
     11 #include <vector>
     12 
     13 class CFX_GifContext;
     14 
     15 extern const char* kGifSignature87;
     16 extern const char* kGifSignature89;
     17 
     18 #define GIF_SIG_EXTENSION 0x21
     19 #define GIF_SIG_IMAGE 0x2C
     20 #define GIF_SIG_TRAILER 0x3B
     21 #define GIF_BLOCK_GCE 0xF9
     22 #define GIF_BLOCK_PTE 0x01
     23 #define GIF_BLOCK_CE 0xFE
     24 #define GIF_BLOCK_TERMINAL 0x00
     25 #define GIF_MAX_LZW_EXP 12
     26 #define GIF_MAX_LZW_CODE 4096
     27 #define GIF_DATA_BLOCK 255
     28 #define GIF_D_STATUS_SIG 0x01
     29 #define GIF_D_STATUS_TAIL 0x02
     30 #define GIF_D_STATUS_EXT 0x03
     31 #define GIF_D_STATUS_EXT_CE 0x05
     32 #define GIF_D_STATUS_EXT_GCE 0x06
     33 #define GIF_D_STATUS_EXT_PTE 0x07
     34 #define GIF_D_STATUS_EXT_UNE 0x08
     35 #define GIF_D_STATUS_IMG_INFO 0x09
     36 #define GIF_D_STATUS_IMG_DATA 0x0A
     37 
     38 #pragma pack(1)
     39 typedef struct {
     40   uint8_t pal_bits : 3;
     41   uint8_t sort_flag : 1;
     42   uint8_t color_resolution : 3;
     43   uint8_t global_pal : 1;
     44 } CFX_GifGlobalFlags;
     45 
     46 typedef struct {
     47   uint8_t pal_bits : 3;
     48   uint8_t reserved : 2;
     49   uint8_t sort_flag : 1;
     50   uint8_t interlace : 1;
     51   uint8_t local_pal : 1;
     52 } CFX_GifLocalFlags;
     53 
     54 typedef struct { char signature[6]; } CFX_GifHeader;
     55 
     56 typedef struct {
     57   uint16_t width;
     58   uint16_t height;
     59   CFX_GifGlobalFlags global_flags;
     60   uint8_t bc_index;
     61   uint8_t pixel_aspect;
     62 } CFX_GifLocalScreenDescriptor;
     63 
     64 typedef struct {
     65   uint16_t left;
     66   uint16_t top;
     67   uint16_t width;
     68   uint16_t height;
     69   CFX_GifLocalFlags local_flags;
     70 } CFX_CFX_GifImageInfo;
     71 
     72 typedef struct {
     73   uint8_t transparency : 1;
     74   uint8_t user_input : 1;
     75   uint8_t disposal_method : 3;
     76   uint8_t reserved : 3;
     77 } CFX_GifControlExtensionFlags;
     78 
     79 typedef struct {
     80   uint8_t block_size;
     81   CFX_GifControlExtensionFlags gce_flags;
     82   uint16_t delay_time;
     83   uint8_t trans_index;
     84 } CFX_GifGraphicControlExtension;
     85 
     86 typedef struct {
     87   uint8_t block_size;
     88   uint16_t grid_left;
     89   uint16_t grid_top;
     90   uint16_t grid_width;
     91   uint16_t grid_height;
     92 
     93   uint8_t char_width;
     94   uint8_t char_height;
     95 
     96   uint8_t fc_index;
     97   uint8_t bc_index;
     98 } CFX_GifPlainTextExtension;
     99 
    100 typedef struct {
    101   uint8_t block_size;
    102   uint8_t app_identify[8];
    103   uint8_t app_authentication[3];
    104 } GifApplicationExtension;
    105 
    106 typedef struct { uint8_t r, g, b; } CFX_GifPalette;
    107 #pragma pack()
    108 
    109 enum class CFX_GifDecodeStatus {
    110   Error,
    111   Success,
    112   Unfinished,
    113   InsufficientDestSize,  // Only used internally by CGifLZWDecoder::Decode()
    114 };
    115 
    116 typedef struct {
    117   std::unique_ptr<CFX_GifGraphicControlExtension> image_GCE;
    118   std::vector<CFX_GifPalette> local_palettes;
    119   std::vector<uint8_t> row_buffer;
    120   CFX_CFX_GifImageInfo image_info;
    121   uint8_t local_pallette_exp;
    122   uint8_t code_exp;
    123   uint32_t data_pos;
    124   int32_t row_num;
    125 } CFX_GifImage;
    126 
    127 #endif  // CORE_FXCODEC_GIF_CFX_GIF_H_
    128