1// Copyright 2013 Google Inc. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14// 15// Author: lode.vandevenne@gmail.com (Lode Vandevenne) 16// Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala) 17 18// Library to recompress and optimize PNG images. Uses Zopfli as the compression 19// backend, chooses optimal PNG color model, and tries out several PNG filter 20// strategies. 21 22#ifndef ZOPFLIPNG_LIB_H_ 23#define ZOPFLIPNG_LIB_H_ 24 25#include <string> 26#include <vector> 27 28enum ZopfliPNGFilterStrategy { 29 kStrategyZero = 0, 30 kStrategyOne = 1, 31 kStrategyTwo = 2, 32 kStrategyThree = 3, 33 kStrategyFour = 4, 34 kStrategyMinSum, 35 kStrategyEntropy, 36 kStrategyPredefined, 37 kStrategyBruteForce, 38 kNumFilterStrategies /* Not a strategy but used for the size of this enum */ 39}; 40 41struct ZopfliPNGOptions { 42 ZopfliPNGOptions(); 43 44 // Allow altering hidden colors of fully transparent pixels 45 bool lossy_transparent; 46 // Convert 16-bit per channel images to 8-bit per channel 47 bool lossy_8bit; 48 49 // Filter strategies to try 50 std::vector<ZopfliPNGFilterStrategy> filter_strategies; 51 52 // Automatically choose filter strategy using less good compression 53 bool auto_filter_strategy; 54 55 // PNG chunks to keep 56 // chunks to literally copy over from the original PNG to the resulting one 57 std::vector<std::string> keepchunks; 58 59 // Use Zopfli deflate compression 60 bool use_zopfli; 61 62 // Zopfli number of iterations 63 int num_iterations; 64 65 // Zopfli number of iterations on large images 66 int num_iterations_large; 67 68 // 0=none, 1=first, 2=last, 3=both 69 int block_split_strategy; 70}; 71 72// Returns 0 on success, error code otherwise. 73// If verbose is true, it will print some info while working. 74int ZopfliPNGOptimize(const std::vector<unsigned char>& origpng, 75 const ZopfliPNGOptions& png_options, 76 bool verbose, 77 std::vector<unsigned char>* resultpng); 78 79#endif // ZOPFLIPNG_LIB_H_ 80