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

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

Issue 2850042: Deprecate more old filepath functions. (Closed)
Patch Set: rebase Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 &data_, &w_, &h_)) { 82 &data_, &w_, &h_)) {
83 Clear(); 83 Clear();
84 return false; 84 return false;
85 } 85 }
86 return true; 86 return true;
87 } 87 }
88 88
89 // Creates the image from the given filename on disk, and returns true on 89 // Creates the image from the given filename on disk, and returns true on
90 // success. 90 // success.
91 bool CreateFromFilename(const char* filename) { 91 bool CreateFromFilename(const char* filename) {
92 FILE* f = file_util::OpenFile(std::string(filename), "rb"); 92 FilePath path = FilePath::FromWStringHack(ASCIIToWide(filename));
93 FILE* f = file_util::OpenFile(path, "rb");
93 if (!f) 94 if (!f)
94 return false; 95 return false;
95 96
96 std::vector<unsigned char> compressed; 97 std::vector<unsigned char> compressed;
97 const int buf_size = 1024; 98 const int buf_size = 1024;
98 unsigned char buf[buf_size]; 99 unsigned char buf[buf_size];
99 size_t num_read = 0; 100 size_t num_read = 0;
100 while ((num_read = fread(buf, 1, buf_size, f)) > 0) { 101 while ((num_read = fread(buf, 1, buf_size, f)) > 0) {
101 std::copy(buf, &buf[num_read], std::back_inserter(compressed)); 102 std::copy(buf, &buf[num_read], std::back_inserter(compressed));
102 } 103 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 305
305 Image diff_image; 306 Image diff_image;
306 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image); 307 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image);
307 if (same) 308 if (same)
308 return kStatusSame; 309 return kStatusSame;
309 310
310 std::vector<unsigned char> png_encoding; 311 std::vector<unsigned char> png_encoding;
311 gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA, 312 gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA,
312 diff_image.w(), diff_image.h(), diff_image.w() * 4, 313 diff_image.w(), diff_image.h(), diff_image.w() * 4,
313 false, &png_encoding); 314 false, &png_encoding);
314 if (file_util::WriteFile(UTF8ToWide(out_file), 315 FilePath out_path = FilePath::FromWStringHack(ASCIIToWide(out_file));
316 if (file_util::WriteFile(out_path,
315 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) 317 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0)
316 return kStatusError; 318 return kStatusError;
317 319
318 return kStatusDifferent; 320 return kStatusDifferent;
319 } 321 }
320 322
321 int main(int argc, const char* argv[]) { 323 int main(int argc, const char* argv[]) {
322 base::EnableTerminationOnHeapCorruption(); 324 base::EnableTerminationOnHeapCorruption();
323 CommandLine::Init(argc, argv); 325 CommandLine::Init(argc, argv);
324 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 326 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
(...skipping 30 matching lines...) Expand all
355 WideToUTF8(values[1]).c_str(), 357 WideToUTF8(values[1]).c_str(),
356 WideToUTF8(values[2]).c_str()); 358 WideToUTF8(values[2]).c_str());
357 } 359 }
358 } else if (values.size() == 2) { 360 } else if (values.size() == 2) {
359 return CompareImages(argv[1], argv[2]); 361 return CompareImages(argv[1], argv[2]);
360 } 362 }
361 363
362 PrintHelp(); 364 PrintHelp();
363 return kStatusError; 365 return kStatusError;
364 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698