diff options
58 files changed, 493 insertions, 552 deletions
diff --git a/app/app.gyp b/app/app.gyp index 73d65ba..12e3121 100644 --- a/app/app.gyp +++ b/app/app.gyp @@ -49,7 +49,10 @@ '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', + '../third_party/libjpeg/libjpeg.gyp:libjpeg', + '../third_party/libpng/libpng.gyp:libpng', '../third_party/sqlite/sqlite.gyp:sqlite', + '../third_party/zlib/zlib.gyp:zlib', ], 'include_dirs': [ '..', @@ -74,6 +77,10 @@ 'gfx/canvas_linux.cc', 'gfx/canvas_mac.mm', 'gfx/canvas_win.cc', + 'gfx/codec/jpeg_codec.cc', + 'gfx/codec/jpeg_codec.h', + 'gfx/codec/png_codec.cc', + 'gfx/codec/png_codec.h', 'gfx/font.h', 'gfx/font_gtk.cc', 'gfx/font_mac.mm', @@ -199,10 +206,15 @@ '../testing/gtest.gyp:gtest', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', + '../third_party/libjpeg/libjpeg.gyp:libjpeg', + '../third_party/libpng/libpng.gyp:libpng', '../third_party/libxml/libxml.gyp:libxml', + '../third_party/zlib/zlib.gyp:zlib', ], 'sources': [ 'animation_unittest.cc', + 'gfx/codec/jpeg_codec_unittest.cc', + 'gfx/codec/png_codec_unittest.cc', 'gfx/color_utils_unittest.cc', 'gfx/font_unittest.cc', 'gfx/icon_util_unittest.cc', diff --git a/app/gfx/codec/DEPS b/app/gfx/codec/DEPS new file mode 100644 index 0000000..e4907a6c --- /dev/null +++ b/app/gfx/codec/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+skia", + "+third_party/libjpeg", + "+third_party/libpng", +] diff --git a/base/gfx/jpeg_codec.cc b/app/gfx/codec/jpeg_codec.cc index 4aea077..75ae384 100644 --- a/base/gfx/jpeg_codec.cc +++ b/app/gfx/codec/jpeg_codec.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/gfx/jpeg_codec.h" +#include "app/gfx/codec/jpeg_codec.h" #include <setjmp.h> @@ -18,6 +18,8 @@ extern "C" { #endif } +namespace gfx { + // Encoder/decoder shared stuff ------------------------------------------------ namespace { @@ -525,3 +527,5 @@ SkBitmap* JPEGCodec::Decode(const unsigned char* input, size_t input_size) { return bitmap; } + +} // namespace gfx diff --git a/base/gfx/jpeg_codec.h b/app/gfx/codec/jpeg_codec.h index 3f0c4e0..8f58ecd 100644 --- a/base/gfx/jpeg_codec.h +++ b/app/gfx/codec/jpeg_codec.h @@ -1,14 +1,16 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BASE_GFX_JPEG_CODEC_H_ -#define BASE_GFX_JPEG_CODEC_H_ +#ifndef APP_GFX_CODEC_JPEG_CODEC_H_ +#define APP_GFX_CODEC_JPEG_CODEC_H_ #include <vector> class SkBitmap; +namespace gfx { + // Interface for encoding/decoding JPEG data. This is a wrapper around libjpeg, // which has an inconvenient interface for callers. This is only used for UI // elements, WebKit has its own more complicated JPEG decoder which handles, @@ -56,4 +58,6 @@ class JPEGCodec { static SkBitmap* Decode(const unsigned char* input, size_t input_size); }; -#endif // BASE_GFX_JPEG_CODEC_H_ +} // namespace gfx + +#endif // APP_GFX_CODEC_JPEG_CODEC_H_ diff --git a/base/gfx/jpeg_codec_unittest.cc b/app/gfx/codec/jpeg_codec_unittest.cc index 0a58630..bf8eaab 100644 --- a/base/gfx/jpeg_codec_unittest.cc +++ b/app/gfx/codec/jpeg_codec_unittest.cc @@ -1,12 +1,14 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <math.h> -#include "base/gfx/jpeg_codec.h" +#include "app/gfx/codec/jpeg_codec.h" #include "testing/gtest/include/gtest/gtest.h" +namespace gfx { + // out of 100, this indicates how compressed it will be, this should be changed // with jpeg equality threshold // static int jpeg_quality = 75; // FIXME(brettw) @@ -145,3 +147,5 @@ TEST(JPEGCodec, DecodeCorrupted) { JPEGCodec::FORMAT_RGB, &output, &outw, &outh)); } + +} // namespace gfx diff --git a/base/gfx/png_decoder.cc b/app/gfx/codec/png_codec.cc index 5b27ed8..41057a0 100644 --- a/base/gfx/png_decoder.cc +++ b/app/gfx/codec/png_codec.cc @@ -1,11 +1,13 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/gfx/png_decoder.h" +#include "app/gfx/codec/png_codec.h" #include "base/logging.h" +#include "base/scoped_ptr.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkUnPreMultiply.h" extern "C" { #if defined(USE_SYSTEM_LIBPNG) @@ -15,6 +17,8 @@ extern "C" { #endif } +namespace gfx { + namespace { // Converts BGRA->RGBA and RGBA->BGRA. @@ -57,7 +61,7 @@ const double kInverseGamma = 1.0 / kDefaultGamma; class PngDecoderState { public: - PngDecoderState(PNGDecoder::ColorFormat ofmt, std::vector<unsigned char>* o) + PngDecoderState(PNGCodec::ColorFormat ofmt, std::vector<unsigned char>* o) : output_format(ofmt), output_channels(0), output(o), @@ -67,7 +71,7 @@ class PngDecoderState { done(false) { } - PNGDecoder::ColorFormat output_format; + PNGCodec::ColorFormat output_format; int output_channels; std::vector<unsigned char>* output; @@ -84,7 +88,7 @@ class PngDecoderState { bool done; private: - DISALLOW_EVIL_CONSTRUCTORS(PngDecoderState); + DISALLOW_COPY_AND_ASSIGN(PngDecoderState); }; void ConvertRGBtoRGBA(const unsigned char* rgb, int pixel_width, @@ -176,15 +180,15 @@ void DecodeInfoCallback(png_struct* png_ptr, png_info* info_ptr) { // Pick our row format converter necessary for this data. if (channels == 3) { switch (state->output_format) { - case PNGDecoder::FORMAT_RGB: + case PNGCodec::FORMAT_RGB: state->row_converter = NULL; // no conversion necessary state->output_channels = 3; break; - case PNGDecoder::FORMAT_RGBA: + case PNGCodec::FORMAT_RGBA: state->row_converter = &ConvertRGBtoRGBA; state->output_channels = 4; break; - case PNGDecoder::FORMAT_BGRA: + case PNGCodec::FORMAT_BGRA: state->row_converter = &ConvertRGBtoBGRA; state->output_channels = 4; break; @@ -194,15 +198,15 @@ void DecodeInfoCallback(png_struct* png_ptr, png_info* info_ptr) { } } else if (channels == 4) { switch (state->output_format) { - case PNGDecoder::FORMAT_RGB: + case PNGCodec::FORMAT_RGB: state->row_converter = &ConvertRGBAtoRGB; state->output_channels = 3; break; - case PNGDecoder::FORMAT_RGBA: + case PNGCodec::FORMAT_RGBA: state->row_converter = NULL; // no conversion necessary state->output_channels = 4; break; - case PNGDecoder::FORMAT_BGRA: + case PNGCodec::FORMAT_BGRA: state->row_converter = &ConvertBetweenBGRAandRGBA; state->output_channels = 4; break; @@ -264,9 +268,9 @@ class PngReadStructDestroyer { } // namespace // static -bool PNGDecoder::Decode(const unsigned char* input, size_t input_size, - ColorFormat format, std::vector<unsigned char>* output, - int* w, int* h) { +bool PNGCodec::Decode(const unsigned char* input, size_t input_size, + ColorFormat format, std::vector<unsigned char>* output, + int* w, int* h) { if (input_size < 8) return false; // Input data too small to be a png @@ -317,15 +321,15 @@ bool PNGDecoder::Decode(const unsigned char* input, size_t input_size, } // static -bool PNGDecoder::Decode(const std::vector<unsigned char>* data, - SkBitmap* bitmap) { +bool PNGCodec::Decode(const std::vector<unsigned char>* data, + SkBitmap* bitmap) { DCHECK(bitmap); if (!data || data->empty()) return false; int width, height; std::vector<unsigned char> decoded_data; - if (PNGDecoder::Decode(&data->front(), data->size(), PNGDecoder::FORMAT_BGRA, - &decoded_data, &width, &height)) { + if (PNGCodec::Decode(&data->front(), data->size(), PNGCodec::FORMAT_BGRA, + &decoded_data, &width, &height)) { bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); bitmap->allocPixels(); unsigned char* bitmap_data = @@ -351,8 +355,8 @@ bool PNGDecoder::Decode(const std::vector<unsigned char>* data, return false; } -//static -SkBitmap* PNGDecoder::CreateSkBitmapFromBGRAFormat( +// static +SkBitmap* PNGCodec::CreateSkBitmapFromBGRAFormat( std::vector<unsigned char>& bgra, int width, int height) { SkBitmap* bitmap = new SkBitmap(); bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); @@ -375,3 +379,199 @@ SkBitmap* PNGDecoder::CreateSkBitmapFromBGRAFormat( bitmap->setIsOpaque(opaque); return bitmap; } + +// Encoder -------------------------------------------------------------------- +// +// This section of the code is based on nsPNGEncoder.cpp in Mozilla +// (Copyright 2005 Google Inc.) + +namespace { + +// Passed around as the io_ptr in the png structs so our callbacks know where +// to write data. +struct PngEncoderState { + PngEncoderState(std::vector<unsigned char>* o) : out(o) {} + std::vector<unsigned char>* out; +}; + +// Called by libpng to flush its internal buffer to ours. +void EncoderWriteCallback(png_structp png, png_bytep data, png_size_t size) { + PngEncoderState* state = static_cast<PngEncoderState*>(png_get_io_ptr(png)); + DCHECK(state->out); + + size_t old_size = state->out->size(); + state->out->resize(old_size + size); + memcpy(&(*state->out)[old_size], data, size); +} + +void ConvertBGRAtoRGB(const unsigned char* bgra, int pixel_width, + unsigned char* rgb) { + for (int x = 0; x < pixel_width; x++) { + const unsigned char* pixel_in = &bgra[x * 4]; + unsigned char* pixel_out = &rgb[x * 3]; + pixel_out[0] = pixel_in[2]; + pixel_out[1] = pixel_in[1]; + pixel_out[2] = pixel_in[0]; + } +} + +// Automatically destroys the given write structs on destruction to make +// cleanup and error handling code cleaner. +class PngWriteStructDestroyer { + public: + PngWriteStructDestroyer(png_struct** ps, png_info** pi) : ps_(ps), pi_(pi) { + } + ~PngWriteStructDestroyer() { + png_destroy_write_struct(ps_, pi_); + } + private: + png_struct** ps_; + png_info** pi_; + + DISALLOW_EVIL_CONSTRUCTORS(PngWriteStructDestroyer); +}; + +} // namespace + +// static +bool PNGCodec::Encode(const unsigned char* input, ColorFormat format, + int w, int h, int row_byte_width, + bool discard_transparency, + std::vector<unsigned char>* output) { + // Run to convert an input row into the output row format, NULL means no + // conversion is necessary. + void (*converter)(const unsigned char* in, int w, unsigned char* out) = NULL; + + int input_color_components, output_color_components; + int png_output_color_type; + switch (format) { + case FORMAT_RGB: + input_color_components = 3; + output_color_components = 3; + png_output_color_type = PNG_COLOR_TYPE_RGB; + discard_transparency = false; + break; + + case FORMAT_RGBA: + input_color_components = 4; + if (discard_transparency) { + output_color_components = 3; + png_output_color_type = PNG_COLOR_TYPE_RGB; + converter = ConvertRGBAtoRGB; + } else { + output_color_components = 4; + png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; + converter = NULL; + } + break; + + case FORMAT_BGRA: + input_color_components = 4; + if (discard_transparency) { + output_color_components = 3; + png_output_color_type = PNG_COLOR_TYPE_RGB; + converter = ConvertBGRAtoRGB; + } else { + output_color_components = 4; + png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; + converter = ConvertBetweenBGRAandRGBA; + } + break; + + default: + NOTREACHED() << "Unknown pixel format"; + return false; + } + + // Row stride should be at least as long as the length of the data. + DCHECK(input_color_components * w <= row_byte_width); + + png_struct* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + png_voidp_NULL, + png_error_ptr_NULL, + png_error_ptr_NULL); + if (!png_ptr) + return false; + png_info* info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_write_struct(&png_ptr, NULL); + return false; + } + PngWriteStructDestroyer destroyer(&png_ptr, &info_ptr); + + if (setjmp(png_jmpbuf(png_ptr))) { + // The destroyer will ensure that the structures are cleaned up in this + // case, even though we may get here as a jump from random parts of the + // PNG library called below. + return false; + } + + // Set our callback for libpng to give us the data. + PngEncoderState state(output); + png_set_write_fn(png_ptr, &state, EncoderWriteCallback, NULL); + + png_set_IHDR(png_ptr, info_ptr, w, h, 8, png_output_color_type, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + png_write_info(png_ptr, info_ptr); + + if (!converter) { + // No conversion needed, give the data directly to libpng. + for (int y = 0; y < h; y ++) + png_write_row(png_ptr, + const_cast<unsigned char*>(&input[y * row_byte_width])); + } else { + // Needs conversion using a separate buffer. + unsigned char* row = new unsigned char[w * output_color_components]; + for (int y = 0; y < h; y ++) { + converter(&input[y * row_byte_width], w, row); + png_write_row(png_ptr, row); + } + delete[] row; + } + + png_write_end(png_ptr, info_ptr); + return true; +} + +// static +bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input, + bool discard_transparency, + std::vector<unsigned char>* output) { + static const int bbp = 4; + + SkAutoLockPixels lock_input(input); + DCHECK(input.empty() || input.bytesPerPixel() == bbp); + + // SkBitmaps are premultiplied, we need to unpremultiply them. + scoped_array<unsigned char> divided( + new unsigned char[input.width() * input.height() * bbp]); + + int i = 0; + for (int y = 0; y < input.height(); y++) { + for (int x = 0; x < input.width(); x++) { + uint32 pixel = input.getAddr32(0, y)[x]; + + int alpha = SkColorGetA(pixel); + if (alpha != 0 && alpha != 255) { + SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); + divided[i + 0] = SkColorGetR(unmultiplied); + divided[i + 1] = SkColorGetG(unmultiplied); + divided[i + 2] = SkColorGetB(unmultiplied); + divided[i + 3] = alpha; + } else { + divided[i + 0] = SkColorGetR(pixel); + divided[i + 1] = SkColorGetG(pixel); + divided[i + 2] = SkColorGetB(pixel); + divided[i + 3] = alpha; + } + i += bbp; + } + } + + return Encode(divided.get(), + PNGCodec::FORMAT_RGBA, input.width(), input.height(), + input.width() * bbp, discard_transparency, output); +} + +} // namespace gfx diff --git a/base/gfx/png_encoder.h b/app/gfx/codec/png_codec.h index da4e897..1e07632 100644 --- a/base/gfx/png_encoder.h +++ b/app/gfx/codec/png_codec.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BASE_GFX_PNG_ENCODER_H_ -#define BASE_GFX_PNG_ENCODER_H_ +#ifndef APP_GFX_CODEC_PNG_CODEC_H_ +#define APP_GFX_CODEC_PNG_CODEC_H_ #include <vector> @@ -11,13 +11,15 @@ class SkBitmap; -// Interface for encoding PNG data. This is a wrapper around libpng, -// which has an inconvenient interface for callers. This is currently designed -// for use in tests only (where we control the files), so the handling isn't as -// robust as would be required for a browser (see Decode() for more). WebKit -// has its own more complicated PNG decoder which handles, among other things, -// partially downloaded data. -class PNGEncoder { +namespace gfx { + +// Interface for encoding and decoding PNG data. This is a wrapper around +// libpng, which has an inconvenient interface for callers. This is currently +// designed for use in tests only (where we control the files), so the handling +// isn't as robust as would be required for a browser (see Decode() for more). +// WebKit has its own more complicated PNG decoder which handles, among other +// things, partially downloaded data. +class PNGCodec { public: enum ColorFormat { // 3 bytes per pixel (packed), in RGB order regardless of endianness. @@ -53,7 +55,7 @@ class PNGEncoder { bool discard_transparency, std::vector<unsigned char>* output); - // Call PNGEncoder::Encode on the supplied SkBitmap |input|, which is assumed + // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed // to be BGRA, 32 bits per pixel. The params |discard_transparency| and // |output| are passed directly to Encode; refer to Encode for more // information. During the call, an SkAutoLockPixels lock is held on |input|. @@ -61,8 +63,34 @@ class PNGEncoder { bool discard_transparency, std::vector<unsigned char>* output); + // Decodes the PNG data contained in input of length input_size. The + // decoded data will be placed in *output with the dimensions in *w and *h + // on success (returns true). This data will be written in the 'format' + // format. On failure, the values of these output variables are undefined. + // + // This function may not support all PNG types, and it hasn't been tested + // with a large number of images, so assume a new format may not work. It's + // really designed to be able to read in something written by Encode() above. + static bool Decode(const unsigned char* input, size_t input_size, + ColorFormat format, std::vector<unsigned char>* output, + int* w, int* h); + + // A convenience function for decoding PNGs as previously encoded by the PNG + // encoder. Chrome encodes png in the format PNGCodec::FORMAT_BGRA. + // + // Returns true if data is non-null and can be decoded as a png, false + // otherwise. + static bool Decode(const std::vector<unsigned char>* data, SkBitmap* icon); + + // Create a SkBitmap from a decoded BGRA DIB. The caller owns the returned + // SkBitmap. + static SkBitmap* CreateSkBitmapFromBGRAFormat( + std::vector<unsigned char>& bgra, int width, int height); + private: - DISALLOW_COPY_AND_ASSIGN(PNGEncoder); + DISALLOW_COPY_AND_ASSIGN(PNGCodec); }; -#endif // BASE_GFX_PNG_ENCODER_H_ +} // namespace gfx + +#endif // APP_GFX_CODEC_PNG_CODEC_H_ diff --git a/base/gfx/png_codec_unittest.cc b/app/gfx/codec/png_codec_unittest.cc index c9734a7..d16f519 100644 --- a/base/gfx/png_codec_unittest.cc +++ b/app/gfx/codec/png_codec_unittest.cc @@ -4,11 +4,12 @@ #include <math.h> -#include "base/gfx/png_encoder.h" -#include "base/gfx/png_decoder.h" +#include "app/gfx/codec/png_codec.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +namespace gfx { + static void MakeRGBImage(int w, int h, std::vector<unsigned char>* dat) { dat->resize(w * h * 3); for (int y = 0; y < h; y++) { @@ -70,14 +71,14 @@ TEST(PNGCodec, EncodeDecodeRGB) { // encode std::vector<unsigned char> encoded; - EXPECT_TRUE(PNGEncoder::Encode(&original[0], PNGEncoder::FORMAT_RGB, w, h, + EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, w, h, w * 3, false, &encoded)); // decode, it should have the same size as the original std::vector<unsigned char> decoded; int outw, outh; - EXPECT_TRUE(PNGDecoder::Decode(&encoded[0], encoded.size(), - PNGDecoder::FORMAT_RGB, &decoded, + EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), + PNGCodec::FORMAT_RGB, &decoded, &outw, &outh)); ASSERT_EQ(w, outw); ASSERT_EQ(h, outh); @@ -97,14 +98,14 @@ TEST(PNGCodec, EncodeDecodeRGBA) { // encode std::vector<unsigned char> encoded; - EXPECT_TRUE(PNGEncoder::Encode(&original[0], PNGEncoder::FORMAT_RGBA, w, h, + EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGBA, w, h, w * 4, false, &encoded)); // decode, it should have the same size as the original std::vector<unsigned char> decoded; int outw, outh; - EXPECT_TRUE(PNGDecoder::Decode(&encoded[0], encoded.size(), - PNGDecoder::FORMAT_RGBA, &decoded, + EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), + PNGCodec::FORMAT_RGBA, &decoded, &outw, &outh)); ASSERT_EQ(w, outw); ASSERT_EQ(h, outh); @@ -125,25 +126,25 @@ TEST(PNGCodec, DecodeCorrupted) { // It should fail when given non-JPEG compressed data. std::vector<unsigned char> output; int outw, outh; - EXPECT_FALSE(PNGDecoder::Decode(&original[0], original.size(), - PNGDecoder::FORMAT_RGB, &output, + EXPECT_FALSE(PNGCodec::Decode(&original[0], original.size(), + PNGCodec::FORMAT_RGB, &output, &outw, &outh)); // Make some compressed data. std::vector<unsigned char> compressed; - EXPECT_TRUE(PNGEncoder::Encode(&original[0], PNGEncoder::FORMAT_RGB, w, h, + EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, w, h, w * 3, false, &compressed)); // Try decompressing a truncated version. - EXPECT_FALSE(PNGDecoder::Decode(&compressed[0], compressed.size() / 2, - PNGDecoder::FORMAT_RGB, &output, + EXPECT_FALSE(PNGCodec::Decode(&compressed[0], compressed.size() / 2, + PNGCodec::FORMAT_RGB, &output, &outw, &outh)); // Corrupt it and try decompressing that. for (int i = 10; i < 30; i++) compressed[i] = i; - EXPECT_FALSE(PNGDecoder::Decode(&compressed[0], compressed.size(), - PNGDecoder::FORMAT_RGB, &output, + EXPECT_FALSE(PNGCodec::Decode(&compressed[0], compressed.size(), + PNGCodec::FORMAT_RGB, &output, &outw, &outh)); } @@ -157,14 +158,14 @@ TEST(PNGCodec, EncodeDecodeBGRA) { // Encode. std::vector<unsigned char> encoded; - EXPECT_TRUE(PNGEncoder::Encode(&original[0], PNGEncoder::FORMAT_BGRA, w, h, + EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_BGRA, w, h, w * 4, false, &encoded)); // Decode, it should have the same size as the original. std::vector<unsigned char> decoded; int outw, outh; - EXPECT_TRUE(PNGDecoder::Decode(&encoded[0], encoded.size(), - PNGDecoder::FORMAT_BGRA, &decoded, + EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), + PNGCodec::FORMAT_BGRA, &decoded, &outw, &outh)); ASSERT_EQ(w, outw); ASSERT_EQ(h, outh); @@ -185,16 +186,16 @@ TEST(PNGCodec, StripAddAlpha) { // Encode RGBA data as RGB. std::vector<unsigned char> encoded; - EXPECT_TRUE(PNGEncoder::Encode(&original_rgba[0], - PNGEncoder::FORMAT_RGBA, - w, h, - w * 4, true, &encoded)); + EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0], + PNGCodec::FORMAT_RGBA, + w, h, + w * 4, true, &encoded)); // Decode the RGB to RGBA. std::vector<unsigned char> decoded; int outw, outh; - EXPECT_TRUE(PNGDecoder::Decode(&encoded[0], encoded.size(), - PNGDecoder::FORMAT_RGBA, &decoded, + EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), + PNGCodec::FORMAT_RGBA, &decoded, &outw, &outh)); // Decoded and reference should be the same (opaque alpha). @@ -204,14 +205,14 @@ TEST(PNGCodec, StripAddAlpha) { ASSERT_TRUE(original_rgba == decoded); // Encode RGBA to RGBA. - EXPECT_TRUE(PNGEncoder::Encode(&original_rgba[0], - PNGEncoder::FORMAT_RGBA, - w, h, - w * 4, false, &encoded)); + EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0], + PNGCodec::FORMAT_RGBA, + w, h, + w * 4, false, &encoded)); // Decode the RGBA to RGB. - EXPECT_TRUE(PNGDecoder::Decode(&encoded[0], encoded.size(), - PNGDecoder::FORMAT_RGB, &decoded, + EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), + PNGCodec::FORMAT_RGB, &decoded, &outw, &outh)); // It should be the same as our non-alpha-channel reference. @@ -229,11 +230,11 @@ TEST(PNGCodec, EncodeBGRASkBitmap) { // Encode the bitmap. std::vector<unsigned char> encoded; - PNGEncoder::EncodeBGRASkBitmap(original_bitmap, false, &encoded); + PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded); // Decode the encoded string. SkBitmap decoded_bitmap; - EXPECT_TRUE(PNGDecoder::Decode(&encoded, &decoded_bitmap)); + EXPECT_TRUE(PNGCodec::Decode(&encoded, &decoded_bitmap)); // Compare the original bitmap and the output bitmap. We use ColorsClose // as SkBitmaps are considered to be pre-multiplied, the unpremultiplication @@ -247,3 +248,4 @@ TEST(PNGCodec, EncodeBGRASkBitmap) { } } +} // namespace gfx diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index c930fa3..a108660 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -4,8 +4,8 @@ #include "app/resource_bundle.h" +#include "app/gfx/codec/png_codec.h" #include "app/gfx/font.h" -#include "base/gfx/png_decoder.h" #include "base/logging.h" #include "base/string_piece.h" #include "net/base/file_stream.h" @@ -80,16 +80,16 @@ SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { // Decode the PNG. int image_width; int image_height; - if (!PNGDecoder::Decode(&raw_data.front(), raw_data.size(), - PNGDecoder::FORMAT_BGRA, - &png_data, &image_width, &image_height)) { + if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(), + gfx::PNGCodec::FORMAT_BGRA, + &png_data, &image_width, &image_height)) { NOTREACHED() << "Unable to decode image resource " << resource_id; return NULL; } - return PNGDecoder::CreateSkBitmapFromBGRAFormat(png_data, - image_width, - image_height); + return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, + image_width, + image_height); } std::string ResourceBundle::GetDataResource(int resource_id) { diff --git a/base/base.gyp b/base/base.gyp index 757f5e2..f68564a 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -528,16 +528,10 @@ 'gfx/gtk_native_view_id_manager.h', 'gfx/gtk_util.cc', 'gfx/gtk_util.h', - 'gfx/jpeg_codec.cc', - 'gfx/jpeg_codec.h', 'gfx/native_theme.cc', 'gfx/native_theme.h', 'gfx/native_widget_types.h', 'gfx/native_widget_types_gtk.cc', - 'gfx/png_decoder.cc', - 'gfx/png_decoder.h', - 'gfx/png_encoder.cc', - 'gfx/png_encoder.h', 'gfx/point.cc', 'gfx/point.h', 'gfx/rect.cc', @@ -551,9 +545,6 @@ 'dependencies': [ 'base', '../skia/skia.gyp:skia', - '../third_party/libjpeg/libjpeg.gyp:libjpeg', - '../third_party/libpng/libpng.gyp:libpng', - '../third_party/zlib/zlib.gyp:zlib', ], 'export_dependent_settings': [ 'base', @@ -604,9 +595,7 @@ 'file_path_unittest.cc', 'file_util_unittest.cc', 'file_version_info_unittest.cc', - 'gfx/jpeg_codec_unittest.cc', 'gfx/native_theme_unittest.cc', - 'gfx/png_codec_unittest.cc', 'gfx/rect_unittest.cc', 'gmock_unittest.cc', 'histogram_unittest.cc', diff --git a/base/gfx/DEPS b/base/gfx/DEPS index e0b7df8..2a3980b 100644 --- a/base/gfx/DEPS +++ b/base/gfx/DEPS @@ -1,4 +1,3 @@ include_rules = [ "+skia", - "+third_party/libpng" ] diff --git a/base/gfx/png_decoder.h b/base/gfx/png_decoder.h deleted file mode 100644 index 68b310f..0000000 --- a/base/gfx/png_decoder.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_GFX_PNG_DECODER_H_ -#define BASE_GFX_PNG_DECODER_H_ - -#include <vector> - -#include "base/basictypes.h" - -class SkBitmap; - -// Interface for decoding PNG data. This is a wrapper around libpng, -// which has an inconvenient interface for callers. This is currently designed -// for use in tests only (where we control the files), so the handling isn't as -// robust as would be required for a browser (see Decode() for more). WebKit -// has its own more complicated PNG decoder which handles, among other things, -// partially downloaded data. -class PNGDecoder { - public: - enum ColorFormat { - // 3 bytes per pixel (packed), in RGB order regardless of endianness. - // This is the native JPEG format. - FORMAT_RGB, - - // 4 bytes per pixel, in RGBA order in memory regardless of endianness. - FORMAT_RGBA, - - // 4 bytes per pixel, in BGRA order in memory regardless of endianness. - // This is the default Windows DIB order. - FORMAT_BGRA - }; - - // Decodes the PNG data contained in input of length input_size. The - // decoded data will be placed in *output with the dimensions in *w and *h - // on success (returns true). This data will be written in the 'format' - // format. On failure, the values of these output variables are undefined. - // - // This function may not support all PNG types, and it hasn't been tested - // with a large number of images, so assume a new format may not work. It's - // really designed to be able to read in something written by Encode() above. - static bool Decode(const unsigned char* input, size_t input_size, - ColorFormat format, std::vector<unsigned char>* output, - int* w, int* h); - - // A convenience function for decoding PNGs as previously encoded by the PNG - // encoder. Chrome encodes png in the format PNGDecoder::FORMAT_BGRA. - // - // Returns true if data is non-null and can be decoded as a png, false - // otherwise. - static bool Decode(const std::vector<unsigned char>* data, SkBitmap* icon); - - // Create a SkBitmap from a decoded BGRA DIB. The caller owns the returned - // SkBitmap. - static SkBitmap* CreateSkBitmapFromBGRAFormat( - std::vector<unsigned char>& bgra, int width, int height); - - private: - DISALLOW_COPY_AND_ASSIGN(PNGDecoder); -}; - -#endif // BASE_GFX_PNG_DECODER_H_ diff --git a/base/gfx/png_encoder.cc b/base/gfx/png_encoder.cc deleted file mode 100644 index 10a60c6..0000000 --- a/base/gfx/png_encoder.cc +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/basictypes.h" -#include "base/gfx/png_encoder.h" -#include "base/logging.h" -#include "base/scoped_ptr.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkUnPreMultiply.h" - -extern "C" { -#if defined(USE_SYSTEM_LIBPNG) -#include <png.h> -#else -#include "third_party/libpng/png.h" -#endif -} - -namespace { - -// Converts BGRA->RGBA and RGBA->BGRA. -void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width, - unsigned char* output) { - for (int x = 0; x < pixel_width; x++) { - const unsigned char* pixel_in = &input[x * 4]; - unsigned char* pixel_out = &output[x * 4]; - pixel_out[0] = pixel_in[2]; - pixel_out[1] = pixel_in[1]; - pixel_out[2] = pixel_in[0]; - pixel_out[3] = pixel_in[3]; - } -} - -void ConvertRGBAtoRGB(const unsigned char* rgba, int pixel_width, - unsigned char* rgb) { - for (int x = 0; x < pixel_width; x++) { - const unsigned char* pixel_in = &rgba[x * 4]; - unsigned char* pixel_out = &rgb[x * 3]; - pixel_out[0] = pixel_in[0]; - pixel_out[1] = pixel_in[1]; - pixel_out[2] = pixel_in[2]; - } -} - -} // namespace - -// Encoder -------------------------------------------------------------------- -// -// This section of the code is based on nsPNGEncoder.cpp in Mozilla -// (Copyright 2005 Google Inc.) - -namespace { - -// Passed around as the io_ptr in the png structs so our callbacks know where -// to write data. -struct PngEncoderState { - PngEncoderState(std::vector<unsigned char>* o) : out(o) {} - std::vector<unsigned char>* out; -}; - -// Called by libpng to flush its internal buffer to ours. -void EncoderWriteCallback(png_structp png, png_bytep data, png_size_t size) { - PngEncoderState* state = static_cast<PngEncoderState*>(png_get_io_ptr(png)); - DCHECK(state->out); - - size_t old_size = state->out->size(); - state->out->resize(old_size + size); - memcpy(&(*state->out)[old_size], data, size); -} - -void ConvertBGRAtoRGB(const unsigned char* bgra, int pixel_width, - unsigned char* rgb) { - for (int x = 0; x < pixel_width; x++) { - const unsigned char* pixel_in = &bgra[x * 4]; - unsigned char* pixel_out = &rgb[x * 3]; - pixel_out[0] = pixel_in[2]; - pixel_out[1] = pixel_in[1]; - pixel_out[2] = pixel_in[0]; - } -} - -// Automatically destroys the given write structs on destruction to make -// cleanup and error handling code cleaner. -class PngWriteStructDestroyer { - public: - PngWriteStructDestroyer(png_struct** ps, png_info** pi) : ps_(ps), pi_(pi) { - } - ~PngWriteStructDestroyer() { - png_destroy_write_struct(ps_, pi_); - } - private: - png_struct** ps_; - png_info** pi_; - - DISALLOW_EVIL_CONSTRUCTORS(PngWriteStructDestroyer); -}; - -} // namespace - -// static -bool PNGEncoder::Encode(const unsigned char* input, ColorFormat format, - int w, int h, int row_byte_width, - bool discard_transparency, - std::vector<unsigned char>* output) { - // Run to convert an input row into the output row format, NULL means no - // conversion is necessary. - void (*converter)(const unsigned char* in, int w, unsigned char* out) = NULL; - - int input_color_components, output_color_components; - int png_output_color_type; - switch (format) { - case FORMAT_RGB: - input_color_components = 3; - output_color_components = 3; - png_output_color_type = PNG_COLOR_TYPE_RGB; - discard_transparency = false; - break; - - case FORMAT_RGBA: - input_color_components = 4; - if (discard_transparency) { - output_color_components = 3; - png_output_color_type = PNG_COLOR_TYPE_RGB; - converter = ConvertRGBAtoRGB; - } else { - output_color_components = 4; - png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; - converter = NULL; - } - break; - - case FORMAT_BGRA: - input_color_components = 4; - if (discard_transparency) { - output_color_components = 3; - png_output_color_type = PNG_COLOR_TYPE_RGB; - converter = ConvertBGRAtoRGB; - } else { - output_color_components = 4; - png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; - converter = ConvertBetweenBGRAandRGBA; - } - break; - - default: - NOTREACHED() << "Unknown pixel format"; - return false; - } - - // Row stride should be at least as long as the length of the data. - DCHECK(input_color_components * w <= row_byte_width); - - png_struct* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - png_voidp_NULL, - png_error_ptr_NULL, - png_error_ptr_NULL); - if (!png_ptr) - return false; - png_info* info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - png_destroy_write_struct(&png_ptr, NULL); - return false; - } - PngWriteStructDestroyer destroyer(&png_ptr, &info_ptr); - - if (setjmp(png_jmpbuf(png_ptr))) { - // The destroyer will ensure that the structures are cleaned up in this - // case, even though we may get here as a jump from random parts of the - // PNG library called below. - return false; - } - - // Set our callback for libpng to give us the data. - PngEncoderState state(output); - png_set_write_fn(png_ptr, &state, EncoderWriteCallback, NULL); - - png_set_IHDR(png_ptr, info_ptr, w, h, 8, png_output_color_type, - PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - png_write_info(png_ptr, info_ptr); - - if (!converter) { - // No conversion needed, give the data directly to libpng. - for (int y = 0; y < h; y ++) - png_write_row(png_ptr, - const_cast<unsigned char*>(&input[y * row_byte_width])); - } else { - // Needs conversion using a separate buffer. - unsigned char* row = new unsigned char[w * output_color_components]; - for (int y = 0; y < h; y ++) { - converter(&input[y * row_byte_width], w, row); - png_write_row(png_ptr, row); - } - delete[] row; - } - - png_write_end(png_ptr, info_ptr); - return true; -} - -// static -bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input, - bool discard_transparency, - std::vector<unsigned char>* output) { - static const int bbp = 4; - - SkAutoLockPixels lock_input(input); - DCHECK(input.empty() || input.bytesPerPixel() == bbp); - - // SkBitmaps are premultiplied, we need to unpremultiply them. - scoped_array<unsigned char> divided( - new unsigned char[input.width() * input.height() * bbp]); - - int i = 0; - for (int y = 0; y < input.height(); y++) { - for (int x = 0; x < input.width(); x++) { - uint32 pixel = input.getAddr32(0, y)[x]; - - int alpha = SkColorGetA(pixel); - if (alpha != 0 && alpha != 255) { - SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); - divided[i + 0] = SkColorGetR(unmultiplied); - divided[i + 1] = SkColorGetG(unmultiplied); - divided[i + 2] = SkColorGetB(unmultiplied); - divided[i + 3] = alpha; - } else { - divided[i + 0] = SkColorGetR(pixel); - divided[i + 1] = SkColorGetG(pixel); - divided[i + 2] = SkColorGetB(pixel); - divided[i + 3] = alpha; - } - i += bbp; - } - } - - return Encode(divided.get(), - PNGEncoder::FORMAT_RGBA, input.width(), input.height(), - input.width() * bbp, discard_transparency, output); -} diff --git a/build/common.gypi b/build/common.gypi index fd29d5e..50b2c6c 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -480,7 +480,7 @@ '-D_FILE_OFFSET_BITS=64', ], 'cflags_cc': [ - '-fno-rtti', + #'-fno-rtti', '-fno-threadsafe-statics', ], 'ldflags': [ diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 450521e..a49055e 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -488,7 +488,7 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget, actual_content_width /= PANGO_SCALE; actual_content_height /= PANGO_SCALE; - DCHECK_LT(actual_content_height, kHeightPerResult); // Font is too tall. + //DCHECK_LT(actual_content_height, kHeightPerResult); // Font is too tall. // Center the text within the line. int content_y = std::max(line_rect.y(), line_rect.y() + ((kHeightPerResult - actual_content_height) / 2)); diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 4769f90..6b3e368 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -1,11 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/bookmarks/bookmark_model.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" -#include "base/gfx/png_decoder.h" #include "base/scoped_vector.h" #include "build/build_config.h" #include "chrome/browser/bookmarks/bookmark_index.h" @@ -644,7 +644,7 @@ void BookmarkModel::OnFavIconDataAvailable( DCHECK(node); node->set_favicon_load_handle(0); if (know_favicon && data.get() && - PNGDecoder::Decode(&data->data, &fav_icon)) { + gfx::PNGCodec::Decode(&data->data, &fav_icon)) { node->set_favicon(fav_icon); FavIconLoaded(node); } diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 96f1d29..4be04498 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -4,10 +4,9 @@ #include "chrome/browser/browser_theme_provider.h" +#include "app/gfx/codec/png_codec.h" #include "app/gfx/skbitmap_operations.h" #include "base/file_util.h" -#include "base/gfx/png_decoder.h" -#include "base/gfx/png_encoder.h" #include "base/string_util.h" #include "base/thread.h" #include "base/values.h" @@ -225,7 +224,7 @@ class WriteImagesToDiskTask : public Task { if (found != themed_image_cache_.end()) { SkBitmap* bitmap = found->second; std::vector<unsigned char> image_data; - if (!PNGEncoder::EncodeBGRASkBitmap(*bitmap, false, &image_data)) { + if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &image_data)) { NOTREACHED() << "Image file could not be encoded."; return; } @@ -650,16 +649,16 @@ SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { int image_width = 0; int image_height = 0; - if (!PNGDecoder::Decode(&raw_data.front(), raw_data.size(), - PNGDecoder::FORMAT_BGRA, &png_data, + if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(), + gfx::PNGCodec::FORMAT_BGRA, &png_data, &image_width, &image_height)) { NOTREACHED() << "Unable to decode theme image resource " << id; return NULL; } - return PNGDecoder::CreateSkBitmapFromBGRAFormat(png_data, - image_width, - image_height); + return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, + image_width, + image_height); } else { // TODO(glen): File no-longer exists, we're out of date. We should // clear the theme (or maybe just the pref that points to this diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc index bfb5852..eed0dde 100644 --- a/chrome/browser/chrome_plugin_host.cc +++ b/chrome/browser/chrome_plugin_host.cc @@ -10,7 +10,6 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/histogram.h" #include "base/message_loop.h" #include "base/path_service.h" diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 2fe9f98..565a8fb 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -7,7 +7,6 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/theme_provider.h" -#include "base/gfx/png_encoder.h" #include "base/message_loop.h" #include "base/string_util.h" #include "base/time.h" diff --git a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc index e946047..653c2ef 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/gfx/png_encoder.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/dom_ui/dom_ui_theme_source.h" #include "chrome/browser/profile.h" diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc index 230389b..acb8276 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc @@ -4,9 +4,9 @@ #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" +#include "app/gfx/codec/jpeg_codec.h" #include "app/resource_bundle.h" #include "base/command_line.h" -#include "base/gfx/jpeg_codec.h" #include "chrome/browser/profile.h" #include "chrome/browser/thumbnail_store.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc index aa646c0..e13163f 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.cc +++ b/chrome/browser/dom_ui/downloads_dom_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,7 +6,6 @@ #include "app/l10n_util.h" #include "base/basictypes.h" -#include "base/gfx/png_encoder.h" #include "base/string_piece.h" #include "base/thread.h" #include "base/time_format.h" diff --git a/chrome/browser/dom_ui/fileicon_source.cc b/chrome/browser/dom_ui/fileicon_source.cc index daf9a43..247f8c5 100644 --- a/chrome/browser/dom_ui/fileicon_source.cc +++ b/chrome/browser/dom_ui/fileicon_source.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/dom_ui/fileicon_source.h" -#include "base/gfx/png_encoder.h" +#include "app/gfx/codec/png_codec.h" #include "base/string_util.h" #include "chrome/browser/browser_process.h" #include "chrome/common/time_format.h" @@ -40,7 +40,7 @@ void FileIconSource::StartDataRequest(const std::string& path, if (icon) { std::vector<unsigned char> png_bytes; - PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); + gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &png_bytes); scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); SendResponse(request_id, icon_data); @@ -63,7 +63,7 @@ void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, if (icon) { std::vector<unsigned char> png_bytes; - PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); + gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &png_bytes); scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); SendResponse(request_id, icon_data); diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 12028c2..89cb48c 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -4,7 +4,7 @@ #include "chrome/browser/extensions/extension_tabs_module.h" -#include "base/gfx/jpeg_codec.h" +#include "app/gfx/codec/jpeg_codec.h" #include "base/string_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" @@ -785,9 +785,9 @@ bool CaptureVisibleTabFunction::RunImpl() { #endif scoped_refptr<RefCountedBytes> jpeg_data(new RefCountedBytes); SkAutoLockPixels screen_capture_lock(screen_capture); - bool encoded = JPEGCodec::Encode( + bool encoded = gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, screen_capture.width(), + gfx::JPEGCodec::FORMAT_BGRA, screen_capture.width(), screen_capture.height(), static_cast<int>(screen_capture.rowBytes()), 90, &jpeg_data->data); diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc index e1d600c..7003139 100644 --- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc @@ -6,9 +6,9 @@ #include <set> +#include "app/gfx/codec/png_codec.h" #include "base/crypto/signature_verifier.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/message_loop.h" #include "base/scoped_handle.h" #include "base/task.h" @@ -171,7 +171,7 @@ void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( // TODO(mpcomplete): It's lame that we're encoding all images as PNG, even // though they may originally be .jpg, etc. Figure something out. // http://code.google.com/p/chromium/issues/detail?id=12459 - if (!PNGEncoder::EncodeBGRASkBitmap(image, false, &image_data)) { + if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data)) { ReportFailure("Error re-encoding theme image."); return; } diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc index 991376c..f0d7d64 100644 --- a/chrome/browser/fav_icon_helper.cc +++ b/chrome/browser/fav_icon_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,9 +6,8 @@ #include "build/build_config.h" +#include "app/gfx/codec/png_codec.h" #include "app/gfx/favicon_size.h" -#include "base/gfx/png_decoder.h" -#include "base/gfx/png_encoder.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" @@ -65,7 +64,7 @@ void FavIconHelper::SetFavIcon( if (GetFaviconService() && !profile()->IsOffTheRecord()) { std::vector<unsigned char> image_data; - PNGEncoder::EncodeBGRASkBitmap(sized_image, false, &image_data); + gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); GetFaviconService()->SetFavicon(i->second.url, i->second.fav_icon_url, image_data); } @@ -88,7 +87,7 @@ void FavIconHelper::FavIconDownloadFailed(int download_id) { void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, const std::vector<unsigned char>& data) { SkBitmap image; - PNGDecoder::Decode(&data, &image); + gfx::PNGCodec::Decode(&data, &image); UpdateFavIcon(entry, image); } diff --git a/chrome/browser/gears_integration.cc b/chrome/browser/gears_integration.cc index d7cf898..b6f1d3b 100644 --- a/chrome/browser/gears_integration.cc +++ b/chrome/browser/gears_integration.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/gears_integration.h" -#include "base/gfx/png_encoder.h" +#include "app/gfx/codec/png_codec.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" @@ -116,7 +116,7 @@ static GURL ConvertSkBitmapToDataURL(const SkBitmap& icon) { // Get the FavIcon data. std::vector<unsigned char> icon_data; - PNGEncoder::EncodeBGRASkBitmap(icon, false, &icon_data); + gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &icon_data); // Base64-encode it (to make it a data URL). std::string icon_data_str(reinterpret_cast<char*>(&icon_data[0]), diff --git a/chrome/browser/gtk/list_store_favicon_loader.cc b/chrome/browser/gtk/list_store_favicon_loader.cc index 68f7547..eb1e327 100644 --- a/chrome/browser/gtk/list_store_favicon_loader.cc +++ b/chrome/browser/gtk/list_store_favicon_loader.cc @@ -6,8 +6,8 @@ #include <vector> +#include "app/gfx/codec/png_codec.h" #include "base/gfx/gtk_util.h" -#include "base/gfx/png_decoder.h" #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/profile.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -71,9 +71,10 @@ void ListStoreFavIconLoader::OnGotFavIcon( if (know_fav_icon && image_data.get() && !image_data->data.empty()) { int width, height; std::vector<unsigned char> decoded_data; - if (PNGDecoder::Decode(&image_data->data.front(), image_data->data.size(), - PNGDecoder::FORMAT_BGRA, &decoded_data, &width, - &height)) { + if (gfx::PNGCodec::Decode(&image_data->data.front(), + image_data->data.size(), + gfx::PNGCodec::FORMAT_BGRA, &decoded_data, + &width, &height)) { SkBitmap icon; icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); icon.allocPixels(); diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 08cdf38..31eab71 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/gfx/codec/jpeg_codec.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/path_service.h" #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -205,7 +205,7 @@ void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) { // Thumbnails for each URL. scoped_ptr<SkBitmap> thumbnail( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); ThumbnailScore score(0.25, true, true, Time::Now()); Time time; diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 9f14f1d..bb92d19 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/gfx/codec/jpeg_codec.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/path_service.h" #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -231,14 +231,14 @@ TEST_F(HistoryBackendTest, DeleteAll) { // Add thumbnails for each page. ThumbnailScore score(0.25, true, true); scoped_ptr<SkBitmap> google_bitmap( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); Time time; GURL gurl; backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, *google_bitmap, score, time); scoped_ptr<SkBitmap> weewar_bitmap( - JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); + gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, *weewar_bitmap, score, time); @@ -405,7 +405,7 @@ TEST_F(HistoryBackendTest, GetPageThumbnailAfterRedirects) { // Add a thumbnail for the end of that redirect chain. scoped_ptr<SkBitmap> thumbnail( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); backend_->SetPageThumbnail(GURL(thumbnail_url), *thumbnail, ThumbnailScore(0.25, true, true)); diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index be84f01..ce6121a 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -20,12 +20,12 @@ #include <time.h> #include <algorithm> +#include "app/gfx/codec/jpeg_codec.h" #include "app/sql/connection.h" #include "app/sql/statement.h" #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/scoped_vector.h" @@ -668,7 +668,7 @@ TEST_F(HistoryTest, Thumbnails) { ASSERT_TRUE(history->Init(history_dir_, NULL)); scoped_ptr<SkBitmap> thumbnail( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); static const double boringness = 0.25; const GURL url("http://www.google.com/thumbnail_test/"); @@ -687,7 +687,7 @@ TEST_F(HistoryTest, Thumbnails) { // compression and we don't have a similarity measure. EXPECT_TRUE(thumbnail_data_.size()); scoped_ptr<SkBitmap> decoded_thumbnail( - JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); + gfx::JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); EXPECT_TRUE(decoded_thumbnail.get()); // Request a nonexistent thumbnail and make sure we get diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index 735440f..ac06464 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -4,10 +4,10 @@ #include "chrome/browser/history/thumbnail_database.h" +#include "app/gfx/codec/jpeg_codec.h" #include "app/sql/statement.h" #include "app/sql/transaction.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/time.h" #include "base/string_util.h" #include "chrome/browser/history/history_publisher.h" @@ -229,9 +229,9 @@ void ThumbnailDatabase::SetPageThumbnail( // highly detailed images. std::vector<unsigned char> jpeg_data; SkAutoLockPixels thumbnail_lock(thumbnail); - bool encoded = JPEGCodec::Encode( + bool encoded = gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, thumbnail.width(), + gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), thumbnail.height(), static_cast<int>(thumbnail.rowBytes()), 90, &jpeg_data); diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc index d6a93ff..83d67cf 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -1,11 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/gfx/codec/jpeg_codec.h" #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/path_service.h" #include "chrome/browser/history/thumbnail_database.h" #include "chrome/common/chrome_paths.h" @@ -55,7 +55,7 @@ class ThumbnailDatabaseTest : public testing::Test { file_util::Delete(file_name_, false); google_bitmap_.reset( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); } virtual void TearDown() { diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index 48a1751..1206843 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -4,7 +4,7 @@ #include "chrome/browser/history/top_sites.h" -#include "base/gfx/jpeg_codec.h" +#include "app/gfx/codec/jpeg_codec.h" #include "base/logging.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -45,9 +45,9 @@ bool TopSites::SetPageThumbnail(const GURL& url, image.thumbnail = new RefCountedBytes; SkAutoLockPixels thumbnail_lock(thumbnail); - bool encoded = JPEGCodec::Encode( + bool encoded = gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, thumbnail.width(), + gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), thumbnail.height(), static_cast<int>(thumbnail.rowBytes()), 90, &image.thumbnail->data); diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index 05a4935..371a7c3 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -8,8 +8,8 @@ #include <gio/gio.h> #include <gtk/gtk.h> +#include "app/gfx/codec/png_codec.h" #include "base/file_util.h" -#include "base/gfx/png_decoder.h" #include "base/logging.h" #include "base/linux_util.h" #include "base/message_loop.h" @@ -65,8 +65,8 @@ void IconLoader::ParseIcon() { pixel_vector.resize(height * stride); memcpy(const_cast<unsigned char*>(pixel_vector.data()), BGRA_pixels, height * stride); - bitmap_ = PNGDecoder::CreateSkBitmapFromBGRAFormat(pixel_vector, - width, height); + bitmap_ = gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(pixel_vector, + width, height); free(BGRA_pixels); } } else { diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 62cbf52..29911f6 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -8,9 +8,9 @@ #include <set> #include "app/gfx/favicon_size.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -425,7 +425,7 @@ bool Importer::ReencodeFavicon(const unsigned char* src_data, size_t src_len, } // Encode our bitmap as a PNG. - PNGEncoder::EncodeBGRASkBitmap(decoded, false, png_data); + gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); return true; } diff --git a/chrome/browser/possible_url_model.cc b/chrome/browser/possible_url_model.cc index 5a0d0b5..5960ada 100644 --- a/chrome/browser/possible_url_model.cc +++ b/chrome/browser/possible_url_model.cc @@ -4,10 +4,10 @@ #include "chrome/browser/possible_url_model.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/table_model_observer.h" -#include "base/gfx/png_decoder.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/profile.h" @@ -176,7 +176,7 @@ void PossibleURLModel::OnFavIconAvailable( size_t index = consumer_.GetClientData(favicon_service, h); if (fav_icon_available) { // The decoder will leave our bitmap empty on error. - PNGDecoder::Decode(&data->data, &(fav_icon_map_[index])); + gfx::PNGCodec::Decode(&data->data, &(fav_icon_map_[index])); // Notify the observer. if (!fav_icon_map_[index].isNull() && observer_) diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 59fb294..3b1aaca 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -4,10 +4,10 @@ #include "chrome/browser/search_engines/template_url_table_model.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/table_model_observer.h" -#include "base/gfx/png_decoder.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -100,7 +100,7 @@ class ModelEntry { GURL icon_url) { load_state_ = LOADED; if (know_favicon && data.get() && - PNGDecoder::Decode(&data->data, &fav_icon_)) { + gfx::PNGCodec::Decode(&data->data, &fav_icon_)) { model_->FavIconAvailable(this); } } diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index 11f976e..3034afb 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -13,11 +13,11 @@ #include <string> #include <vector> +#include "app/gfx/codec/png_codec.h" #include "base/command_line.h" #include "base/eintr_wrapper.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" @@ -152,7 +152,7 @@ class CreateDesktopShortcutTask : public Task { shortcut_filename.ReplaceExtension("png")); std::vector<unsigned char> png_data; - PNGEncoder::EncodeBGRASkBitmap(shortcut_info_.favicon, false, &png_data); + gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_info_.favicon, false, &png_data); int bytes_written = file_util::WriteFile(temp_file_path, reinterpret_cast<char*>(png_data.data()), png_data.size()); diff --git a/chrome/browser/sync/glue/change_processor.cc b/chrome/browser/sync/glue/change_processor.cc index dc4cc0d..696df04 100644 --- a/chrome/browser/sync/glue/change_processor.cc +++ b/chrome/browser/sync/glue/change_processor.cc @@ -6,7 +6,7 @@ #include "chrome/browser/sync/glue/change_processor.h" -#include "base/gfx/png_encoder.h" +#include "app/gfx/codec/png_codec.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/favicon_service.h" @@ -65,7 +65,7 @@ void ChangeProcessor::EncodeFavicon(const BookmarkNode* src, // Re-encode the BookmarkNode's favicon as a PNG, and pass the data to the // sync subsystem. - if (!PNGEncoder::EncodeBGRASkBitmap(favicon, false, dst)) + if (!gfx::PNGCodec::EncodeBGRASkBitmap(favicon, false, dst)) return; } diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 3db3908..e90d555 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -13,7 +13,6 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/histogram.h" #include "base/stl_util-inl.h" #include "base/string_util.h" diff --git a/chrome/browser/thumbnail_store.cc b/chrome/browser/thumbnail_store.cc index 19cd9f3..9a5b746 100644 --- a/chrome/browser/thumbnail_store.cc +++ b/chrome/browser/thumbnail_store.cc @@ -7,11 +7,11 @@ #include <string.h> #include <algorithm> +#include "app/gfx/codec/jpeg_codec.h" #include "app/sql/statement.h" #include "app/sql/transaction.h" #include "base/basictypes.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/md5.h" #include "base/string_util.h" #include "base/thread.h" @@ -77,9 +77,9 @@ bool ThumbnailStore::SetPageThumbnail(const GURL& url, // Encode the SkBitmap to jpeg. scoped_refptr<RefCountedBytes> jpeg_data = new RefCountedBytes; SkAutoLockPixels thumbnail_lock(thumbnail); - bool encoded = JPEGCodec::Encode( + bool encoded = gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, thumbnail.width(), + gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), thumbnail.height(), static_cast<int>(thumbnail.rowBytes()), 90, &jpeg_data->data); diff --git a/chrome/browser/thumbnail_store_unittest.cc b/chrome/browser/thumbnail_store_unittest.cc index cd249f3..e5a5be0 100644 --- a/chrome/browser/thumbnail_store_unittest.cc +++ b/chrome/browser/thumbnail_store_unittest.cc @@ -9,12 +9,12 @@ #include "chrome/browser/thumbnail_store.h" +#include "app/gfx/codec/jpeg_codec.h" #include "app/sql/connection.h" #include "app/sql/statement.h" #include "base/time.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/path_service.h" #include "base/ref_counted.h" #include "chrome/common/chrome_paths.h" @@ -70,23 +70,25 @@ void ThumbnailStoreTest::SetUp() { db_name_ = db_name_.AppendASCII("ThumbnailDB"); file_util::Delete(db_name_, false); - google_.reset(JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); - weewar_.reset(JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); + google_.reset(gfx::JPEGCodec::Decode(kGoogleThumbnail, + sizeof(kGoogleThumbnail))); + weewar_.reset(gfx::JPEGCodec::Decode(kWeewarThumbnail, + sizeof(kWeewarThumbnail))); SkAutoLockPixels lock1(*google_); jpeg_google_ = new RefCountedBytes; - JPEGCodec::Encode( + gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(google_->getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, google_->width(), + gfx::JPEGCodec::FORMAT_BGRA, google_->width(), google_->height(), static_cast<int>(google_->rowBytes()), 90, &(jpeg_google_->data)); SkAutoLockPixels lock2(*weewar_); jpeg_weewar_ = new RefCountedBytes; - JPEGCodec::Encode( + gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(weewar_->getAddr32(0,0)), - JPEGCodec::FORMAT_BGRA, weewar_->width(), + gfx::JPEGCodec::FORMAT_BGRA, weewar_->width(), weewar_->height(), static_cast<int>(weewar_->rowBytes()), 90, &(jpeg_weewar_->data)); diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index 94fb959..e7f9b37 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -5,9 +5,9 @@ #include "chrome/browser/views/options/general_page_view.h" #include "app/combobox_model.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" -#include "base/gfx/png_decoder.h" #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/browser.h" @@ -239,9 +239,10 @@ void CustomHomePagesTableModel::OnGotFavIcon( if (know_fav_icon && image_data.get() && !image_data->data.empty()) { int width, height; std::vector<unsigned char> decoded_data; - if (PNGDecoder::Decode(&image_data->data.front(), image_data->data.size(), - PNGDecoder::FORMAT_BGRA, &decoded_data, &width, - &height)) { + if (gfx::PNGCodec::Decode(&image_data->data.front(), + image_data->data.size(), + gfx::PNGCodec::FORMAT_BGRA, &decoded_data, + &width, &height)) { entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); entry->icon.allocPixels(); memcpy(entry->icon.getPixels(), &decoded_data.front(), diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index a4db1c9..e796979 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -8,11 +8,10 @@ #include <limits> #include <vector> +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "app/sql/statement.h" #include "app/sql/transaction.h" -#include "base/gfx/png_decoder.h" -#include "base/gfx/png_encoder.h" #include "base/string_util.h" #include "base/time.h" #include "chrome/browser/history/history_database.h" @@ -187,7 +186,7 @@ bool WebDatabase::SetWebAppImage(const GURL& url, const SkBitmap& image) { return false; std::vector<unsigned char> image_data; - PNGEncoder::EncodeBGRASkBitmap(image, false, &image_data); + gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data); s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); s.BindInt(1, image.width()); @@ -212,7 +211,7 @@ bool WebDatabase::GetWebAppImages(const GURL& url, if (col_bytes > 0) { image_data.resize(col_bytes); memcpy(&image_data[0], s.ColumnBlob(0), col_bytes); - if (PNGDecoder::Decode(&image_data, &image)) { + if (gfx::PNGCodec::Decode(&image_data, &image)) { images->push_back(image); } else { // Should only have valid image data in the db. diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 8214db3..4fcec3a 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -4143,6 +4143,7 @@ 'syncapi', 'test_support_unit', 'utility', + '../app/app.gyp:app_base', '../app/app.gyp:app_resources', '../ipc/ipc.gyp:ipc', '../net/net.gyp:net_resources', diff --git a/chrome/common/security_filter_peer.cc b/chrome/common/security_filter_peer.cc index 79256e7..a72ed31 100644 --- a/chrome/common/security_filter_peer.cc +++ b/chrome/common/security_filter_peer.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/common/security_filter_peer.h" +#include "app/gfx/codec/png_codec.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" -#include "base/gfx/png_encoder.h" #include "base/gfx/size.h" #include "base/string_util.h" #include "grit/generated_resources.h" @@ -310,8 +310,8 @@ bool ImageFilterPeer::DataReady() { // Now encode it to a PNG. std::vector<unsigned char> output; - if (!PNGEncoder::EncodeBGRASkBitmap(canvas.getDevice()->accessBitmap(false), - false, &output)) { + if (!gfx::PNGCodec::EncodeBGRASkBitmap( + canvas.getDevice()->accessBitmap(false), false, &output)) { return false; } diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 86c5fc1..780d02f 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -4,8 +4,8 @@ #include "chrome/renderer/print_web_view_helper.h" +#include "app/gfx/codec/jpeg_codec.h" #include "app/l10n_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/logging.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/render_view.h" @@ -139,9 +139,9 @@ void PrintWebViewHelper::PrintPageAsJPEG( // Encode the SkBitmap to jpeg. SkAutoLockPixels image_lock(bitmap); - bool encoded = JPEGCodec::Encode( + bool encoded = gfx::JPEGCodec::Encode( reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), - JPEGCodec::FORMAT_BGRA, + gfx::JPEGCodec::FORMAT_BGRA, static_cast<int>(bitmap.width() * zoom_factor), static_cast<int>(bitmap.height() * zoom_factor), static_cast<int>(bitmap.rowBytes()), diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index ac34636..2ef79b5 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -16,7 +16,6 @@ #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/field_trial.h" -#include "base/gfx/png_encoder.h" #include "base/gfx/native_widget_types.h" #include "base/process_util.h" #include "base/singleton.h" diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index 8bf7847..3bdb362 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/gfx/codec/jpeg_codec.h" #include "base/file_util.h" -#include "base/gfx/jpeg_codec.h" #include "base/shared_memory.h" #include "chrome/common/native_web_keyboard_event.h" #include "chrome/common/render_messages.h" @@ -518,8 +518,9 @@ TEST_F(RenderViewTest, OnPrintPageAsBitmap) { &data); std::vector<unsigned char> decoded; int w, h; - EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA, - &decoded, &w, &h)); + EXPECT_TRUE(gfx::JPEGCodec::Decode(&data[0], data.size(), + gfx::JPEGCodec::FORMAT_RGBA, + &decoded, &w, &h)); // Check if its not 100% white. bool is_white = true; diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/tools/profiles/generate_profile.cc index 6115412..0c492cd 100644 --- a/chrome/tools/profiles/generate_profile.cc +++ b/chrome/tools/profiles/generate_profile.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,9 +7,9 @@ #include "chrome/tools/profiles/thumbnail-inl.h" +#include "app/gfx/codec/jpeg_codec.h" #include "base/at_exit.h" #include "base/file_path.h" -#include "base/gfx/jpeg_codec.h" #include "base/icu_util.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -159,11 +159,11 @@ void InsertURLBatch(const std::wstring& profile_dir, int page_id, history_service->SetPageContents(url, ConstructRandomPage()); if (RandomInt(0, 2) == 0) { scoped_ptr<SkBitmap> bitmap( - JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); history_service->SetPageThumbnail(url, *bitmap, score); } else { scoped_ptr<SkBitmap> bitmap( - JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); + gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); history_service->SetPageThumbnail(url, *bitmap, score); } } diff --git a/printing/image.cc b/printing/image.cc index 667adae..b9c86dd 100644 --- a/printing/image.cc +++ b/printing/image.cc @@ -1,12 +1,11 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "printing/image.h" +#include "app/gfx/codec/png_codec.h" #include "base/file_util.h" -#include "base/gfx/png_decoder.h" -#include "base/gfx/png_encoder.h" #include "base/gfx/rect.h" #include "base/md5.h" #include "base/string_util.h" @@ -101,13 +100,13 @@ std::string Image::checksum() const { bool Image::SaveToPng(const std::wstring& filename) const { DCHECK(!data_.empty()); std::vector<unsigned char> compressed; - bool success = PNGEncoder::Encode(&*data_.begin(), - PNGEncoder::FORMAT_BGRA, - size_.width(), - size_.height(), - row_length_, - true, - &compressed); + bool success = gfx::PNGCodec::Encode(&*data_.begin(), + gfx::PNGCodec::FORMAT_BGRA, + size_.width(), + size_.height(), + row_length_, + true, + &compressed); DCHECK(success && compressed.size()); if (success) { int write_bytes = file_util::WriteFile( @@ -179,9 +178,9 @@ double Image::PercentageDifferent(const Image& rhs) const { bool Image::LoadPng(const std::string& compressed) { int w; int h; - bool success = PNGDecoder::Decode( + bool success = gfx::PNGCodec::Decode( reinterpret_cast<const unsigned char*>(compressed.c_str()), - compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h); + compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); size_.SetSize(w, h); row_length_ = size_.width() * sizeof(uint32); return success; diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc index 64a6b2b..4cebf7b 100644 --- a/skia/ext/vector_canvas_unittest.cc +++ b/skia/ext/vector_canvas_unittest.cc @@ -12,10 +12,10 @@ #include "PNGImageDecoder.h" +#include "app/gfx/codec/png_codec.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/gfx/gdi_util.h" -#include "base/gfx/png_encoder.h" #include "base/path_service.h" #include "base/string_util.h" #include "skia/ext/vector_canvas.h" @@ -116,13 +116,13 @@ class Image { // Save the image to a png file. Used to create the initial test files. void SaveToFile(const std::wstring& filename) { std::vector<unsigned char> compressed; - ASSERT_TRUE(PNGEncoder::Encode(&*data_.begin(), - PNGEncoder::FORMAT_BGRA, - width_, - height_, - row_length_, - true, - &compressed)); + ASSERT_TRUE(gfx::PNGCodec::Encode(&*data_.begin(), + gfx::PNGCodec::FORMAT_BGRA, + width_, + height_, + row_length_, + true, + &compressed)); ASSERT_TRUE(compressed.size()); FILE* f = file_util::OpenFile(filename, "wb"); ASSERT_TRUE(f); diff --git a/tools/imagediff/image_diff.cc b/tools/imagediff/image_diff.cc index 044b89c..60c3a7f 100644 --- a/tools/imagediff/image_diff.cc +++ b/tools/imagediff/image_diff.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,11 +13,10 @@ #include <string> #include <iostream> +#include "app/gfx/codec/png_codec.h" #include "base/basictypes.h" #include "base/command_line.h" #include "base/file_util.h" -#include "base/gfx/png_decoder.h" -#include "base/gfx/png_encoder.h" #include "base/logging.h" #include "base/process_util.h" #include "base/scoped_ptr.h" @@ -78,8 +77,9 @@ class Image { if (fread(source.get(), 1, byte_length, stdin) != byte_length) return false; - if (!PNGDecoder::Decode(source.get(), byte_length, PNGDecoder::FORMAT_RGBA, - &data_, &w_, &h_)) { + if (!gfx::PNGCodec::Decode(source.get(), byte_length, + gfx::PNGCodec::FORMAT_RGBA, + &data_, &w_, &h_)) { Clear(); return false; } @@ -103,8 +103,8 @@ class Image { file_util::CloseFile(f); - if (!PNGDecoder::Decode(&compressed[0], compressed.size(), - PNGDecoder::FORMAT_RGBA, &data_, &w_, &h_)) { + if (!gfx::PNGCodec::Decode(&compressed[0], compressed.size(), + gfx::PNGCodec::FORMAT_RGBA, &data_, &w_, &h_)) { Clear(); return false; } @@ -308,9 +308,9 @@ int DiffImages(const char* file1, const char* file2, const char* out_file) { return kStatusSame; std::vector<unsigned char> png_encoding; - PNGEncoder::Encode(diff_image.data(), PNGEncoder::FORMAT_RGBA, - diff_image.w(), diff_image.h(), diff_image.w() * 4, - false, &png_encoding); + gfx::PNGCodec::Encode(diff_image.data(), gfx::PNGCodec::FORMAT_RGBA, + diff_image.w(), diff_image.h(), diff_image.w() * 4, + false, &png_encoding); if (file_util::WriteFile(UTF8ToWide(out_file), reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) return kStatusError; diff --git a/tools/imagediff/image_diff.gyp b/tools/imagediff/image_diff.gyp index eb2518c..60e6b9f 100644 --- a/tools/imagediff/image_diff.gyp +++ b/tools/imagediff/image_diff.gyp @@ -9,8 +9,8 @@ 'type': 'executable', 'msvs_guid': '50B079C7-CD01-42D3-B8C4-9F8D9322E822', 'dependencies': [ + '../../app/app.gyp:app_base', '../../base/base.gyp:base', - '../../base/base.gyp:base_gfx', ], 'sources': [ 'image_diff.cc', diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 09c1909..dad1964 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -54,26 +54,26 @@ const char RootView::kViewClassName[] = "views/RootView"; ///////////////////////////////////////////////////////////////////////////// RootView::RootView(Widget* widget) - : mouse_pressed_handler_(NULL), - mouse_move_handler_(NULL), - last_click_handler_(NULL), - widget_(widget), - invalid_rect_urgent_(false), - pending_paint_task_(NULL), - paint_task_needed_(false), - explicit_mouse_handler_(false), + : mouse_pressed_handler_(NULL), + mouse_move_handler_(NULL), + last_click_handler_(NULL), + widget_(widget), + invalid_rect_urgent_(false), + pending_paint_task_(NULL), + paint_task_needed_(false), + explicit_mouse_handler_(false), #if defined(OS_WIN) - previous_cursor_(NULL), + previous_cursor_(NULL), #endif - default_keyboard_handler_(NULL), - focus_on_mouse_pressed_(false), - ignore_set_focus_calls_(false), - focus_traversable_parent_(NULL), - focus_traversable_parent_view_(NULL), - drag_view_(NULL) + default_keyboard_handler_(NULL), + focus_on_mouse_pressed_(false), + ignore_set_focus_calls_(false), + focus_traversable_parent_(NULL), + focus_traversable_parent_view_(NULL), + drag_view_(NULL) #ifndef NDEBUG - , - is_processing_paint_(false) + , + is_processing_paint_(false) #endif { } diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index cce4997..4de3869 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,12 +6,12 @@ #include "webkit/tools/test_shell/test_shell.h" +#include "app/gfx/codec/png_codec.h" #include "base/base_paths.h" #include "base/command_line.h" #include "base/debug_on_start.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/gfx/png_encoder.h" #include "base/gfx/size.h" #include "base/icu_util.h" #if defined(OS_MACOSX) @@ -265,7 +265,7 @@ std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, // Encode image. std::vector<unsigned char> png; SkAutoLockPixels src_bmp_lock(src_bmp); - PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; + gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_BGRA; // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want // to keep it. On Windows, the alpha channel is wrong since text/form control @@ -297,7 +297,7 @@ std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, // Only encode and dump the png if the hashes don't match. Encoding the image // is really expensive. if (md5hash.compare(pixel_hash) != 0) { - PNGEncoder::Encode( + gfx::PNGCodec::Encode( reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), color_format, src_bmp.width(), src_bmp.height(), static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index 8a85e44..d3e6b1c 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -26,6 +26,7 @@ 'target_name': 'test_shell_common', 'type': '<(library)', 'dependencies': [ + '../../../app/app.gyp:app_base', '../../../base/base.gyp:base', '../../../base/base.gyp:base_gfx', '../../../media/media.gyp:media', |