1/* Image library 
2 * 
3 * Copyright (c) 2016 Max Stepin 
4 * maxst at users.sourceforge.net 
5 * 
6 * zlib license 
7 * ------------ 
8 * 
9 * This software is provided 'as-is', without any express or implied 
10 * warranty. In no event will the authors be held liable for any damages 
11 * arising from the use of this software. 
12 * 
13 * Permission is granted to anyone to use this software for any purpose, 
14 * including commercial applications, and to alter it and redistribute it 
15 * freely, subject to the following restrictions: 
16 * 
17 * 1. The origin of this software must not be misrepresented; you must not 
18 * claim that you wrote the original software. If you use this software 
19 * in a product, an acknowledgment in the product documentation would be 
20 * appreciated but is not required. 
21 * 2. Altered source versions must be plainly marked as such, and must not be 
22 * misrepresented as being the original software. 
23 * 3. This notice may not be removed or altered from any source distribution. 
24 * 
25 */ 
26////////////////////////////////////////////////////////////////////////////////////// 
27// This is a modified version of apngasm // 
28// // 
29// The modifications were made by Tristan Grimmer and are primarily to remove // 
30// main so the functionality can be called directly from other source files. // 
31// A header file has been created to allow external access. // 
32// // 
33// All modifications should be considered to be covered by the zlib license above. // 
34////////////////////////////////////////////////////////////////////////////////////// 
35 
36#ifndef IMAGE_H 
37#define IMAGE_H 
38#include <string.h> 
39#include <vector> 
40 
41 
42// @tacent Added version string. Value taken from printf in main(). 
43#define APNGASM_VERSION_STRING "2.91" 
44 
45// @tacent Put it all in a namespace. 
46namespace APngAsm 
47
48 
49 
50struct rgb { unsigned char r, g, b; }; 
51 
52struct Image 
53
54 typedef unsigned char * ROW
55 unsigned int w, h, bpp, type
56 int ps, ts
57 rgb pl[256]; 
58 unsigned char tr[256]; 
59 unsigned int delay_num, delay_den
60 unsigned char * p
61 ROW * rows
62 Image() : w(0), h(0), bpp(0), type(0), ps(0), ts(0), delay_num(1), delay_den(10), p(0), rows(0
63
64 memset(s: pl, c: 255, n: sizeof(pl)); 
65 memset(s: tr, c: 255, n: sizeof(tr)); 
66
67 ~Image() { } 
68 // bpp is bytes per pixel. 
69 // type = 2 for RGB. type = 6 for RGBA 
70 void init(unsigned int w1, unsigned int h1, unsigned int bpp1, unsigned int type1
71
72 w = w1; h = h1; bpp = bpp1; type = type1
73 int rowbytes = w * bpp
74 delete[] rows; delete[] p
75 rows = new ROW[h]; 
76 rows[0] = p = new unsigned char[h * rowbytes]; 
77 for (unsigned int j=1; j<h; j++) 
78 rows[j] = rows[j-1] + rowbytes
79
80 void init(unsigned int w, unsigned int h, Image * image
81 {  
82 init(w1: w, h1: h, bpp1: image->bpp, type1: image->type); 
83 if ((ps = image->ps) != 0) memcpy(dest: &pl[0], src: &image->pl[0], n: ps*3); 
84 if ((ts = image->ts) != 0) memcpy(dest: &tr[0], src: &image->tr[0], n: ts); 
85
86 void init(Image * image) { init(w: image->w, h: image->h, image); } 
87 void free() { delete[] rows; delete[] p; } 
88}; 
89 
90int load_image(char * szName, Image * image); 
91unsigned char find_common_coltype(std::vector<Image>& img); 
92void optim_upconvert(Image * image, unsigned char coltype); 
93void optim_duplicates(std::vector<Image>& img, unsigned int first); 
94void optim_dirty_transp(Image * image); 
95void optim_downconvert(std::vector<Image>& img); 
96void optim_palette(std::vector<Image>& img); 
97void optim_add_transp(std::vector<Image>& img); 
98 
99 
100// @tacent 
101// deflate_method = 0 for zlib (only one supported). 
102// iter is ignored for zlib. 
103// first is the index of the first frame (usually 0). 
104int save_apng(char * szOut, std::vector<Image>& img, unsigned int loops, unsigned int first, int deflate_method, int iter); 
105 
106 
107
108 
109 
110#endif /* IMAGE_H */ 
111