| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_GFX_PNG_ENCODER_H_ | |
| 6 #define BASE_GFX_PNG_ENCODER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 | |
| 12 class SkBitmap; | |
| 13 | |
| 14 // Interface for encoding PNG data. This is a wrapper around libpng, | |
| 15 // which has an inconvenient interface for callers. This is currently designed | |
| 16 // for use in tests only (where we control the files), so the handling isn't as | |
| 17 // robust as would be required for a browser (see Decode() for more). WebKit | |
| 18 // has its own more complicated PNG decoder which handles, among other things, | |
| 19 // partially downloaded data. | |
| 20 class PNGEncoder { | |
| 21 public: | |
| 22 enum ColorFormat { | |
| 23 // 3 bytes per pixel (packed), in RGB order regardless of endianness. | |
| 24 // This is the native JPEG format. | |
| 25 FORMAT_RGB, | |
| 26 | |
| 27 // 4 bytes per pixel, in RGBA order in memory regardless of endianness. | |
| 28 FORMAT_RGBA, | |
| 29 | |
| 30 // 4 bytes per pixel, in BGRA order in memory regardless of endianness. | |
| 31 // This is the default Windows DIB order. | |
| 32 FORMAT_BGRA | |
| 33 }; | |
| 34 | |
| 35 // Encodes the given raw 'input' data, with each pixel being represented as | |
| 36 // given in 'format'. The encoded PNG data will be written into the supplied | |
| 37 // vector and true will be returned on success. On failure (false), the | |
| 38 // contents of the output buffer are undefined. | |
| 39 // | |
| 40 // When writing alpha values, the input colors are assumed to be post | |
| 41 // multiplied. | |
| 42 // | |
| 43 // w, h: dimensions of the image | |
| 44 // row_byte_width: the width in bytes of each row. This may be greater than | |
| 45 // w * bytes_per_pixel if there is extra padding at the end of each row | |
| 46 // (often, each row is padded to the next machine word). | |
| 47 // discard_transparency: when true, and when the input data format includes | |
| 48 // alpha values, these alpha values will be discarded and only RGB will be | |
| 49 // written to the resulting file. Otherwise, alpha values in the input | |
| 50 // will be preserved. | |
| 51 static bool Encode(const unsigned char* input, ColorFormat format, | |
| 52 int w, int h, int row_byte_width, | |
| 53 bool discard_transparency, | |
| 54 std::vector<unsigned char>* output); | |
| 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 | |
| 64 private: | |
| 65 DISALLOW_COPY_AND_ASSIGN(PNGEncoder); | |
| 66 }; | |
| 67 | |
| 68 #endif // BASE_GFX_PNG_ENCODER_H_ | |
| OLD | NEW |