github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/test/test_util.h (about)

     1  // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #ifndef TEST_UTIL_H_
     6  #define TEST_UTIL_H_
     7  
     8  #include <math.h>
     9  #include <string>
    10  
    11  // int arr[5][3];
    12  // assert(TEST_DIM(arr) == 5);
    13  // assert(TEST_DIM(arr[0]) == 3);
    14  #ifndef TEST_DIM
    15  #define TEST_DIM(x) ((sizeof(x))/(sizeof((x)[0])))
    16  #endif
    17  
    18  bool DecodeJpeg(
    19  	std::string* dst, const char* data, int size,
    20  	int* width, int* height, int* channels
    21  );
    22  
    23  bool EncodeJpeg(
    24  	std::string* dst, const char* data, int size,
    25  	int width, int height, int channels, int quality /* =90 */,
    26  	int width_step /* =0 */
    27  );
    28  
    29  bool DecodePng32(
    30  	std::string* dst, const char* data, int size,
    31  	int* width, int* height
    32  );
    33  
    34  bool DecodePng24(
    35  	std::string* dst, const char* data, int size,
    36  	int* width, int* height
    37  );
    38  
    39  bool EncodePng32(
    40  	std::string* dst, const char* data, int size,
    41  	int width, int height, int width_step /*=0*/
    42  );
    43  
    44  bool EncodePng24(
    45  	std::string* dst, const char* data, int size,
    46  	int width, int height, int width_step /*=0*/
    47  );
    48  
    49  bool LoadFileData(const char* name, std::string* data);
    50  bool SaveFileData(const char* name, const char* data, int size);
    51  
    52  template<typename T> double DiffImageData(
    53  	const T* b0, const T* b1,
    54  	int width, int height, int channels
    55  ) {
    56  	double sum = 0;
    57  	int n = width*height*channels;
    58  	for(int i = 0; i < n; ++i) {
    59  		sum += abs(int(b0[i])-int(b1[i]));
    60  	}
    61  	return sum/n;
    62  }
    63  
    64  #endif // TEST_UTIL_H_
    65