| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_GFX_PNG_ENCODER_H__ | 5 #ifndef BASE_GFX_PNG_ENCODER_H__ |
| 6 #define BASE_GFX_PNG_ENCODER_H__ | 6 #define BASE_GFX_PNG_ENCODER_H__ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 class SkBitmap; |
| 13 |
| 12 // Interface for encoding PNG data. This is a wrapper around libpng, | 14 // Interface for encoding PNG data. This is a wrapper around libpng, |
| 13 // which has an inconvenient interface for callers. This is currently designed | 15 // which has an inconvenient interface for callers. This is currently designed |
| 14 // for use in tests only (where we control the files), so the handling isn't as | 16 // for use in tests only (where we control the files), so the handling isn't as |
| 15 // robust as would be required for a browser (see Decode() for more). WebKit | 17 // robust as would be required for a browser (see Decode() for more). WebKit |
| 16 // has its own more complicated PNG decoder which handles, among other things, | 18 // has its own more complicated PNG decoder which handles, among other things, |
| 17 // partially downloaded data. | 19 // partially downloaded data. |
| 18 class PNGEncoder { | 20 class PNGEncoder { |
| 19 public: | 21 public: |
| 20 enum ColorFormat { | 22 enum ColorFormat { |
| 21 // 3 bytes per pixel (packed), in RGB order regardless of endianness. | 23 // 3 bytes per pixel (packed), in RGB order regardless of endianness. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 // (often, each row is padded to the next machine word). | 46 // (often, each row is padded to the next machine word). |
| 45 // discard_transparency: when true, and when the input data format includes | 47 // discard_transparency: when true, and when the input data format includes |
| 46 // alpha values, these alpha values will be discarded and only RGB will be | 48 // alpha values, these alpha values will be discarded and only RGB will be |
| 47 // written to the resulting file. Otherwise, alpha values in the input | 49 // written to the resulting file. Otherwise, alpha values in the input |
| 48 // will be preserved. | 50 // will be preserved. |
| 49 static bool Encode(const unsigned char* input, ColorFormat format, | 51 static bool Encode(const unsigned char* input, ColorFormat format, |
| 50 int w, int h, int row_byte_width, | 52 int w, int h, int row_byte_width, |
| 51 bool discard_transparency, | 53 bool discard_transparency, |
| 52 std::vector<unsigned char>* output); | 54 std::vector<unsigned char>* output); |
| 53 | 55 |
| 56 // Call PNGEncoder::Encode on the supplied SkBitmap |input|, which is assumed |
| 57 // to be BGRA, 32 bits per pixel. The params |discard_transparency| and |
| 58 // |output| are passed directly to Encode; refer to Encode for more |
| 59 // information. During the call, an SkAutoLockPixels lock is held on |input|. |
| 60 static bool EncodeBGRASkBitmap(const SkBitmap& input, |
| 61 bool discard_transparency, |
| 62 std::vector<unsigned char>* output); |
| 63 |
| 54 private: | 64 private: |
| 55 DISALLOW_EVIL_CONSTRUCTORS(PNGEncoder); | 65 DISALLOW_EVIL_CONSTRUCTORS(PNGEncoder); |
| 56 }; | 66 }; |
| 57 | 67 |
| 58 #endif // BASE_GFX_PNG_ENCODER_H__ | 68 #endif // BASE_GFX_PNG_ENCODER_H__ |
| 59 | 69 |
| OLD | NEW |