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

Side by Side Diff: ui/gfx/codec/png_codec.cc

Issue 2944633002: Use SkPngEncoder in gfx jpeg_codec (Closed)
Patch Set: Created 3 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/codec/png_codec.h" 5 #include "ui/gfx/codec/png_codec.h"
6 #include "ui/gfx/codec/codec_priv.h"
6 7
7 #include <stdint.h> 8 #include <stdint.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "third_party/libpng/png.h" 13 #include "third_party/libpng/png.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/skia/include/core/SkColorPriv.h" 15 #include "third_party/skia/include/core/SkColorPriv.h"
15 #include "third_party/skia/include/core/SkUnPreMultiply.h" 16 #include "third_party/skia/include/core/SkUnPreMultiply.h"
17 #include "third_party/skia/include/encode/SkPngEncoder.h"
16 #include "third_party/zlib/zlib.h" 18 #include "third_party/zlib/zlib.h"
17 #include "ui/gfx/geometry/size.h" 19 #include "ui/gfx/geometry/size.h"
18 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
19 21
20 namespace gfx { 22 namespace gfx {
21 23
22 namespace { 24 namespace {
23 25
24 // Converts BGRA->RGBA and RGBA->BGRA. 26 // Converts BGRA->RGBA and RGBA->BGRA.
25 void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width, 27 void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width,
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 inputAddr, 727 inputAddr,
726 PNGCodec::FORMAT_SkBitmap, 728 PNGCodec::FORMAT_SkBitmap,
727 Size(input.width(), input.height()), 729 Size(input.width(), input.height()),
728 static_cast<int>(input.rowBytes()), 730 static_cast<int>(input.rowBytes()),
729 discard_transparency, 731 discard_transparency,
730 std::vector<PNGCodec::Comment>(), 732 std::vector<PNGCodec::Comment>(),
731 compression_level, 733 compression_level,
732 output); 734 output);
733 } 735 }
734 736
737 static void AddComments(SkPngEncoder::Options& options,
738 const std::vector<PNGCodec::Comment>& comments) {
739 std::vector<const char*> commentPointers;
740 std::vector<size_t> commentSizes;
741 for (const auto& comment : comments) {
742 commentPointers.push_back(comment.key.c_str());
743 commentPointers.push_back(comment.text.c_str());
744 commentSizes.push_back(comment.key.length() + 1);
745 commentSizes.push_back(comment.text.length() + 1);
746 }
747 options.fComments =
748 SkDataTable::MakeCopyArrays((void const* const*)commentPointers.data(),
749 commentSizes.data(), commentPointers.size());
750 }
735 751
736 } // namespace 752 } // namespace
737 753
738 // static 754 // static
739 bool PNGCodec::Encode(const unsigned char* input, 755 bool PNGCodec::Encode(const SkPixmap& src,
740 ColorFormat format,
741 const Size& size,
742 int row_byte_width,
743 bool discard_transparency,
msarett1 2017/06/16 21:29:56 As we discussed in person, you'll have to find a w
liyuqian 2017/06/23 13:54:25 Done.
744 const std::vector<Comment>& comments, 756 const std::vector<Comment>& comments,
745 std::vector<unsigned char>* output) { 757 std::vector<unsigned char>* output) {
746 return EncodeWithCompressionLevel(input, 758 output->clear();
747 format, 759 VectorWStream dst(output);
748 size, 760
749 row_byte_width, 761 SkPngEncoder::Options options;
750 discard_transparency, 762 AddComments(options, comments);
751 comments, 763 return SkPngEncoder::Encode(&dst, src, options);
752 Z_DEFAULT_COMPRESSION,
753 output);
754 } 764 }
755 765
756 // static 766 // static
757 bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input, 767 bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input,
758 bool discard_transparency, 768 bool discard_transparency,
759 std::vector<unsigned char>* output) { 769 std::vector<unsigned char>* output) {
760 return InternalEncodeSkBitmap(input, 770 return InternalEncodeSkBitmap(input,
761 discard_transparency, 771 discard_transparency,
762 Z_DEFAULT_COMPRESSION, 772 Z_DEFAULT_COMPRESSION,
763 output); 773 output);
(...skipping 19 matching lines...) Expand all
783 } 793 }
784 794
785 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) 795 PNGCodec::Comment::Comment(const std::string& k, const std::string& t)
786 : key(k), text(t) { 796 : key(k), text(t) {
787 } 797 }
788 798
789 PNGCodec::Comment::~Comment() { 799 PNGCodec::Comment::~Comment() {
790 } 800 }
791 801
792 } // namespace gfx 802 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698