Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: tools/imagediff/image_diff.cc

Issue 12217101: Replace FilePath with base::FilePath in some more top level directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file input format is based loosely on 5 // This file input format is based loosely on
6 // Tools/DumpRenderTree/ImageDiff.m 6 // Tools/DumpRenderTree/ImageDiff.m
7 7
8 // The exact format of this tool's output to stdout is important, to match 8 // The exact format of this tool's output to stdout is important, to match
9 // what the run-webkit-tests script expects. 9 // what the run-webkit-tests script expects.
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 gfx::PNGCodec::FORMAT_RGBA, 84 gfx::PNGCodec::FORMAT_RGBA,
85 &data_, &w_, &h_)) { 85 &data_, &w_, &h_)) {
86 Clear(); 86 Clear();
87 return false; 87 return false;
88 } 88 }
89 return true; 89 return true;
90 } 90 }
91 91
92 // Creates the image from the given filename on disk, and returns true on 92 // Creates the image from the given filename on disk, and returns true on
93 // success. 93 // success.
94 bool CreateFromFilename(const FilePath& path) { 94 bool CreateFromFilename(const base::FilePath& path) {
95 FILE* f = file_util::OpenFile(path, "rb"); 95 FILE* f = file_util::OpenFile(path, "rb");
96 if (!f) 96 if (!f)
97 return false; 97 return false;
98 98
99 std::vector<unsigned char> compressed; 99 std::vector<unsigned char> compressed;
100 const int buf_size = 1024; 100 const int buf_size = 1024;
101 unsigned char buf[buf_size]; 101 unsigned char buf[buf_size];
102 size_t num_read = 0; 102 size_t num_read = 0;
103 while ((num_read = fread(buf, 1, buf_size, f)) > 0) { 103 while ((num_read = fread(buf, 1, buf_size, f)) > 0) {
104 compressed.insert(compressed.end(), buf, buf + num_read); 104 compressed.insert(compressed.end(), buf, buf + num_read);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 /* For unfinished webkit-like-mode (see below) 186 /* For unfinished webkit-like-mode (see below)
187 "\n" 187 "\n"
188 " image_diff -s\n" 188 " image_diff -s\n"
189 " Reads stream input from stdin, should be EXACTLY of the format\n" 189 " Reads stream input from stdin, should be EXACTLY of the format\n"
190 " \"Content-length: <byte length> <data>Content-length: ...\n" 190 " \"Content-length: <byte length> <data>Content-length: ...\n"
191 " it will take as many file pairs as given, and will compare them as\n" 191 " it will take as many file pairs as given, and will compare them as\n"
192 " (cmp_file, reference_file) pairs\n"); 192 " (cmp_file, reference_file) pairs\n");
193 */ 193 */
194 } 194 }
195 195
196 int CompareImages(const FilePath& file1, const FilePath& file2) { 196 int CompareImages(const base::FilePath& file1, const base::FilePath& file2) {
197 Image actual_image; 197 Image actual_image;
198 Image baseline_image; 198 Image baseline_image;
199 199
200 if (!actual_image.CreateFromFilename(file1)) { 200 if (!actual_image.CreateFromFilename(file1)) {
201 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n", 201 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n",
202 file1.value().c_str()); 202 file1.value().c_str());
203 return kStatusError; 203 return kStatusError;
204 } 204 }
205 if (!baseline_image.CreateFromFilename(file2)) { 205 if (!baseline_image.CreateFromFilename(file2)) {
206 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n", 206 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n",
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 uint32 alpha = base_pixel & RGBA_ALPHA; 287 uint32 alpha = base_pixel & RGBA_ALPHA;
288 uint32 new_pixel = base_pixel - ((alpha / 2) & RGBA_ALPHA); 288 uint32 new_pixel = base_pixel - ((alpha / 2) & RGBA_ALPHA);
289 out->set_pixel_at(x, y, new_pixel); 289 out->set_pixel_at(x, y, new_pixel);
290 } 290 }
291 } 291 }
292 } 292 }
293 293
294 return same; 294 return same;
295 } 295 }
296 296
297 int DiffImages(const FilePath& file1, const FilePath& file2, 297 int DiffImages(const base::FilePath& file1, const base::FilePath& file2,
298 const FilePath& out_file) { 298 const base::FilePath& out_file) {
299 Image actual_image; 299 Image actual_image;
300 Image baseline_image; 300 Image baseline_image;
301 301
302 if (!actual_image.CreateFromFilename(file1)) { 302 if (!actual_image.CreateFromFilename(file1)) {
303 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n", 303 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n",
304 file1.value().c_str()); 304 file1.value().c_str());
305 return kStatusError; 305 return kStatusError;
306 } 306 }
307 if (!baseline_image.CreateFromFilename(file2)) { 307 if (!baseline_image.CreateFromFilename(file2)) {
308 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n", 308 fprintf(stderr, "image_diff: Unable to open file \"%" PRFilePath "\"\n",
(...skipping 14 matching lines...) Expand all
323 if (file_util::WriteFile(out_file, 323 if (file_util::WriteFile(out_file,
324 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) 324 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0)
325 return kStatusError; 325 return kStatusError;
326 326
327 return kStatusDifferent; 327 return kStatusDifferent;
328 } 328 }
329 329
330 // It isn't strictly correct to only support ASCII paths, but this 330 // It isn't strictly correct to only support ASCII paths, but this
331 // program reads paths on stdin and the program that spawns it outputs 331 // program reads paths on stdin and the program that spawns it outputs
332 // paths as non-wide strings anyway. 332 // paths as non-wide strings anyway.
333 FilePath FilePathFromASCII(const std::string& str) { 333 base::FilePath FilePathFromASCII(const std::string& str) {
334 #if defined(OS_WIN) 334 #if defined(OS_WIN)
335 return FilePath(ASCIIToWide(str)); 335 return base::FilePath(ASCIIToWide(str));
336 #else 336 #else
337 return FilePath(str); 337 return base::FilePath(str);
338 #endif 338 #endif
339 } 339 }
340 340
341 int main(int argc, const char* argv[]) { 341 int main(int argc, const char* argv[]) {
342 base::EnableTerminationOnHeapCorruption(); 342 base::EnableTerminationOnHeapCorruption();
343 CommandLine::Init(argc, argv); 343 CommandLine::Init(argc, argv);
344 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 344 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
345 if (parsed_command_line.HasSwitch(kOptionPollStdin)) { 345 if (parsed_command_line.HasSwitch(kOptionPollStdin)) {
346 // Watch stdin for filenames. 346 // Watch stdin for filenames.
347 std::string stdin_buffer; 347 std::string stdin_buffer;
348 FilePath filename1; 348 base::FilePath filename1;
349 while (std::getline(std::cin, stdin_buffer)) { 349 while (std::getline(std::cin, stdin_buffer)) {
350 if (stdin_buffer.empty()) 350 if (stdin_buffer.empty())
351 continue; 351 continue;
352 352
353 if (!filename1.empty()) { 353 if (!filename1.empty()) {
354 // CompareImages writes results to stdout unless an error occurred. 354 // CompareImages writes results to stdout unless an error occurred.
355 FilePath filename2 = FilePathFromASCII(stdin_buffer); 355 base::FilePath filename2 = FilePathFromASCII(stdin_buffer);
356 if (CompareImages(filename1, filename2) == kStatusError) 356 if (CompareImages(filename1, filename2) == kStatusError)
357 printf("error\n"); 357 printf("error\n");
358 fflush(stdout); 358 fflush(stdout);
359 filename1 = FilePath(); 359 filename1 = base::FilePath();
360 } else { 360 } else {
361 // Save the first filename in another buffer and wait for the second 361 // Save the first filename in another buffer and wait for the second
362 // filename to arrive via stdin. 362 // filename to arrive via stdin.
363 filename1 = FilePathFromASCII(stdin_buffer); 363 filename1 = FilePathFromASCII(stdin_buffer);
364 } 364 }
365 } 365 }
366 return 0; 366 return 0;
367 } 367 }
368 368
369 const CommandLine::StringVector& args = parsed_command_line.GetArgs(); 369 const CommandLine::StringVector& args = parsed_command_line.GetArgs();
370 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) { 370 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) {
371 if (args.size() == 3) { 371 if (args.size() == 3) {
372 return DiffImages(FilePath(args[0]), 372 return DiffImages(base::FilePath(args[0]),
373 FilePath(args[1]), 373 base::FilePath(args[1]),
374 FilePath(args[2])); 374 base::FilePath(args[2]));
375 } 375 }
376 } else if (args.size() == 2) { 376 } else if (args.size() == 2) {
377 return CompareImages(FilePath(args[0]), FilePath(args[1])); 377 return CompareImages(base::FilePath(args[0]), base::FilePath(args[1]));
378 } 378 }
379 379
380 PrintHelp(); 380 PrintHelp();
381 return kStatusError; 381 return kStatusError;
382 } 382 }
OLDNEW
« no previous file with comments | « tools/generate_library_loader/generate_library_loader.py ('k') | tools/memory_watcher/memory_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698