| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // WebKitTools/DumpRenderTree/ImageDiff.m | 6 // WebKitTools/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 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/file_util.h" |
| 16 #include "base/gfx/png_decoder.h" | 17 #include "base/gfx/png_decoder.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 19 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
| 20 | 21 |
| 21 // Causes the app to remain open, waiting for pairs of filenames on stdin. | 22 // Causes the app to remain open, waiting for pairs of filenames on stdin. |
| 22 // The caller is then responsible for terminating this app. | 23 // The caller is then responsible for terminating this app. |
| 23 static const wchar_t kOptionPollStdin[] = L"use-stdin"; | 24 static const wchar_t kOptionPollStdin[] = L"use-stdin"; |
| 24 | 25 |
| 25 // Return codes used by this utility. | 26 // Return codes used by this utility. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 &data_, &w_, &h_)) { | 59 &data_, &w_, &h_)) { |
| 59 Clear(); | 60 Clear(); |
| 60 return false; | 61 return false; |
| 61 } | 62 } |
| 62 return true; | 63 return true; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Creates the image from the given filename on disk, and returns true on | 66 // Creates the image from the given filename on disk, and returns true on |
| 66 // success. | 67 // success. |
| 67 bool CreateFromFilename(const char* filename) { | 68 bool CreateFromFilename(const char* filename) { |
| 68 FILE* f; | 69 FILE* f = file_util::OpenFile(std::string(filename), "rb"); |
| 69 if (fopen_s(&f, filename, "rb") != 0) | 70 if (!f) |
| 70 return false; | 71 return false; |
| 71 | 72 |
| 72 std::vector<unsigned char> compressed; | 73 std::vector<unsigned char> compressed; |
| 73 const int buf_size = 1024; | 74 const int buf_size = 1024; |
| 74 unsigned char buf[buf_size]; | 75 unsigned char buf[buf_size]; |
| 75 size_t num_read = 0; | 76 size_t num_read = 0; |
| 76 while ((num_read = fread(buf, 1, buf_size, f)) > 0) { | 77 while ((num_read = fread(buf, 1, buf_size, f)) > 0) { |
| 77 std::copy(buf, &buf[num_read], std::back_inserter(compressed)); | 78 std::copy(buf, &buf[num_read], std::back_inserter(compressed)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 fclose(f); | 81 file_util::CloseFile(f); |
| 81 | 82 |
| 82 if (!PNGDecoder::Decode(&compressed[0], compressed.size(), | 83 if (!PNGDecoder::Decode(&compressed[0], compressed.size(), |
| 83 PNGDecoder::FORMAT_RGBA, &data_, &w_, &h_)) { | 84 PNGDecoder::FORMAT_RGBA, &data_, &w_, &h_)) { |
| 84 Clear(); | 85 Clear(); |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 return true; | 88 return true; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void Clear() { | 91 void Clear() { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 261 } |
| 261 | 262 |
| 262 if (argc == 3) { | 263 if (argc == 3) { |
| 263 return CompareImages(argv[1], argv[2]); | 264 return CompareImages(argv[1], argv[2]); |
| 264 } | 265 } |
| 265 | 266 |
| 266 PrintHelp(); | 267 PrintHelp(); |
| 267 return kStatusError; | 268 return kStatusError; |
| 268 } | 269 } |
| 269 | 270 |
| OLD | NEW |