apngasm
 All Classes Namespaces Functions Variables
apngasm.h
1 
7 #ifndef _APNGASM_H_
8 #define _APNGASM_H_
9 
10 #include <vector>
11 #include <string>
12 #include <zlib.h> // z_stream
13 #include "apngframe.h"
14 #include "apngasm-conf.h"
15 #include "apngasm-version.h"
16 
21 namespace apngasm {
22 
23  namespace listener { class IAPNGAsmListener; }
24 
25  typedef struct { unsigned char *p; unsigned int size; int x, y, w, h, valid, filters; } OP;
26 
31  struct CHUNK { unsigned int size; unsigned char * p; };
32 
37  class APNGASM_DECLSPEC APNGAsm {
38  public:
42  APNGAsm(void);
43 
48  APNGAsm(const std::vector<APNGFrame> &frames);
49 
53  ~APNGAsm(void);
54 
62  size_t addFrame(const std::string &filePath, unsigned delayNum = DEFAULT_FRAME_NUMERATOR, unsigned delayDen = DEFAULT_FRAME_DENOMINATOR);
63 
69  size_t addFrame(const APNGFrame &frame);
70 
76  APNGAsm& operator << (const APNGFrame &frame);
77 
78 #ifdef APNG_WRITE_SUPPORTED
79 
84  bool assemble(const std::string &outputPath);
85 #endif
86 
87 #ifdef APNG_READ_SUPPORTED
88 
93  const std::vector<APNGFrame>& disassemble(const std::string &filePath);
94 
100  bool savePNGs(const std::string& outputDir) const;
101 #endif
102 
103 #ifdef APNG_SPECS_SUPPORTED
104 
112  const std::vector<APNGFrame>& loadAnimationSpec(const std::string &filePath);
113 
120  bool saveJSON(const std::string& outputPath, const std::string& imageDir="") const;
121 
128  bool saveXML(const std::string& outputPath, const std::string& imageDir="") const;
129 #endif
130 
135  void setAPNGAsmListener(listener::IAPNGAsmListener* listener=NULL);
136 
141  const std::vector<APNGFrame>& getFrames() const;
142 
147  size_t frameCount();
148 
153  size_t reset();
154 
159  const char* version(void) const;
160 
161  private:
162  //apng frame vector
163  std::vector<APNGFrame> _frames;
164 
165  // APNGAsm event listener.
166  listener::IAPNGAsmListener* _listener;
167 
168 #ifdef APNG_WRITE_SUPPORTED
169  unsigned char findCommonType(void);
170  int upconvertToCommonType(unsigned char coltype);
171  void dirtyTransparencyOptimization(unsigned char coltype);
172  unsigned char downconvertOptimizations(unsigned char coltype, bool keep_palette, bool keep_coltype);
173 
174  bool save(const std::string &outputPath, unsigned char coltype, unsigned first, unsigned loops);
175 
176  void process_rect(unsigned char * row, int rowbytes, int bpp, int stride, int h, unsigned char * rows);
177  void deflate_rect_fin(unsigned char * zbuf, unsigned int * zsize, int bpp, int stride, unsigned char * rows, int zbuf_size, int n);
178  void deflate_rect_op(unsigned char *pdata, int x, int y, int w, int h, int bpp, int stride, int zbuf_size, int n);
179  void get_rect(unsigned int w, unsigned int h, unsigned char *pimage1, unsigned char *pimage2, unsigned char *ptemp, unsigned int bpp, unsigned int stride, int zbuf_size, unsigned int has_tcolor, unsigned int tcolor, int n);
180 
181  void write_chunk(FILE * f, const char * name, unsigned char * data, unsigned int length);
182  void write_IDATs(FILE * f, int frame, unsigned char * data, unsigned int length, unsigned int idat_size);
183 
184  OP _op[6];
185  z_stream _op_zstream1;
186  z_stream _op_zstream2;
187  unsigned char * _op_zbuf1;
188  unsigned char * _op_zbuf2;
189  z_stream _fin_zstream;
190  unsigned char * _row_buf;
191  unsigned char * _sub_row;
192  unsigned char * _up_row;
193  unsigned char * _avg_row;
194  unsigned char * _paeth_row;
195  unsigned int _next_seq_num;
196 #endif
197 
198 #ifdef APNG_READ_SUPPORTED
199  const std::vector<APNGFrame>& fileToFrames(const std::string &filePath, unsigned delayNum, unsigned delayDen);
200  void compose_frame(unsigned char ** rows_dst, unsigned char ** rows_src, unsigned char bop, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
201  unsigned int read_chunk(FILE * f, CHUNK * pChunk);
202  void recalc_crc(unsigned char * p, unsigned int size);
203 
204  std::vector<CHUNK> _info_chunks;
205 #endif
206 
207  unsigned int _width;
208  unsigned int _height;
209  unsigned int _size;
210  rgb _palette[256];
211  unsigned char _trns[256];
212  unsigned int _palsize;
213  unsigned int _trnssize;
214  }; // class APNGAsm
215 
216 } // namespace apngasm
217 
218 #endif // _APNGASM_H_
The APNGAsm core class is all you need to assemble and disassemble Animated PNG.
Definition: apngasm.h:37
Definition: apngframe.h:12
Definition: apngframe.h:16
const unsigned DEFAULT_FRAME_DENOMINATOR
The default denominator for the frame delay fraction.
Definition: apngframe.h:10
const unsigned DEFAULT_FRAME_NUMERATOR
The default numerator for the frame delay fraction.
Definition: apngframe.h:9