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

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

Issue 243076: Move the JPEG and PNG codecs from base/gfx to app/gfx/codec. Move the classes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2006-2008 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
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 "app/gfx/codec/png_codec.h"
16 #include "base/basictypes.h" 17 #include "base/basictypes.h"
17 #include "base/command_line.h" 18 #include "base/command_line.h"
18 #include "base/file_util.h" 19 #include "base/file_util.h"
19 #include "base/gfx/png_decoder.h"
20 #include "base/gfx/png_encoder.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "base/process_util.h" 21 #include "base/process_util.h"
23 #include "base/scoped_ptr.h" 22 #include "base/scoped_ptr.h"
24 #include "base/string_util.h" 23 #include "base/string_util.h"
25 24
26 #if defined(OS_WIN) 25 #if defined(OS_WIN)
27 #include "windows.h" 26 #include "windows.h"
28 #endif 27 #endif
29 28
30 // Causes the app to remain open, waiting for pairs of filenames on stdin. 29 // Causes the app to remain open, waiting for pairs of filenames on stdin.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Creates the image from stdin with the given data length. On success, it 70 // Creates the image from stdin with the given data length. On success, it
72 // will return true. On failure, no other methods should be accessed. 71 // will return true. On failure, no other methods should be accessed.
73 bool CreateFromStdin(size_t byte_length) { 72 bool CreateFromStdin(size_t byte_length) {
74 if (byte_length == 0) 73 if (byte_length == 0)
75 return false; 74 return false;
76 75
77 scoped_array<unsigned char> source(new unsigned char[byte_length]); 76 scoped_array<unsigned char> source(new unsigned char[byte_length]);
78 if (fread(source.get(), 1, byte_length, stdin) != byte_length) 77 if (fread(source.get(), 1, byte_length, stdin) != byte_length)
79 return false; 78 return false;
80 79
81 if (!PNGDecoder::Decode(source.get(), byte_length, PNGDecoder::FORMAT_RGBA, 80 if (!gfx::PNGCodec::Decode(source.get(), byte_length,
82 &data_, &w_, &h_)) { 81 gfx::PNGCodec::FORMAT_RGBA,
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 FILE* f = file_util::OpenFile(std::string(filename), "rb");
93 if (!f) 93 if (!f)
94 return false; 94 return false;
95 95
96 std::vector<unsigned char> compressed; 96 std::vector<unsigned char> compressed;
97 const int buf_size = 1024; 97 const int buf_size = 1024;
98 unsigned char buf[buf_size]; 98 unsigned char buf[buf_size];
99 size_t num_read = 0; 99 size_t num_read = 0;
100 while ((num_read = fread(buf, 1, buf_size, f)) > 0) { 100 while ((num_read = fread(buf, 1, buf_size, f)) > 0) {
101 std::copy(buf, &buf[num_read], std::back_inserter(compressed)); 101 std::copy(buf, &buf[num_read], std::back_inserter(compressed));
102 } 102 }
103 103
104 file_util::CloseFile(f); 104 file_util::CloseFile(f);
105 105
106 if (!PNGDecoder::Decode(&compressed[0], compressed.size(), 106 if (!gfx::PNGCodec::Decode(&compressed[0], compressed.size(),
107 PNGDecoder::FORMAT_RGBA, &data_, &w_, &h_)) { 107 gfx::PNGCodec::FORMAT_RGBA, &data_, &w_, &h_)) {
108 Clear(); 108 Clear();
109 return false; 109 return false;
110 } 110 }
111 return true; 111 return true;
112 } 112 }
113 113
114 void Clear() { 114 void Clear() {
115 w_ = h_ = 0; 115 w_ = h_ = 0;
116 data_.clear(); 116 data_.clear();
117 } 117 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 fprintf(stderr, "image_diff: Unable to open file \"%s\"\n", file2); 301 fprintf(stderr, "image_diff: Unable to open file \"%s\"\n", file2);
302 return kStatusError; 302 return kStatusError;
303 } 303 }
304 304
305 Image diff_image; 305 Image diff_image;
306 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image); 306 bool same = CreateImageDiff(baseline_image, actual_image, &diff_image);
307 if (same) 307 if (same)
308 return kStatusSame; 308 return kStatusSame;
309 309
310 std::vector<unsigned char> png_encoding; 310 std::vector<unsigned char> png_encoding;
311 PNGEncoder::Encode(diff_image.data(), PNGEncoder::FORMAT_RGBA, 311 gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA,
312 diff_image.w(), diff_image.h(), diff_image.w() * 4, 312 diff_image.w(), diff_image.h(), diff_image.w() * 4,
313 false, &png_encoding); 313 false, &png_encoding);
314 if (file_util::WriteFile(UTF8ToWide(out_file), 314 if (file_util::WriteFile(UTF8ToWide(out_file),
315 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) 315 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0)
316 return kStatusError; 316 return kStatusError;
317 317
318 return kStatusDifferent; 318 return kStatusDifferent;
319 } 319 }
320 320
321 int main(int argc, const char* argv[]) { 321 int main(int argc, const char* argv[]) {
322 base::EnableTerminationOnHeapCorruption(); 322 base::EnableTerminationOnHeapCorruption();
323 CommandLine::Init(argc, argv); 323 CommandLine::Init(argc, argv);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 WideToUTF8(values[1]).c_str(), 355 WideToUTF8(values[1]).c_str(),
356 WideToUTF8(values[2]).c_str()); 356 WideToUTF8(values[2]).c_str());
357 } 357 }
358 } else if (values.size() == 2) { 358 } else if (values.size() == 2) {
359 return CompareImages(argv[1], argv[2]); 359 return CompareImages(argv[1], argv[2]);
360 } 360 }
361 361
362 PrintHelp(); 362 PrintHelp();
363 return kStatusError; 363 return kStatusError;
364 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698