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

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

Issue 396133002: ui/gfx: cleanup: change a function name for readability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "third_party/libpng/png.h" 9 #include "third_party/libpng/png.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 19 matching lines...) Expand all
30 pixel_out[3] = pixel_in[3]; 30 pixel_out[3] = pixel_in[3];
31 } 31 }
32 } 32 }
33 33
34 void ConvertRGBAtoRGB(const unsigned char* rgba, int pixel_width, 34 void ConvertRGBAtoRGB(const unsigned char* rgba, int pixel_width,
35 unsigned char* rgb, bool* is_opaque) { 35 unsigned char* rgb, bool* is_opaque) {
36 for (int x = 0; x < pixel_width; x++) 36 for (int x = 0; x < pixel_width; x++)
37 memcpy(&rgb[x * 3], &rgba[x * 4], 3); 37 memcpy(&rgb[x * 3], &rgba[x * 4], 3);
38 } 38 }
39 39
40 void ConvertSkiatoRGB(const unsigned char* skia, int pixel_width, 40 void ConvertSkiaToRGB(const unsigned char* skia, int pixel_width,
41 unsigned char* rgb, bool* is_opaque) { 41 unsigned char* rgb, bool* is_opaque) {
42 for (int x = 0; x < pixel_width; x++) { 42 for (int x = 0; x < pixel_width; x++) {
43 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[x * 4]); 43 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[x * 4]);
44 unsigned char* pixel_out = &rgb[x * 3]; 44 unsigned char* pixel_out = &rgb[x * 3];
45 45
46 int alpha = SkGetPackedA32(pixel_in); 46 int alpha = SkGetPackedA32(pixel_in);
47 if (alpha != 0 && alpha != 255) { 47 if (alpha != 0 && alpha != 255) {
48 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); 48 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in);
49 pixel_out[0] = SkColorGetR(unmultiplied); 49 pixel_out[0] = SkColorGetR(unmultiplied);
50 pixel_out[1] = SkColorGetG(unmultiplied); 50 pixel_out[1] = SkColorGetG(unmultiplied);
51 pixel_out[2] = SkColorGetB(unmultiplied); 51 pixel_out[2] = SkColorGetB(unmultiplied);
52 } else { 52 } else {
53 pixel_out[0] = SkGetPackedR32(pixel_in); 53 pixel_out[0] = SkGetPackedR32(pixel_in);
54 pixel_out[1] = SkGetPackedG32(pixel_in); 54 pixel_out[1] = SkGetPackedG32(pixel_in);
55 pixel_out[2] = SkGetPackedB32(pixel_in); 55 pixel_out[2] = SkGetPackedB32(pixel_in);
56 } 56 }
57 } 57 }
58 } 58 }
59 59
60 void ConvertSkiatoRGBA(const unsigned char* skia, int pixel_width, 60 void ConvertSkiaToRGBA(const unsigned char* skia, int pixel_width,
61 unsigned char* rgba, bool* is_opaque) { 61 unsigned char* rgba, bool* is_opaque) {
62 gfx::ConvertSkiaToRGBA(skia, pixel_width, rgba); 62 gfx::ConvertSkiaToRGBA(skia, pixel_width, rgba);
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 // Decoder -------------------------------------------------------------------- 67 // Decoder --------------------------------------------------------------------
68 // 68 //
69 // This code is based on WebKit libpng interface (PNGImageDecoder), which is 69 // This code is based on WebKit libpng interface (PNGImageDecoder), which is
70 // in turn based on the Mozilla png decoder. 70 // in turn based on the Mozilla png decoder.
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // color intensity. 681 // color intensity.
682 input_color_components = 1; 682 input_color_components = 1;
683 output_color_components = 1; 683 output_color_components = 1;
684 png_output_color_type = PNG_COLOR_TYPE_GRAY; 684 png_output_color_type = PNG_COLOR_TYPE_GRAY;
685 // |converter| is left as null 685 // |converter| is left as null
686 } else { 686 } else {
687 input_color_components = 4; 687 input_color_components = 4;
688 if (discard_transparency) { 688 if (discard_transparency) {
689 output_color_components = 3; 689 output_color_components = 3;
690 png_output_color_type = PNG_COLOR_TYPE_RGB; 690 png_output_color_type = PNG_COLOR_TYPE_RGB;
691 converter = ConvertSkiatoRGB; 691 converter = ConvertSkiaToRGB;
692 } else { 692 } else {
693 output_color_components = 4; 693 output_color_components = 4;
694 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; 694 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
695 converter = ConvertSkiatoRGBA; 695 converter = ConvertSkiaToRGBA;
696 } 696 }
697 } 697 }
698 break; 698 break;
699 699
700 default: 700 default:
701 NOTREACHED() << "Unknown pixel format"; 701 NOTREACHED() << "Unknown pixel format";
702 return false; 702 return false;
703 } 703 }
704 704
705 // Row stride should be at least as long as the length of the data. 705 // Row stride should be at least as long as the length of the data.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 801 }
802 802
803 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) 803 PNGCodec::Comment::Comment(const std::string& k, const std::string& t)
804 : key(k), text(t) { 804 : key(k), text(t) {
805 } 805 }
806 806
807 PNGCodec::Comment::~Comment() { 807 PNGCodec::Comment::~Comment() {
808 } 808 }
809 809
810 } // namespace gfx 810 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698