19 #ifndef PAGESPEED_KERNEL_IMAGE_TEST_UTILS_H_
20 #define PAGESPEED_KERNEL_IMAGE_TEST_UTILS_H_
29 namespace net_instaweb {
35 namespace image_compression {
37 class ScanlineReaderInterface;
41 const char kTestRootDir[] =
"/pagespeed/kernel/image/testdata/";
44 const char kGifTestDir[] =
"gif/";
45 const char kJpegTestDir[] =
"jpeg/";
46 const char kPngSuiteGifTestDir[] =
"pngsuite/gif/";
47 const char kPngSuiteTestDir[] =
"pngsuite/";
48 const char kPngTestDir[] =
"png/";
49 const char kWebpTestDir[] =
"webp/";
50 const char kResizedTestDir[] =
"resized/";
53 const char kMessagePatternAnimatedGif[] =
54 "*Unable to optimize image with * frames.";
55 const char kMessagePatternFailedToOpen[] =
"*Failed to open*";
56 const char kMessagePatternFailedToRead[] =
"*Failed to read*";
57 const char kMessagePatternLibJpegFailure[] =
"*libjpeg failed to*";
58 const char kMessagePatternLibpngError[] =
"*libpng error:*";
59 const char kMessagePatternLibpngFailure[] =
"*libpng failed to*";
60 const char kMessagePatternLibpngWarning[] =
"*libpng warning:*";
61 const char kMessagePatternPixelFormat[] =
"*Pixel format:*";
62 const char kMessagePatternStats[] =
"*Stats:*";
63 const char kMessagePatternUnexpectedEOF[] =
"*Unexpected EOF*";
64 const char kMessagePatternWritingToWebp[] =
"*Writing to webp:*";
69 size_t a_original_size,
70 size_t a_compressed_size_best,
71 size_t a_compressed_size_default,
74 int a_original_bit_depth,
75 int a_original_color_type,
76 int a_compressed_bit_depth,
77 int a_compressed_color_type) :
79 original_size(a_original_size),
80 compressed_size_best(a_compressed_size_best),
81 compressed_size_default(a_compressed_size_default),
84 original_bit_depth(a_original_bit_depth),
85 original_color_type(a_original_color_type),
86 compressed_bit_depth(a_compressed_bit_depth),
87 compressed_color_type(a_compressed_color_type) {
93 size_t compressed_size_best;
94 size_t compressed_size_default;
97 int original_bit_depth;
98 int original_color_type;
99 int compressed_bit_depth;
100 int compressed_color_type;
106 size_t a_original_size,
107 size_t a_compressed_size_best,
108 size_t a_compressed_size_default,
111 int a_original_bit_depth,
112 int a_original_color_type,
113 int a_compressed_bit_depth,
114 int a_compressed_color_type,
115 bool a_transparency) :
118 a_compressed_size_best,
119 a_compressed_size_default,
122 a_original_bit_depth,
123 a_original_color_type,
124 a_compressed_bit_depth,
125 a_compressed_color_type),
126 transparency(a_transparency) {
134 GoldImageCompressionInfo(
"basi0g01", 153, 166, 166, 32, 32, 8, 3, 1, 3,
136 GoldImageCompressionInfo(
"basi0g02", 185, 112, 112, 32, 32, 8, 3, 2, 3,
138 GoldImageCompressionInfo(
"basi0g04", 344, 144, 186, 32, 32, 8, 3, 4, 3,
140 GoldImageCompressionInfo(
"basi0g08", 1736, 116, 714, 32, 32, 8, 3, 8, 0,
142 GoldImageCompressionInfo(
"basi3p01", 138, 96, 96, 32, 32, 8, 3, 1, 3,
144 GoldImageCompressionInfo(
"basi3p02", 186, 115, 115, 32, 32, 8, 3, 2, 3,
146 GoldImageCompressionInfo(
"basi3p04", 344, 185, 185, 32, 32, 8, 3, 4, 3,
148 GoldImageCompressionInfo(
"basi3p08", 1737, 1270, 1270, 32, 32, 8, 3, 8, 3,
150 GoldImageCompressionInfo(
"basn0g01", 153, 166, 166, 32, 32, 8, 3, 1, 3,
152 GoldImageCompressionInfo(
"basn0g02", 185, 112, 112, 32, 32, 8, 3, 2, 3,
154 GoldImageCompressionInfo(
"basn0g04", 344, 144, 186, 32, 32, 8, 3, 4, 3,
156 GoldImageCompressionInfo(
"basn0g08", 1736, 116, 714, 32, 32, 8, 3, 8, 0,
158 GoldImageCompressionInfo(
"basn3p01", 138, 96, 96, 32, 32, 8, 3, 1, 3,
160 GoldImageCompressionInfo(
"basn3p02", 186, 115, 115, 32, 32, 8, 3, 2, 3,
162 GoldImageCompressionInfo(
"basn3p04", 344, 185, 185, 32, 32, 8, 3, 4, 3,
164 GoldImageCompressionInfo(
"basn3p08", 1737, 1270, 1270, 32, 32, 8, 3, 8, 3,
169 GoldImageCompressionInfo(
"tr-basi4a08", 467, 239, 316, 32, 32, 8, 3, 8, 3,
171 GoldImageCompressionInfo(
"tr-basn4a08", 467, 239, 316, 32, 32, 8, 3, 8, 3,
174 const size_t kValidGifImageCount = arraysize(kValidGifImages);
181 const char* extension,
185 const char* name_with_extension,
188 void DecodeAndCompareImages(
189 pagespeed::image_compression::ImageFormat image_format1,
190 const void* image_buffer1,
191 size_t buffer_length1,
192 pagespeed::image_compression::ImageFormat image_format2,
193 const void* image_buffer2,
194 size_t buffer_length2,
195 bool ignore_transparent_rgb,
196 MessageHandler* message_handler);
198 void DecodeAndCompareImagesByPSNR(
199 pagespeed::image_compression::ImageFormat image_format1,
200 const void* image_buffer1,
201 size_t buffer_length1,
202 pagespeed::image_compression::ImageFormat image_format2,
203 const void* image_buffer2,
204 size_t buffer_length2,
206 bool ignore_transparent_rgb,
208 MessageHandler* message_handler);
211 void CompareImageReaders(ScanlineReaderInterface* reader1,
212 ScanlineReaderInterface* reader2);
221 void CompareImageRegions(
const uint8_t* image1, PixelFormat format1,
222 int bytes_per_row1,
int col1,
int row1,
223 const uint8_t* image2, PixelFormat format2,
224 int bytes_per_row2,
int col2,
int row2,
225 int num_cols,
int num_rows, MessageHandler* handler);
230 void ComparePixelsByPSNR(
const uint8_t* image1,
const uint8_t* image2,
231 PixelFormat format,
int num_rows,
int num_cols,
232 double min_psnr,
bool ignore_transparent_rgb,
233 MessageHandler* handler);
242 void CompareImageRegionsByPSNR(
const uint8_t* image1, PixelFormat format1,
243 int bytes_per_row1,
int col1,
int row1,
244 const uint8_t* image2, PixelFormat format2,
245 int bytes_per_row2,
int col2,
int row2,
246 int num_cols,
int num_rows,
double min_psnr,
247 bool ignore_transparent_rgb,
248 bool expand_colors, MessageHandler* handler);
258 void SynthesizeImage(
int width,
int height,
int bytes_per_line,
259 int num_channels,
const uint8_t* seed_value,
260 const int* delta_x,
const int* delta_y, uint8_t* image);
265 inline GoogleString PixelRgbaChannelsToString(
const uint8_t*
const channels) {
266 return StringPrintf(
"%02hhx%02hhx%02hhx%02hhx",
268 channels[RGBA_GREEN],
270 channels[RGBA_ALPHA]);
274 inline uint32_t PackAsRgba(uint8_t alpha,
278 return PackHiToLo(red, green, blue, alpha);
283 inline uint32_t RgbaToPackedRgba(
const PixelRgbaChannels rgba) {
284 return PackAsRgba(rgba[RGBA_ALPHA],
291 bool CompareAnimatedImages(
const GoogleString& expected_image_filename,
293 MessageHandler* message_handler);
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: test_utils.h:66
Definition: test_utils.h:103
Definition: message_handler.h:39