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

Unified Diff: ui/gfx/codec/png_codec.cc

Issue 136453009: Fix for Issue 331895: Make gesturenav screenshot greyscale (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improving the logic for format detection in EncodeWithCompressionLevel() Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/codec/png_codec.h ('K') | « ui/gfx/codec/png_codec.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/codec/png_codec.cc
diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc
index b3f4345343f0d15a49c0cfc9c759bed662cc4189..201b7a6b8a6ade309df1cffe4a380800450636b7 100644
--- a/ui/gfx/codec/png_codec.cc
+++ b/ui/gfx/codec/png_codec.cc
@@ -678,15 +678,29 @@ bool EncodeWithCompressionLevel(const unsigned char* input,
break;
case PNGCodec::FORMAT_SkBitmap:
- input_color_components = 4;
- if (discard_transparency) {
- output_color_components = 3;
- png_output_color_type = PNG_COLOR_TYPE_RGB;
- converter = ConvertSkiatoRGB;
+ // Compare row_byte_width and size.width() to detect the format of
+ // SkBitmap. kA8_Config (1bpp) and kARGB_8888_Config (4bpp) are the two
+ // supported formats
Peter Kasting 2014/01/25 03:29:58 Nit: Trailing period
mfomitchev 2014/01/27 17:15:28 Done.
+ if (row_byte_width < 4 * size.width()) {
+ // Not 4bpp, so must be 1bpp.
+ // Ignore discard_transparency - it doesn't make sense in this context,
+ // since alpha is the only thing we have and it needs to be used for
+ // color intensity.
+ input_color_components = 1;
+ output_color_components = 1;
+ png_output_color_type = PNG_COLOR_TYPE_GRAY;
+ //converter = NULL;
Peter Kasting 2014/01/25 03:29:58 Nit: Remove this line. If you need to explain tha
mfomitchev 2014/01/27 17:15:28 Done.
} else {
- output_color_components = 4;
- png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
- converter = ConvertSkiatoRGBA;
+ input_color_components = 4;
+ if (discard_transparency) {
+ output_color_components = 3;
+ png_output_color_type = PNG_COLOR_TYPE_RGB;
+ converter = ConvertSkiatoRGB;
+ } else {
+ output_color_components = 4;
+ png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ converter = ConvertSkiatoRGBA;
+ }
}
break;
@@ -719,12 +733,36 @@ bool EncodeWithCompressionLevel(const unsigned char* input,
return success;
}
+bool InternalEncodeSkBitmap(const SkBitmap& input,
+ int bpp,
+ bool discard_transparency,
+ int compression_level,
+ std::vector<unsigned char>* output) {
+ if (input.empty())
+ return false;
+ DCHECK_EQ(input.bytesPerPixel(), bpp);
Peter Kasting 2014/01/25 03:29:58 If these are always equal, why pass |bpp| at all?
mfomitchev 2014/01/27 17:15:28 Now EncodeA8SkBitmap() and EncodeBGRASkBitmap() ar
mfomitchev 2014/01/27 17:15:28 Now EncodeA8SkBitmap() and EncodeBGRASkBitmap() ar
+ DCHECK_GE(static_cast<int>(input.rowBytes()), input.width() * bpp);
+
+ SkAutoLockPixels lock_input(input);
+ return EncodeWithCompressionLevel(
+ reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)),
+ PNGCodec::FORMAT_SkBitmap,
+ Size(input.width(), input.height()),
+ static_cast<int>(input.rowBytes()),
+ discard_transparency,
+ std::vector<PNGCodec::Comment>(),
+ compression_level,
+ output);
+}
+
} // namespace
// static
-bool PNGCodec::Encode(const unsigned char* input, ColorFormat format,
- const Size& size, int row_byte_width,
+bool PNGCodec::Encode(const unsigned char* input,
+ ColorFormat format,
+ const Size& size,
+ int row_byte_width,
bool discard_transparency,
const std::vector<Comment>& comments,
std::vector<unsigned char>* output) {
@@ -742,37 +780,38 @@ bool PNGCodec::Encode(const unsigned char* input, ColorFormat format,
bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input,
bool discard_transparency,
std::vector<unsigned char>* output) {
- static const int bbp = 4;
+ static const int bpp = 4;
- if (input.empty())
- return false;
- DCHECK_EQ(input.bytesPerPixel(), bbp);
- DCHECK_GE(static_cast<int>(input.rowBytes()), input.width() * bbp);
+ return InternalEncodeSkBitmap(input,
+ bpp,
+ discard_transparency,
+ Z_DEFAULT_COMPRESSION,
+ output);
+}
- SkAutoLockPixels lock_input(input);
- return Encode(reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)),
- FORMAT_SkBitmap, Size(input.width(), input.height()),
- static_cast<int>(input.rowBytes()), discard_transparency,
- std::vector<Comment>(), output);
+// static
+bool PNGCodec::EncodeA8SkBitmap(const SkBitmap& input,
+ std::vector<unsigned char>* output) {
Peter Kasting 2014/01/25 03:29:58 Nit: Fix indenting
mfomitchev 2014/01/27 17:15:28 Done.
+ static const int bpp = 1;
+
+ return InternalEncodeSkBitmap(input,
+ bpp,
+ false,
+ Z_DEFAULT_COMPRESSION,
+ output);
}
// static
bool PNGCodec::FastEncodeBGRASkBitmap(const SkBitmap& input,
bool discard_transparency,
std::vector<unsigned char>* output) {
- static const int bbp = 4;
+ static const int bpp = 4;
- if (input.empty())
- return false;
- DCHECK_EQ(input.bytesPerPixel(), bbp);
- DCHECK_GE(static_cast<int>(input.rowBytes()), input.width() * bbp);
-
- SkAutoLockPixels lock_input(input);
- return EncodeWithCompressionLevel(
- reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)),
- FORMAT_SkBitmap, Size(input.width(), input.height()),
- static_cast<int>(input.rowBytes()), discard_transparency,
- std::vector<Comment>(), Z_BEST_SPEED, output);
+ return InternalEncodeSkBitmap(input,
+ bpp,
+ discard_transparency,
+ Z_BEST_SPEED,
+ output);
}
PNGCodec::Comment::Comment(const std::string& k, const std::string& t)
« ui/gfx/codec/png_codec.h ('K') | « ui/gfx/codec/png_codec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698