| 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 #include <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/codec/jpeg_codec.h" | 9 #include "ui/gfx/codec/jpeg_codec.h" |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 static double jpeg_equality_threshold = 1.0; | 69 static double jpeg_equality_threshold = 1.0; |
| 70 | 70 |
| 71 // Computes the average difference between each value in a and b. A and b | 71 // Computes the average difference between each value in a and b. A and b |
| 72 // should be the same size. Used to see if two images are approximately equal | 72 // should be the same size. Used to see if two images are approximately equal |
| 73 // in the presence of compression. | 73 // in the presence of compression. |
| 74 static double AveragePixelDelta(const std::vector<unsigned char>& a, | 74 static double AveragePixelDelta(const std::vector<unsigned char>& a, |
| 75 const std::vector<unsigned char>& b) { | 75 const std::vector<unsigned char>& b) { |
| 76 // if the sizes are different, say the average difference is the maximum | 76 // if the sizes are different, say the average difference is the maximum |
| 77 if (a.size() != b.size()) | 77 if (a.size() != b.size()) |
| 78 return 255.0; | 78 return 255.0; |
| 79 if (a.size() == 0) | 79 if (a.empty()) |
| 80 return 0; // prevent divide by 0 below | 80 return 0; // prevent divide by 0 below |
| 81 | 81 |
| 82 double acc = 0.0; | 82 double acc = 0.0; |
| 83 for (size_t i = 0; i < a.size(); i++) | 83 for (size_t i = 0; i < a.size(); i++) |
| 84 acc += fabs(static_cast<double>(a[i]) - static_cast<double>(b[i])); | 84 acc += fabs(static_cast<double>(a[i]) - static_cast<double>(b[i])); |
| 85 | 85 |
| 86 return acc / static_cast<double>(a.size()); | 86 return acc / static_cast<double>(a.size()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static void MakeRGBImage(int w, int h, std::vector<unsigned char>* dat) { | 89 static void MakeRGBImage(int w, int h, std::vector<unsigned char>* dat) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 JPEGCodec::FORMAT_RGB, &output, | 208 JPEGCodec::FORMAT_RGB, &output, |
| 209 &outw, &outh); | 209 &outw, &outh); |
| 210 | 210 |
| 211 JPEGCodec::Decode(kTopSitesMigrationTestImage, | 211 JPEGCodec::Decode(kTopSitesMigrationTestImage, |
| 212 arraysize(kTopSitesMigrationTestImage), | 212 arraysize(kTopSitesMigrationTestImage), |
| 213 JPEGCodec::FORMAT_RGBA, &output, | 213 JPEGCodec::FORMAT_RGBA, &output, |
| 214 &outw, &outh); | 214 &outw, &outh); |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace gfx | 217 } // namespace gfx |
| OLD | NEW |