github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/jxr/jxrlib/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 jpegDecode( 19 std::string* dst, const char* data, int size, 20 int* width, int* height, int* channels 21 ); 22 23 bool jpegEncode( 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 loadImageData(const char* name, std::string* data); 30 bool saveImageData(const char* name, const char* data, int size); 31 32 template<typename T> double diffImageData( 33 const T* b0, const T* b1, 34 int width, int height, int channels 35 ) { 36 double sum = 0; 37 int n = width*height*channels; 38 for(int i = 0; i < n; ++i) { 39 sum += abs(int(b0[i])-int(b1[i])); 40 } 41 return sum/n; 42 } 43 44 #endif // TEST_UTIL_H_ 45