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

Side by Side Diff: printing/image.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-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 #include "printing/image.h" 5 #include "printing/image.h"
6 6
7 #include "app/gfx/codec/png_codec.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
8 #include "base/gfx/png_decoder.h"
9 #include "base/gfx/png_encoder.h"
10 #include "base/gfx/rect.h" 9 #include "base/gfx/rect.h"
11 #include "base/md5.h" 10 #include "base/md5.h"
12 #include "base/string_util.h" 11 #include "base/string_util.h"
13 #include "skia/ext/platform_device.h" 12 #include "skia/ext/platform_device.h"
14 13
15 #if defined(OS_WIN) 14 #if defined(OS_WIN)
16 #include "base/gfx/gdi_util.h" // EMF support 15 #include "base/gfx/gdi_util.h" // EMF support
17 #endif 16 #endif
18 17
19 namespace { 18 namespace {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 93
95 std::string Image::checksum() const { 94 std::string Image::checksum() const {
96 MD5Digest digest; 95 MD5Digest digest;
97 MD5Sum(&data_[0], data_.size(), &digest); 96 MD5Sum(&data_[0], data_.size(), &digest);
98 return HexEncode(&digest, sizeof(digest)); 97 return HexEncode(&digest, sizeof(digest));
99 } 98 }
100 99
101 bool Image::SaveToPng(const std::wstring& filename) const { 100 bool Image::SaveToPng(const std::wstring& filename) const {
102 DCHECK(!data_.empty()); 101 DCHECK(!data_.empty());
103 std::vector<unsigned char> compressed; 102 std::vector<unsigned char> compressed;
104 bool success = PNGEncoder::Encode(&*data_.begin(), 103 bool success = gfx::PNGCodec::Encode(&*data_.begin(),
105 PNGEncoder::FORMAT_BGRA, 104 gfx::PNGCodec::FORMAT_BGRA,
106 size_.width(), 105 size_.width(),
107 size_.height(), 106 size_.height(),
108 row_length_, 107 row_length_,
109 true, 108 true,
110 &compressed); 109 &compressed);
111 DCHECK(success && compressed.size()); 110 DCHECK(success && compressed.size());
112 if (success) { 111 if (success) {
113 int write_bytes = file_util::WriteFile( 112 int write_bytes = file_util::WriteFile(
114 filename, 113 filename,
115 reinterpret_cast<char*>(&*compressed.begin()), compressed.size()); 114 reinterpret_cast<char*>(&*compressed.begin()), compressed.size());
116 success = (write_bytes == static_cast<int>(compressed.size())); 115 success = (write_bytes == static_cast<int>(compressed.size()));
117 DCHECK(success); 116 DCHECK(success);
118 } 117 }
119 return success; 118 return success;
120 } 119 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Like the WebKit ImageDiff tool, we define percentage different in terms 171 // Like the WebKit ImageDiff tool, we define percentage different in terms
173 // of the size of the 'actual' bitmap. 172 // of the size of the 'actual' bitmap.
174 double total_pixels = static_cast<double>(size_.width()) * 173 double total_pixels = static_cast<double>(size_.width()) *
175 static_cast<double>(height); 174 static_cast<double>(height);
176 return static_cast<double>(pixels_different) / total_pixels * 100.; 175 return static_cast<double>(pixels_different) / total_pixels * 100.;
177 } 176 }
178 177
179 bool Image::LoadPng(const std::string& compressed) { 178 bool Image::LoadPng(const std::string& compressed) {
180 int w; 179 int w;
181 int h; 180 int h;
182 bool success = PNGDecoder::Decode( 181 bool success = gfx::PNGCodec::Decode(
183 reinterpret_cast<const unsigned char*>(compressed.c_str()), 182 reinterpret_cast<const unsigned char*>(compressed.c_str()),
184 compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h); 183 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h);
185 size_.SetSize(w, h); 184 size_.SetSize(w, h);
186 row_length_ = size_.width() * sizeof(uint32); 185 row_length_ = size_.width() * sizeof(uint32);
187 return success; 186 return success;
188 } 187 }
189 188
190 bool Image::LoadMetafile(const std::string& data) { 189 bool Image::LoadMetafile(const std::string& data) {
191 DCHECK(!data.empty()); 190 DCHECK(!data.empty());
192 #if defined(OS_WIN) 191 #if defined(OS_WIN)
193 NativeMetafile metafile; 192 NativeMetafile metafile;
194 metafile.CreateFromData(data.data(), data.size()); 193 metafile.CreateFromData(data.data(), data.size());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return success; 230 return success;
232 } 231 }
233 #else 232 #else
234 NOTIMPLEMENTED(); 233 NOTIMPLEMENTED();
235 #endif 234 #endif
236 235
237 return false; 236 return false;
238 } 237 }
239 238
240 } // namespace printing 239 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698