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

Side by Side Diff: printing/image.cc

Issue 6696085: Add the ability to write comments to PNGCodec::Encode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with webkit_support function Created 9 years, 9 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) 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 "printing/image.h" 5 #include "printing/image.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 MD5Digest digest; 53 MD5Digest digest;
54 MD5Sum(&data_[0], data_.size(), &digest); 54 MD5Sum(&data_[0], data_.size(), &digest);
55 return base::HexEncode(&digest, sizeof(digest)); 55 return base::HexEncode(&digest, sizeof(digest));
56 } 56 }
57 57
58 bool Image::SaveToPng(const FilePath& filepath) const { 58 bool Image::SaveToPng(const FilePath& filepath) const {
59 DCHECK(!data_.empty()); 59 DCHECK(!data_.empty());
60 std::vector<unsigned char> compressed; 60 std::vector<unsigned char> compressed;
61 bool success = gfx::PNGCodec::Encode(&*data_.begin(), 61 bool success = gfx::PNGCodec::Encode(&*data_.begin(),
62 gfx::PNGCodec::FORMAT_BGRA, 62 gfx::PNGCodec::FORMAT_BGRA,
63 size_.width(), 63 size_,
64 size_.height(),
65 row_length_, 64 row_length_,
66 true, 65 true,
66 std::vector<gfx::PNGCodec::Comment>(),
67 &compressed); 67 &compressed);
68 DCHECK(success && compressed.size()); 68 DCHECK(success && compressed.size());
69 if (success) { 69 if (success) {
70 int write_bytes = file_util::WriteFile( 70 int write_bytes = file_util::WriteFile(
71 filepath, 71 filepath,
72 reinterpret_cast<char*>(&*compressed.begin()), compressed.size()); 72 reinterpret_cast<char*>(&*compressed.begin()), compressed.size());
73 success = (write_bytes == static_cast<int>(compressed.size())); 73 success = (write_bytes == static_cast<int>(compressed.size()));
74 DCHECK(success); 74 DCHECK(success);
75 } 75 }
76 return success; 76 return success;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 bool Image::LoadMetafile(const std::string& data) { 147 bool Image::LoadMetafile(const std::string& data) {
148 DCHECK(!data.empty()); 148 DCHECK(!data.empty());
149 scoped_ptr<NativeMetafile> metafile( 149 scoped_ptr<NativeMetafile> metafile(
150 printing::NativeMetafileFactory::Create()); 150 printing::NativeMetafileFactory::Create());
151 metafile->InitFromData(data.data(), data.size()); 151 metafile->InitFromData(data.data(), data.size());
152 return LoadMetafile(*metafile); 152 return LoadMetafile(*metafile);
153 } 153 }
154 154
155 } // namespace printing 155 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698