OLD | NEW |
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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <vector> | 12 #include <vector> |
13 #include <string> | 13 #include <string> |
14 #include <iostream> | 14 #include <iostream> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 23 #include "base/safe_numerics.h" |
23 #include "base/string_util.h" | 24 #include "base/string_util.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
25 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "windows.h" | 30 #include "windows.h" |
30 #endif | 31 #endif |
31 | 32 |
32 // Causes the app to remain open, waiting for pairs of filenames on stdin. | 33 // Causes the app to remain open, waiting for pairs of filenames on stdin. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image); | 315 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image); |
315 if (same) | 316 if (same) |
316 return kStatusSame; | 317 return kStatusSame; |
317 | 318 |
318 std::vector<unsigned char> png_encoding; | 319 std::vector<unsigned char> png_encoding; |
319 gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA, | 320 gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA, |
320 gfx::Size(diff_image.w(), diff_image.h()), | 321 gfx::Size(diff_image.w(), diff_image.h()), |
321 diff_image.w() * 4, false, | 322 diff_image.w() * 4, false, |
322 std::vector<gfx::PNGCodec::Comment>(), &png_encoding); | 323 std::vector<gfx::PNGCodec::Comment>(), &png_encoding); |
323 if (file_util::WriteFile(out_file, | 324 if (file_util::WriteFile(out_file, |
324 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) | 325 reinterpret_cast<char*>(&png_encoding.front()), |
| 326 base::checked_numeric_cast<int>(png_encoding.size())) < 0) |
325 return kStatusError; | 327 return kStatusError; |
326 | 328 |
327 return kStatusDifferent; | 329 return kStatusDifferent; |
328 } | 330 } |
329 | 331 |
330 // It isn't strictly correct to only support ASCII paths, but this | 332 // 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 | 333 // program reads paths on stdin and the program that spawns it outputs |
332 // paths as non-wide strings anyway. | 334 // paths as non-wide strings anyway. |
333 base::FilePath FilePathFromASCII(const std::string& str) { | 335 base::FilePath FilePathFromASCII(const std::string& str) { |
334 #if defined(OS_WIN) | 336 #if defined(OS_WIN) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 base::FilePath(args[1]), | 375 base::FilePath(args[1]), |
374 base::FilePath(args[2])); | 376 base::FilePath(args[2])); |
375 } | 377 } |
376 } else if (args.size() == 2) { | 378 } else if (args.size() == 2) { |
377 return CompareImages(base::FilePath(args[0]), base::FilePath(args[1])); | 379 return CompareImages(base::FilePath(args[0]), base::FilePath(args[1])); |
378 } | 380 } |
379 | 381 |
380 PrintHelp(); | 382 PrintHelp(); |
381 return kStatusError; | 383 return kStatusError; |
382 } | 384 } |
OLD | NEW |